123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wanggb
- * Date: 2019/2/15
- * Time: 10:08
- */
- namespace app\admin\controller\general;
- use app\common\constants\AppConstants;
- use app\common\controller\Backend;
- use app\common\library\Redis;
- use think\Exception;
- class Domainpool extends Backend
- {
- protected $noNeedRight = ['index', 'wechatinfo', 'test'];
- protected $domainPoolModel = '';
- protected $domainRedisKey = 'DOMAINPOOLS:';
- protected $wechatPoolModel = '';
- protected $wechatRedisKey = 'WECHATPOOLS:';
- public function _initialize()
- {
- parent::_initialize();
- $this->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();
- }
- }
- }*/
- }
|