Files
liche/api/controllers/dms/Test.php
T
2023-08-16 17:01:22 +08:00

177 lines
10 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
defined('BASEPATH') or exit('No direct script access allowed');
ini_set('display_errors','On');
error_reporting(E_ERROR);
require_once(APPPATH . "controllers/dms/CurlAutoLogin.php");
class Test extends HD_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('dms/dms_clues_model','dms_clues_model');
$this->log_dir = 'dms';
}
public function index()
{
//登录态缓存文件
$loginResultFile = APPPATH . "cache/loginRes.txt";
$autoLogin = new CurlAutoLogin();
//已有登录态,则直接读取登录态,避免多次重复登录
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'])) {
debug_log("未登录成功...\n", 'dms.txt', $this->log_dir);
exit("未登录成功\n");
}
$token = $resArr['token'];
$pageIndex = 1;
$pageSize = 30;
$dollor = '$';
$createdDateStart = date("Y-m-d H:i:s", strtotime("-1 minute"));
$createdDateEnd = date("Y-m-d H:i:s", strtotime("now"));
debug_log("开始时间: ".$createdDateStart." ", 'dms.txt', $this->log_dir);
debug_log("截止时间: ".$createdDateEnd." ", 'dms.txt', $this->log_dir);
$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' \
-H 'Authorization: $token' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json;charset=UTF-8' \
-H 'Cookie: pwRKey=1; token=$token; wadapp.current.curlang=zh-CN; wadapp.current.token=$token; wadapp.current.user{$dollor}dms.dna-nev.com.cn={"username":"FJ0011董凯杰","remember":false,"randomCode":"8333185700157948","token":"$token","usertype":"2","{$dollor}data":{"result":"1","msg":"Success","token":"$token","username":"FJ0011董凯杰","userRealName":null,"userid":"673d16368b50446681537bd955a09d03","usertype":"2","empname":"董凯杰","errnums":null,"timeout":"3600","expires":10,"initstatus":"1","clientid":null,"vcode":null,"wxbind":"1","errorCode":"Success","message":"Success","loginPage":{"type":"None"}}}; orgInfo={"BRAND_CODE":"1","DLR_CODE":"FJ0011","DLR_ID":"86df6b1f8dd44b44a79723afd536b152","DLR_NAME":"福州狸车","DLR_ORG_TYPE":"1","DLR_STATUS":"1","GROUP_CODE":"1","GROUP_ID":"1","OEM_CODE":"1","OEM_ID":"1","ORG_CODE":"01FJ0011","EMP_ID":"d00f13699d514fb09c8029f59b825a2d","ORG_ID":"90436c9dbef845f2a7c0976132831ee6","ORG_NAME":"整车销售部","ORG_TYPE":"1","PARENT_DLR_CODE":"FJ0011","PARENT_DLR_ID":"86df6b1f8dd44b44a79723afd536b152","PARENT_DLR_NAME":"福州狸车","POS_CODE":"COC_XS_CSR_HEADER,COC_XS_CSR,SE-DLR-003,VE0003,SE-004,VE0001","POS_ID":"0011e894a6fd11ea8bfe005056850f88,00173ad3a6fd11ea8bfe005056850f88,003a9a92a6fd11ea8bfe005056850f88,fffbee61a6fc11ea8bfe005056850f88,293af90463a64f7c820472623a222716,ffca8da7a6fc11ea8bfe005056850f88","SOLUTION_ID":"经销商通用岗位,经销商通用岗位,经销商通用岗位,经销商通用岗位,经销商通用岗位,经销商通用岗位","COMPANY_ID":"9b89df77b07b4258b5d83c8b8f6bbc79","UPDATEPWDTIME":"2022-9-22","empName":"董凯杰","userId":"673d16368b50446681537bd955a09d03","userName":"FJ0011董凯杰","usertype":"2"}' \
-H 'Origin: http://dms.dna-nev.com.cn' \
-H 'Referer: http://dms.dna-nev.com.cn/' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36' \
--data-raw '{"query":"query({$dollor}pageIndex: Int, {$dollor}pageSize: Int, {$dollor}dataInfo: InputClueServer){clueServerQueryFromDlr(dataInfo: {$dollor}dataInfo, pageIndex: {$dollor}pageIndex, pageSize: {$dollor}pageSize){msg pageindex pages records result rows{serverOrder custName contactTel carBrandName carSeriesCn clueLevelCode nextDealUserName createdName cantactWayName infoChanMName infoChanDName clueLabel clueActive assignStatusName statusName crruNodeName column6 createdDate remainDataDate isFirstCallbackName firstReviewDate isOneHour isFourHour isTwentyFourHour orderDate deliveryDate nextCallbackDate changeIntentDate nextDealEmpName inteSeriesCode}}}","variables":{"pageSize":$pageSize,"pageIndex":$pageIndex,"dataInfo":{"custName":"","contactTel":"","inteSeriesId":"","clueLevelCode":"","createdDateStart":"$createdDateStart","createdDateEnd":"$createdDateEnd","orderDateStart":"","orderDateEnd":"","status":"","csr":"","serverOrder":"","cantactWayCode":"CS001","infoChanMCode":"","carBrandCode":"","assignStatus":"","crruNode":"","createdName":"","dlrCode":"","handleCode":"1","assignStatusName":"","statusArray":["10","20","21","30","31","40","50"],"nextDealUserId":"","nextDealUserName":"","infoChanDName":"","isQueryHistory":"0"}}}' \
--compressed \
--insecure
CURL;
$content = $autoLogin->execCurl($curl);
$resArr = json_decode($content, true);
if (!$resArr['result']) {
$this->doLogin($autoLogin, $loginResultFile);
}
if(!$resArr['data']['clueServerQueryFromDlr']['rows']){
debug_log("无新增数据\n", 'dms.txt', $this->log_dir);
exit;
}
else{
debug_log("".$resArr['data']['clueServerQueryFromDlr']['records']." 新增数据\n", 'dms.txt', $this->log_dir);
}
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, */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'Cookie: pwRKey=1' \
-H 'Origin: http://dms.dna-nev.com.cn' \
-H 'Referer: http://dms.dna-nev.com.cn/' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36' \
--data-raw 'reuestParas=vrdCxWqmC6nNDXrxEyNCX5sThLElae5I%2FznYqpsieYlTddUJ3hGzCvtSaYuzgDIiFAA3q0F7oHSYjeXfwRppg6lnsHDViByHQ4sJwSXhMWyKZNQ7zrgAZ%2FzR9jd5XQEQYmdcXnNgzjRxZIUaYmOwkAPFBuBOodE58zLpEvWsTFqLQVfQhVUZzE%2FN941hLaRaAHBbSqn21c6TpJyXHprF766eukiB4b5urdLilNsNQimLVcEfW6xQS9dSzAcMQZIR7dWEWQyWGWqPNnfD5yp%2Btw%3D%3D' \
--compressed \
--insecure
CURL;
$content = $autoLogin->execCurl($curl);
$resArr = json_decode($content, true);
file_put_contents($loginResultFile, $content); //存储登录结果
return $resArr;
}
public function test()
{
$url = 'http://dms.dna-nev.com.cn/mp/login/validlogin.do';
$header = array (
0 => 'Accept: application/json, text/plain, */*',
1 => 'Accept-Language: zh-CN,zh;q=0.9',
2 => 'Connection: keep-alive',
3 => 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
4 => 'Origin: http://dms.dna-nev.com.cn',
5 => 'Referer: http://dms.dna-nev.com.cn/',
6 => 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
);
$postData = 'reuestParas=vrdCxWqmC6nNDXrxEyNCX5sThLElae5I%2FznYqpsieYmu3oIOQecGrZpH%2Bhpntm%2Bnb10K23tP9k9i2sqCxHESj1Leu%2BkGr2FYklTI%2BwwdCn2KZNQ7zrgAZ%2FzR9jd5XQEQzwyUCcwxllqqZWKDNMoWSJCLAYbMf0p%2FuqiVE105v%2Fi7yStvG5q7pE6lk%2B9g7oDsAHBbSqn21c6TpJyXHprF766eukiB4b5urdLilNsNQikR6rU2pY5dfymx5S2ytZzlnIE4pE2GHVV9VW6jzLot1w%3D%3D';
// $postData = array(
// 'reuestParas' => 'vrdCxWqmC6nNDXrxEyNCX5sThLElae5I/znYqpsieYnyP9dYSVqrnNbryed0peXaee4199dAmuV61oHp3hUaIveISmjsLLKviH0eoWO1+5WKZNQ7zrgAZ/zR9jd5XQEQVyCBtq6canDPslkbJJaqBBqDnXrTNfDkp/nCJWdfJaoYGaQma/2+6KOacVm3jq6DAHBbSqn21c6TpJyXHprF766eukiB4b5urdLilNsNQimy2E6KL8vBaa+L4mnRHsEAU3RYz8uFJO2ZRHl9aPfJCA=='
// );
$cookie = 'Cookie: pwRKey=1'; //需要cookie的话去掉这行的注释
$timeout = 10;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回数据不直接输出
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); //指定gzip压缩
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //302/301
//SSL
if(substr($url, 0, 8) === 'https://') {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112)解决
//值有0-6,请参考手册,值1不行试试其他值
//curl_setopt($ch, CURLOPT_SSLVERSION, 1);
}
//post数据
if(!empty($postData)) {
curl_setopt($ch, CURLOPT_POST, 1); //发送POST类型数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); //POST数据,$post可以是数组(multipart/form-data),也可以是拼接参数串(application/x-www-form-urlencoded
}
if(!empty($cookie)) {
$header[] = $cookie;
}
if(!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //使用header头信息
}
//超时时间
curl_setopt($ch, CURLOPT_TIMEOUT, (int)$timeout);
//执行
$content = curl_exec($ch);
if($error = curl_error($ch)) {
//log error
error_log($error);
}
curl_close($ch);
print_r($content);
return $content;
}
}