exists($domainRedisKey)){ $domains = $redis->get($domainRedisKey); if ($domains) { $domains = explode(',', $domains); $domains = array_filter($domains); $random_index = rand(0, count($domains) - 1); $domain = $domains[$random_index]; } else { $domain = ""; } } else { $domainList = model('DomainPools')->select(); $domain_pools_str = ''; foreach ($domainList as $key => $item) { $value = $item->domain; if (!empty(trim($value))) { $domain_pools_str .= trim($value); if ($key < (count($domainList) - 1)) { $domain_pools_str .= ','; } } } $redis = Redis::instance(); $redis->set($domainRedisKey, $domain_pools_str, 7 * 24 * 60 * 60); $data = array_pop($domainList); if($data){ $domain = $data->domain; }else{ $domain = ""; } } return $domain; } /** * 获取随机微信安全域名 * @return string */ public static function getRandomWechatDomain() { $domainRedisKey = 'WECHATPOOLS:'; $redis = Redis::instance(); if ($redis->exists($domainRedisKey)) { $domains_json = $redis->get($domainRedisKey); $domains = json_decode($domains_json, true); if ($domains) { $data = array_pop($domains); } else { $data = ""; } } else { $wechatList = model('WechatPools')->select(); foreach ($wechatList as $key => $value) { $t_data[$key]['appid'] = trim($value->appid); $t_data[$key]['domain'] = trim($value->domain); } $redis = Redis::instance(); $redis->set($domainRedisKey, json_encode($t_data), 7 * 24 * 60 * 60); if ($wechatList) { $data = array_pop($t_data); } else { $data = ""; } } return $data; } }