dms test
This commit is contained in:
@@ -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 = <<<CURL
|
||||
// $redis = &load_cache('redis');
|
||||
// $redisKey = 'dms_json';
|
||||
// $dms_json = $redis->get($redisKey);
|
||||
|
||||
$curl = <<<CURL
|
||||
curl 'http://dms.dna-nev.com.cn/ly/mp/busicen/csc/graphql.do?v=clueServerQueryFromDlr' \
|
||||
-H 'Accept: application/json, text/plain, */*' \
|
||||
-H 'Accept-Language: zh-CN,zh;q=0.9' \
|
||||
@@ -61,53 +70,40 @@ curl 'http://dms.dna-nev.com.cn/ly/mp/busicen/csc/graphql.do?v=clueServerQueryFr
|
||||
--compressed \
|
||||
--insecure
|
||||
CURL;
|
||||
$content = $autoLogin->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 = <<<CURL
|
||||
curl 'http://dms.dna-nev.com.cn/mp/login/validlogin.do' \
|
||||
-H 'Accept: application/json, text/plain, */*' \
|
||||
|
||||
@@ -63,6 +63,8 @@ class Plan extends CI_Controller
|
||||
$plan[] = array('url' => 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user