domainPoolModel = model('DomainPools'); $this->wechatPoolModel = model('WechatPools'); } public function test() { //$data = AppConstants::getRandomFrontDomain(); //$data = AppConstants::getRandomWechatDomain(); } /** * 微信防封,前置域名池 * @return string|\think\response\Json * @throws \think\Exception */ public function index() { if ($_POST) { if (!$_POST['domainpools']) { $this->error('数据不能为空'); } // 删除所有数据 $this->domainPoolModel->trucateDomainPools(); $data = explode(PHP_EOL, $_POST['domainpools']); $domain_pools_str = ''; foreach ($data as $key => $value) { if (!empty(trim($value))) { $this->domainPoolModel->insert(['domain' => trim($value)]); $domain_pools_str .= trim($value); if ($key < (count($data) - 1)) { $domain_pools_str .= ','; } } } $redis = Redis::instance(); $redis->set($this->domainRedisKey, $domain_pools_str, 7 * 24 * 60 * 60); $this->success('保存成功', 'general/domainpool'); } else { $data = $this->domainPoolModel->select(); $domains_str = ''; if ($data) { foreach ($data as $key => $item) { $domains_str .= $item->domain; if ($key < (count($data) - 1)) { $domains_str .= PHP_EOL; } } } $this->assign('domains', $domains_str); return $this->view->fetch(); } } /** * 微信防封,公众号信息设置 * @return string */ public function wechatinfo() { //读取/var/www/cps/public 目录下的文件 if ($_POST) { if (!$_POST['wechatpools']) { $this->error('数据不能为空'); } // 删除所有数据 $this->wechatPoolModel->trucateWechatPools(); $data = explode(PHP_EOL, $_POST['wechatpools']); foreach ($data as $key => $value) { $i_data = explode(':', $value); if (!isset($i_data[0]) || !isset($i_data[1])) { $this->error('格式不正确,单条信息以":"分隔', '/admin/general/domainpool/wechatinfo'); } else { $this->wechatPoolModel->insert(['appid' => trim($i_data[0]), 'domain' => trim($i_data[1])]); $t_data[$key]['appid'] = trim($i_data[0]); $t_data[$key]['domain'] = trim($i_data[1]); } } $redis = Redis::instance(); $redis->set($this->wechatRedisKey, json_encode($t_data), 7 * 24 * 60 * 60); $this->success('保存成功', '/admin/general/domainpool/wechatinfo'); } else { try { $data = $this->wechatPoolModel->select(); $wechat_str = ''; if ($data) { foreach ($data as $key => $value) { $wechat_str .= $value->appid . ':' . $value->domain; if ($key < (count($data) - 1)) { $wechat_str .= PHP_EOL; } } } $this->assign('wechat_domains', $wechat_str); return $this->view->fetch(); } catch (\Exception $e) { echo $e->getMessage(); } } } /*public function index() { if($_POST){ if(!$_POST['domainpools']){ $this->error('数据不能为空'); } $data = explode(PHP_EOL, $_POST['domainpools']); $domains_str = ''; foreach ($data as $key => $value){ if(!empty(trim($value))){ $domains_str .= trim($value); if($key < (count($data) - 1)){ $domains_str .= ','; } } } file_put_contents(ROOT_PATH . 'public/front_domains.txt', $domains_str); $this->success('保存成功', 'general/domainpool'); }else { //读取/var/www/cps/public 目录下的文件 $domains = @file_get_contents(ROOT_PATH . 'public/front_domains.txt'); $data = explode(',', $domains); $domains_str = ''; if($data){ foreach ($data as $key=>$value){ $domains_str .= $value; if($key < (count($data) - 1)){ $domains_str .= PHP_EOL; } } } $this->assign('domains', $domains_str); return $this->view->fetch(); } }*/ /** * 微信防封,公众号信息设置 * @return string */ /*public function wechatinfo() { //读取/var/www/cps/public 目录下的文件 if ($_POST) { if (!$_POST['wechatpools']) { $this->error('数据不能为空'); } $data = explode(PHP_EOL, $_POST['wechatpools']); foreach ($data as $key => $value) { $i_data = explode(':', $value); if (!isset($i_data[0]) || !isset($i_data[1])) { $this->error('格式不正确,单条信息以":"分隔', '/admin/general/domainpool/wechatinfo'); } else { $t_data[$key]['appid'] = trim($i_data[0]); $t_data[$key]['domain'] = trim($i_data[1]); } } file_put_contents(ROOT_PATH . 'public/wechat_domains.txt', json_encode($t_data)); $this->success('保存成功', '/admin/general/domainpool/wechatinfo'); } else { try { $wechat_domains = @file_get_contents(ROOT_PATH . 'public/wechat_domains.txt'); $data = json_decode($wechat_domains, true); $wechat_str = ''; if ($data) { foreach ($data as $key => $value) { $wechat_str .= $value['appid'] . ':' . $value['domain']; if ($key < (count($data) - 1)) { $wechat_str .= PHP_EOL; } } } $this->assign('wechat_domains', $wechat_str); return $this->view->fetch(); } catch (\Exception $e) { echo $e->getMessage(); } } }*/ }