diff --git a/api/controllers/dms/Test.php b/api/controllers/dms/Test.php index 4b7ed34f..3f5582ad 100644 --- a/api/controllers/dms/Test.php +++ b/api/controllers/dms/Test.php @@ -12,6 +12,7 @@ class Test extends HD_Controller { parent::__construct(); $this->load->model('dms/dms_clues_model','dms_clues_model'); + $this->log_dir = 'dms'; } public function index() @@ -21,14 +22,16 @@ class Test extends HD_Controller $autoLogin = new CurlAutoLogin(); //已有登录态,则直接读取登录态,避免多次重复登录 - if(!file_exists($loginResultFile)) { + if (!file_exists($loginResultFile)) { $resArr = $this->doLogin($autoLogin, $loginResultFile); } else { echo "有登录态,自动登录...\n"; + debug_log("有登录态,自动登录...\n", 'dms.txt', $this->log_dir); $resArr = json_decode(file_get_contents($loginResultFile), true); } - if(empty($resArr['username'])) { + if (empty($resArr['username'])) { + debug_log("未登录成功...\n", 'dms.txt', $this->log_dir); exit("未登录成功\n"); } @@ -37,16 +40,22 @@ class Test extends HD_Controller $pageSize = 30; $dollor = '$'; - $createdDateStart = date("Y-m-d 00:00:00",strtotime("-1 day")); - $createdDateEnd = date("Y-m-d 00:00:00"); + $createdDateStart = date("Y-m-d H:i:s", strtotime("-5 minute")); + $createdDateEnd = date("Y-m-d H:i:s", strtotime("now")); - $redis = &load_cache('redis'); - $redisKey = 'dms_cid'; + debug_log("开始时间: ".$createdDateStart." ", 'dms.txt', $this->log_dir); + debug_log("截止时间: ".$createdDateEnd." ", 'dms.txt', $this->log_dir); - while(true) { - echo "处理第".$pageIndex."页..\n"; +// echo strtotime("-1 minute"); +// echo "\n"; +// echo strtotime("now"); +// exit; - $curl = <<get($redisKey); + + $curl = <<execCurl($curl); - $resArr = json_decode($content, true); + $content = $autoLogin->execCurl($curl); + $resArr = json_decode($content, true); - if(!$resArr['result']) { - $resArr = $this->doLogin($autoLogin, $loginResultFile); - $resArr = json_decode($content, true); - } + if (!$resArr['result']) { + $this->doLogin($autoLogin, $loginResultFile); + } - print_r($resArr);exit; + if(!$resArr['data']['clueServerQueryFromDlr']['rows']){ + debug_log("无新增数据\n", 'dms.txt', $this->log_dir); + exit; + } + else{ + debug_log("共".$resArr['data']['clueServerQueryFromDlr']['record']."新增数据\n", 'dms.txt', $this->log_dir); + } - foreach ($resArr['data']['clueServerQueryFromDlr']['rows'] as $k => $v){ - if($pageIndex == 1 && $k == 0){ - $cid = $redis->get($redisKey); - if($cid == $v['serverOrder']){ - $pageIndex = 999; - break; - }else{ - $redis->save($redisKey, $v['serverOrder'], 86400); - } - } - - $add = array( - 'c_id' => $v['serverOrder'], - 'name' => $v['custName'], - 'mobile' => $v['contactTel'], - 'cfrom1' => $v['infoChanMName'], - 'cfrom2' => $v['infoChanDName'], - 'jsondata' => json_encode($v, JSON_UNESCAPED_UNICODE), - 'c_time' => strtotime($v['createdDate']) - ); - - $this->dms_clues_model->add($add); - } - - sleep(random_int(5,10)); - $pageIndex++; - - if($resArr['data']['clueServerQueryFromDlr']['pages'] < $pageIndex) { - break; - } + foreach ($resArr['data']['clueServerQueryFromDlr']['rows'] as $k => $v) { + $add = array( + 'c_id' => $v['serverOrder'], + 'name' => $v['custName'], + 'mobile' => $v['contactTel'], + 'cfrom1' => $v['infoChanMName'], + 'cfrom2' => $v['infoChanDName'], + 'jsondata' => json_encode($v, JSON_UNESCAPED_UNICODE), + 'c_time' => strtotime($v['createdDate']) + ); + $this->dms_clues_model->add($add); } } public function doLogin($autoLogin, $loginResultFile) { echo "无登录态,模拟登录...\n"; + debug_log("无登录态,模拟登录...\n", 'dms.txt', $this->log_dir); $curl = << base_url(array('plan', 'syt', 'out_time')), 'interval' => 1); //订单过期 $plan[] = array('url' => base_url(array('plan', 'syt', 'thApi')), 'interval' => 1); //私域通通知第三方脚本 + $plan[] = array('url' => base_url(array('dms', 'test', 'index')), 'interval' => 1); //dms爬虫 + $this->plan = $plan; }