Commit 2014758a authored by 蒋林's avatar 蒋林

对外相关接口开发

parent 3a770a54
<?php
/**
* Created by PhpStorm.
* User: LinJiangL
* Date: 16/10/24
* Time: 上午10:54
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Class Suning 苏宁相关接口
*
* @property api_log_model api_log_model
* @property SourceSuning SourceSuning
* @property ReceiveSuning ReceiveSuning
*/
class Suning extends BaseController
{
public function __construct()
{
parent::__construct();
ini_set("max_execution_time", 600);
}
//服务订单作业条件
public function serviceOrderCondition()
{
$param = $this->input->post();
//验证参数
$obj = $this->receiveObj();
$obj->SetValues($param);
$obj->CheckServiceOrderConditionValues();
$values = $obj->GetValues();
$this->saveLog('', 'serviceOrderCondition', $values);
$sourceObj = $this->sourceObj($values['account'], $values['pwd']);
$result = $sourceObj->ServiceOrderCondition($values['type']);
$obj->ReturnMessage(true, '', $result);
}
//服务订单作业查询
public function serviceOrder()
{
$param = $this->input->post();
//验证参数
$obj = $this->receiveObj();
$obj->SetValues($param);
$obj->CheckServiceOrderValues();
$values = $obj->GetValues();
$this->saveLog('', 'serviceOrder', $values);
$sourceObj = $this->sourceObj($values['account'], $values['pwd']);
$result = $sourceObj->ServiceOrder($values['type'], $values);
$obj->ReturnMessage(true, '', $result);
}
//服务订单查询条件
public function selectServiceOrderCondition()
{
$param = $this->input->post();
//验证参数
$obj = $this->receiveObj();
$obj->SetValues($param);
$obj->CheckSelectServiceOrderConditionValues();
$values = $obj->GetValues();
$this->saveLog('', 'SelectServiceOrderCondition', $values);
$sourceObj = $this->sourceObj($values['account'], $values['pwd']);
$result = $sourceObj->SelectServiceOrderCondition();
$obj->ReturnMessage(true, '', $result);
}
//服务订单作业查询
public function selectServiceOrder()
{
$param = $this->input->post();
//验证参数
$obj = $this->receiveObj();
$obj->SetValues($param);
$obj->CheckSelectServiceOrderValues();
$values = $obj->GetValues();
$this->saveLog('', 'selectServiceOrder', $values);
$sourceObj = $this->sourceObj($values['account'], $values['pwd']);
$result = $sourceObj->SelectServiceOrder($values);
$obj->ReturnMessage(true, '', $result);
}
/**
* 保存日志
*
* @param $search
* @param $method
* @param $data
*/
private function saveLog($search, $method, $data)
{
//记录日志
$this->load->model('api_log_model');
$this->api_log_model->add($search, 'suning', $method, $data);
}
private function sourceObj($username, $pwd)
{
$account = [
'username' => $username,
'pwd' => $pwd
];
$this->load->library('Source/SourceSuning', $account, 'SourceSuning');
return $this->SourceSuning;
}
private function receiveObj()
{
$this->load->library('Receive/ReceiveSuning', null, 'ReceiveSuning');
return $this->ReceiveSuning;
}
}
\ No newline at end of file
...@@ -81,7 +81,8 @@ function return_msg($code=true, $msg='', $data=null) ...@@ -81,7 +81,8 @@ function return_msg($code=true, $msg='', $data=null)
die(); die();
} }
function curl_get($url) { function curl_get($url)
{
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HEADER, 0);
...@@ -100,7 +101,8 @@ function curl_get($url) { ...@@ -100,7 +101,8 @@ function curl_get($url) {
} }
function curl_post($url, $post) { function curl_post($url, $post)
{
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HEADER, 0);
...@@ -108,7 +110,41 @@ function curl_post($url, $post) { ...@@ -108,7 +110,41 @@ function curl_post($url, $post) {
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
$result = curl_exec($curl); $result = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$info = curl_getinfo($curl);
curl_close($curl); curl_close($curl);
return ['code' => $code, 'data' => $result]; return ['code' => $code, 'data' => $result, 'info' => $info];
}
function phone_code()
{
$mbox = imap_open("{pop.163.com:995/pop3/ssl}INBOX", "wxh__8888@163.com", "WXH888888");
if (!$mbox) {
return_msg(false, '登陆邮箱失败');
}
$num = imap_num_msg($mbox);
$result = [];
if ($num) {
$body = imap_base64(imap_fetchbody($mbox, imap_num_msg($mbox), 1));
$body = iconv('utf8', 'gbk', $body);
preg_match('/\d{6}/', $body, $code);
preg_match('/2\d{3}-[\s\S]{14}/', $body, $date);
if (isset($code[0]) && isset($date[0])) {
$result['code'] = $code[0];
$result['date'] = $date[0];
$result['st'] = time() - strtotime($result['date']);
}
//关闭资源
imap_close($mbox);
}
return $result;
} }
<?php
require 'Receive.php';
class ReceiveSuning extends Receive
{
public function CheckServiceOrderConditionValues()
{
$fileds = ['type'];
$this->CheckValues($fileds);
}
public function CheckServiceOrderValues()
{
$fileds = ['type', 'siteBp'];
$this->CheckValues($fileds);
$dfields = [
'siteBp',
'objectIds',
'startTime',
'endTime',
'processTypeName',
'processType',
];
$this->SetDefaultValues($dfields);
if ($this->values['startTime']) {
$this->values['startTime'] = date('Y-m-d', strtotime($this->values['startTime']));
}
if ($this->values['endTime']) {
$this->values['endTime'] = date('Y-m-d', strtotime($this->values['endTime']));
}
}
public function CheckSelectServiceOrderConditionValues()
{
$this->CheckValues();
}
public function CheckSelectServiceOrderValues()
{
$fileds = ['mark', 'siteBp'];
$this->CheckValues($fileds);
$dfields = [
'mark',
'siteBp',
'objectIds',
'phone',
'startTime',
'endTime',
'processTypeName',
'processType',
'orderStatusName',
'orderStatus'
];
$this->SetDefaultValues($dfields);
if ($this->values['startTime']) {
$this->values['startTime'] = date('Y-m-d', strtotime($this->values['startTime']));
}
if ($this->values['endTime']) {
$this->values['endTime'] = date('Y-m-d', strtotime($this->values['endTime']));
}
}
/**
* 检查参数
* @param array $fields
*/
private function CheckValues($fields = [])
{
if (!$this->GetValues()) {
$this->ReturnMessage(false, '参数错误!');
}
if ($this->CheckAppid() == false) {
$this->ReturnMessage(false, 'appid参数错误!');
}
if ($this->CheckSign() == false) {
$this->ReturnMessage(false, '签名错误!');
}
if (!array_key_exists('account', $this->values) || $this->values['account'] == '') {
$this->ReturnMessage(false, "account参数错误!");
} else {
$this->values['account'] = trim(urldecode($this->values['account']));
}
if (!array_key_exists('pwd', $this->values) || $this->values['pwd'] == '') {
$this->ReturnMessage(false, "pwd参数错误!");
} else {
$this->values['pwd'] = trim(urldecode($this->values['pwd']));
}
if ($fields) {
foreach ($fields as $v) {
if (!array_key_exists($v, $this->values) || $this->values[$v] == '') {
$this->ReturnMessage(false, "{$v}参数错误!");
} else {
$this->values[$v] = trim(urldecode($this->values[$v]));
}
}
}
}
/**
* 给指定参数增加默认值
* @param $fields
*/
private function SetDefaultValues($fields)
{
if ($fields) {
foreach ($fields as $v) {
if (!array_key_exists($v, $this->values)) {
$this->values[$v] = '';
} else {
$this->values[$v] = urldecode($this->values[$v]);
}
}
}
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ class Source ...@@ -10,6 +10,7 @@ class Source
{ {
protected static $cookieFilePath = ''; //cookie 文件路径 protected static $cookieFilePath = ''; //cookie 文件路径
protected static $captchaFilePath = ''; //验证码 文件路径 protected static $captchaFilePath = ''; //验证码 文件路径
protected static $debug = false;
protected function SetUrlCookie($url) protected function SetUrlCookie($url)
{ {
...@@ -56,10 +57,22 @@ class Source ...@@ -56,10 +57,22 @@ class Source
return ['code' => $code, 'data' => $result]; return ['code' => $code, 'data' => $result];
} }
protected function CurlPostHttps($url, $post, $headers) protected function CurlPostHttps($url, $post, $headers, $type="")
{ {
$cacert = APPPATH.'config/cacert.pem'; $cacert = APPPATH.'config/cacert.pem';
if ($type == 'json') {
foreach ($headers as $k => $v) {
if (stripos($v, 'Content-Type') !== false) {
$headers[$k] = 'Content-Type: application/json;charset=UTF-8';
}
}
$post = json_encode($post);
} else {
$post = http_build_query($post);
}
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
...@@ -71,63 +84,86 @@ class Source ...@@ -71,63 +84,86 @@ class Source
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFilePath); curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFilePath);
curl_setopt($curl, CURLOPT_COOKIEJAR, self::$cookieFilePath); curl_setopt($curl, CURLOPT_COOKIEJAR, self::$cookieFilePath);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl); $result = curl_exec($curl);
$info = curl_getinfo($curl); $info = curl_getinfo($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl); curl_close($curl);
if ($info['http_code'] == 200) { if ($code == 200) {
$this->ReturnError($result, $url); $this->ReturnError($result, $url);
} }
return ['info' => $info, 'data' => $result]; return ['code' => $code, 'info' => $info, 'data' => $result];
} }
protected function GetUrlContents($url, $isCheck = true) protected function CurlGetHttps($url, $headers)
{ {
$cacert = APPPATH.'config/cacert.pem';
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 15); curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_CAINFO, $cacert);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFilePath); curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFilePath);
$rs = curl_exec($curl); //执行cURL抓取页面内容 $result = curl_exec($curl);
$info = curl_getinfo($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl); curl_close($curl);
if ($isCheck) { if ($code == 200) {
$this->ReturnError($rs, $url); $this->ReturnError($result, $url);
} }
return $rs; return ['code' => $code, 'info' => $info, 'data' => $result];
} }
/** protected function HttpsFollowLocation($url, $headers)
* 获取手机验证码
* @return array
*/
public function GetMailPhoneCode()
{ {
$mbox = imap_open ("{pop.163.com:995/pop3/ssl}INBOX", "wxh__8888@163.com", "WXH888888"); $cacert = APPPATH.'config/cacert.pem';
$num = imap_num_msg($mbox); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_CAINFO, $cacert);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFilePath);
curl_setopt($curl, CURLOPT_COOKIEJAR, self::$cookieFilePath);
$result = curl_exec($curl);
$info = curl_getinfo($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$result = []; if ($code == 302) {
return $this->HttpsFollowLocation($info['redirect_url'], $headers);
}
if ($num) { return ['code' => $code, 'info' => $info, 'data' => $result];
$body = imap_base64(imap_fetchbody($mbox, imap_num_msg($mbox), 1)); }
$body = iconv('utf8', 'gbk', $body);
preg_match('/\d{6}/', $body, $code); protected function GetUrlContents($url, $isCheck = true)
preg_match('/2\d{3}-[\s\S]{14}/', $body, $date); {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFilePath);
$rs = curl_exec($curl); //执行cURL抓取页面内容
curl_close($curl);
if (isset($code[0]) && isset($date[0])) { if ($isCheck) {
$result['code'] = $code[0]; $this->ReturnError($rs, $url);
$result['date'] = $date[0];
$result['st'] = time() - strtotime($result['date']);
}
} }
return $result; return $rs;
} }
protected function HandelHtmlScript($html) protected function HandelHtmlScript($html)
...@@ -135,6 +171,15 @@ class Source ...@@ -135,6 +171,15 @@ class Source
return str_replace('script', 'scriptt', $html); return str_replace('script', 'scriptt', $html);
} }
protected function Debug($function, $data)
{
if (self::$debug) {
echo "{$function}<br/>";
echo "<pre>";
print_r($data);
}
}
protected function ReturnError($html, $url) protected function ReturnError($html, $url)
{ {
if (!$html) { if (!$html) {
......
...@@ -12,8 +12,6 @@ class SourceSuning extends Source ...@@ -12,8 +12,6 @@ class SourceSuning extends Source
{ {
private static $account = []; private static $account = [];
private static $app = 'suning'; private static $app = 'suning';
private static $debug = false;
public function __construct($account) public function __construct($account)
{ {
...@@ -21,6 +19,9 @@ class SourceSuning extends Source ...@@ -21,6 +19,9 @@ class SourceSuning extends Source
self::$cookieFilePath = PUBDIR . "cookie/" . self::$app . "_" . md5(self::$account['username']) . ".cookie"; self::$cookieFilePath = PUBDIR . "cookie/" . self::$app . "_" . md5(self::$account['username']) . ".cookie";
self::$captchaFilePath = PUBDIR . "captcha/" . self::$app . "_" . md5(self::$account['username']) . ".gif"; self::$captchaFilePath = PUBDIR . "captcha/" . self::$app . "_" . md5(self::$account['username']) . ".gif";
//debug
self::$debug = false;
//判断是否登陆 //判断是否登陆
$isLogin = $this->IsLogin(); $isLogin = $this->IsLogin();
if ($isLogin == false) { if ($isLogin == false) {
...@@ -35,6 +36,10 @@ class SourceSuning extends Source ...@@ -35,6 +36,10 @@ class SourceSuning extends Source
*/ */
public function ServiceOrderCondition($type = 1) public function ServiceOrderCondition($type = 1)
{ {
if (!in_array($type, [1,2,3])) {
return_msg(false, 'type参数错误');
}
$type = $type - 1; $type = $type - 1;
$post = [ $post = [
'choosedtab' => $type 'choosedtab' => $type
...@@ -44,71 +49,40 @@ class SourceSuning extends Source ...@@ -44,71 +49,40 @@ class SourceSuning extends Source
$headers = $this->Header($url); $headers = $this->Header($url);
$result = $this->CurlHttpsPost($url, $post, $headers); $result = $this->CurlHttpsPost($url, $post, $headers);
//debug
$this->Debug('ServiceOrderCondition', $result);
//select
preg_match_all('/<div[^>]+class="fake-select-option"[^>]*>[\s\S]+?<\/div>/', $result['data'], $select);
//debug
$this->Debug('ServiceOrderCondition-select', $select);
$condition = [];
if (isset($select[0]) && $select[0]) {
//select名称 //select名称
$selectName = ['siteBp','processType']; $selectName = ['siteBp','processType'];
$condition = $this->HandelServiceOrderCondition($result['data'], $selectName);
foreach ($select[0] as $key => $val) {
preg_match_all('/<span[^>]+code="([^"]+)"[^>]*>([\s\S]+?)<\/span>/', $val, $option);
$temp = [];
foreach ($option[1] as $k => $v) {
$temp[$v] = preg_replace('/\s+/', '', $option[2][$k]);
}
$temp && $condition[$selectName[$key]] = $temp;
}
}
return $condition; return $condition;
} }
public function ServiceOrderQuery()
{
$post = [
'mark' => '1',
'partner' => '904102',
'objectId' => '',
'mobPhoneNum' => '',
'startTime' => '',
'endTime' => '',
'printTypeName' => '',
'processType' => '',
'statusName' => '',
'orderStatus' => ''
];
}
/** /**
* 服务订单作业 * 服务订单作业
* @param int $type 1:待接收; 2:可重派; 3:待核销; * @param int $type 1:待接收; 2:可重派; 3:待核销;
* @param array $condition 条件
* @return array * @return array
*/ */
public function ServiceOrder($type = 1) public function ServiceOrder($type = 1, $condition)
{ {
$post = [ $post = [
'choosedFlag' => '', //类型 'choosedFlag' => '', //类型
'siteBp' => '904102', //网点BP 'siteBp' => $condition['siteBp'], //网点BP
'objectIds' => '', //订单号,多个用(,)隔开 'objectIds' => $condition['objectIds'], //订单号,多个用(,)隔开
'applyStartTime' => '2016-10-20', //开始时间 'applyStartTime' => $condition['startTime'], //开始时间
'applyEndTime' => '2016-11-10', //结束时间 'applyEndTime' => $condition['endTime'], //结束时间
'choosedtabNow' => '', 'choosedtabNow' => '',
'processTypeName' => '', //订单类型名称 'processTypeName' => $condition['processTypeName'], //订单类型名称
'processType' => '' //订单类型编号 'processType' => $condition['processType'] //订单类型编号
]; ];
//return_msg(true, '', $post);
//debug
$this->Debug('ServiceOrder-condition', $post);
$result = [];
switch ($type) { switch ($type) {
case 1: case 1:
$post['choosedFlag'] = '0'; $post['choosedFlag'] = '0';
...@@ -116,12 +90,87 @@ class SourceSuning extends Source ...@@ -116,12 +90,87 @@ class SourceSuning extends Source
$result = $this->ServiceOrderTab1($post); $result = $this->ServiceOrderTab1($post);
break; break;
default: default:
$result = []; return_msg('false', 'type参数错误');
} }
return $result; return $result;
} }
/**
* 服务订单查询条件
* @return array
*/
public function SelectServiceOrderCondition()
{
$url = "https://asvp.suning.com/asvp/serviceorderquery/selectServiceOrder.action";
$headers = $this->Header($url);
$result = $this->CurlHttpsGet($url, $headers);
//select名称
$selectName = ['siteBp','processType', 'orderStatus'];
$condition = $this->HandelServiceOrderCondition($result['data'], $selectName);
//mark
$condition['mark'] = $this->OrderFormValue($result['data'], $this->OrderFormReg("mark"));
return $condition;
}
/**
* 服务订单查询
* @param $condition
* @return array
*/
public function SelectServiceOrder($condition)
{
$post = [
'mark' => $condition['mark'],
'partner' => $condition['siteBp'],
'objectId' => $condition['objectIds'],
'mobPhoneNum' => $condition['phone'],
'startTime' => $condition['startTime'],
'endTime' => $condition['endTime'],
'printTypeName' => $condition['processTypeName'],
'processType' => $condition['processType'],
'statusName' => $condition['orderStatusName'],
'orderStatus' => $condition['orderStatus']
];
//debug
$this->Debug('SelectServiceOrder-post', $post);
$url = "https://asvp.suning.com/asvp/serviceorderquery/selectServiceOrder.action";
$headers = $this->Header($url);
$result = $this->CurlHttpsPost($url, $post, $headers);
//debug
$this->Debug('ServiceOrderTab1-html', $result);
//订单处理
$list = $this->HandelServiceOrder($result['data']);
return $list;
}
/**
* 接收订单作业
* @param $orderIds
* @return array
*/
public function ReceiveServiceOrder($orderIds)
{
$url = "https://asvp.suning.com/asvp/serviceOrder/receiveServiceOrder.action";
$headers = $this->Header("https://asvp.suning.com/asvp/serviceOrder/serviceOrderTab1.action");
$result = $this->CurlHttpsPost($url, $orderIds, $headers, 'json');
//debug
$this->Debug('ReceiveServiceOrder', $result);
return $result;
}
/** /**
* 返回待接收的订单数据 * 返回待接收的订单数据
* @param $param * @param $param
...@@ -138,9 +187,41 @@ class SourceSuning extends Source ...@@ -138,9 +187,41 @@ class SourceSuning extends Source
$this->Debug('ServiceOrderTab1-html', $result); $this->Debug('ServiceOrderTab1-html', $result);
//订单处理 //订单处理
$result = $this->HandelServiceOrder($result['data']); $list = $this->HandelServiceOrder($result['data']);
return $result; return $list;
}
/**
* 处理订单查询条件
* @param $html
* @param $selectName
* @return array
*/
private function HandelServiceOrderCondition($html, $selectName)
{
//select
preg_match_all('/<div[^>]+class="fake-select-option"[^>]*>[\s\S]+?<\/div>/', $html, $select);
//debug
$this->Debug('HandelServiceOrderCondition', $select);
$condition = [];
if (isset($select[0]) && $select[0]) {
foreach ($select[0] as $key => $val) {
preg_match_all('/<span[^>]+code="([^"]+)"[^>]*>([\s\S]+?)<\/span>/', $val, $option);
$temp = [];
foreach ($option[1] as $k => $v) {
$temp[$v] = preg_replace('/\s+/', '', $option[2][$k]);
}
$temp && $condition[$selectName[$key]] = $temp;
}
}
return $condition;
} }
/** /**
...@@ -314,6 +395,9 @@ class SourceSuning extends Source ...@@ -314,6 +395,9 @@ class SourceSuning extends Source
preg_match('/errorCode = "([^"]+)"/', $vcresult['data'], $vcErrorCode); preg_match('/errorCode = "([^"]+)"/', $vcresult['data'], $vcErrorCode);
//debug
$this->Debug('Loing-needVerifyCode', [$post, $vcresult, $vcErrorCode]);
$vcHandelResult = $this->HandelLoginReturnMsg($vcErrorCode[1], $vcresult['data'], $post); $vcHandelResult = $this->HandelLoginReturnMsg($vcErrorCode[1], $vcresult['data'], $post);
$result = array_merge($vcresult, $vcHandelResult); $result = array_merge($vcresult, $vcHandelResult);
} else { } else {
...@@ -427,15 +511,15 @@ class SourceSuning extends Source ...@@ -427,15 +511,15 @@ class SourceSuning extends Source
*/ */
public function GetPhoneCode($num = 0) public function GetPhoneCode($num = 0)
{ {
$result = parent::GetMailPhoneCode(); $result = phone_code();
if ($num > 45) { if ($num > 60) {
return false; return false;
} }
if (empty($result) || $result['st'] > 15) { if (empty($result) || $result['st'] > 15) {
$num++; $num++;
sleep(1); usleep(2500);
return $this->GetPhoneCode($num); return $this->GetPhoneCode($num);
} }
...@@ -518,7 +602,7 @@ class SourceSuning extends Source ...@@ -518,7 +602,7 @@ class SourceSuning extends Source
$result = $this->CurlHttpsPost($loginUrl, $post, $headers); $result = $this->CurlHttpsPost($loginUrl, $post, $headers);
//debug //debug
$this->Debug('ToAutoLogin', $data); $this->Debug('ToAutoLogin', [$data, $result]);
return $result; return $result;
} }
...@@ -549,18 +633,21 @@ class SourceSuning extends Source ...@@ -549,18 +633,21 @@ class SourceSuning extends Source
return $header; return $header;
} }
private function Debug($function, $data)
private function CurlHttpsPost($url, $post, $headers, $type='')
{ {
if (self::$debug) { $result = parent::CurlPostHttps($url, $post, $headers, $type);
echo "{$function}<br/>";
echo "<pre>"; if ($result['data']) {
print_r($data); $result['data'] = gzdecode($result['data']);
} }
return $result;
} }
private function CurlHttpsPost($url, $post, $headers) private function CurlHttpsGet($url, $headers)
{ {
$result = parent::CurlPostHttps($url, $post, $headers); $result = parent::CurlGetHttps($url, $headers);
if ($result['data']) { if ($result['data']) {
$result['data'] = gzdecode($result['data']); $result['data'] = gzdecode($result['data']);
...@@ -584,5 +671,65 @@ class SourceSuning extends Source ...@@ -584,5 +671,65 @@ class SourceSuning extends Source
return $formData; return $formData;
} }
/**
* 匹配表单值
* @param $html
* @param $reg
* @param string $type
* @return int|string
*/
private function OrderFormValue($html, $reg, $type='text')
{
preg_match("/$reg/", $html, $val);
switch ($type) {
case 'select':
$result = isset($val[1]) ? $val[1] : '';
break;
case 'checkbox':
$result = isset($val[1]) && $val[1]=='checked' ? 1 : 0;
break;
case 'span':
$result = isset($val[1]) ? $val[1] : '';
break;
default:
$result = isset($val[1]) ? $val[1] : '';
}
return $result;
}
/**
* 订单表单参数正则
*
* @param string $id 表单ID
* @param string $type 表单类型
* @return string
*/
private function OrderFormReg($id, $type='text')
{
switch ($type) {
case 'select':
$result = 'id="'. $id .'"[\s\S]+?selected="selected"[^>]+value="([^"]*)"[^>]*>([^\<]*)<';
break;
case 'checkbox':
$result = 'id="'. $id .'"[^>]+checked="([^"]*)"';
break;
case 'span':
$result = 'id="'. $id .'"[^>]*>([^<]*)<\/span>';
break;
default:
$result = 'id="'. $id .'"[^>]+value="([^"]*)"';
}
return $result;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment