Commit bd796fa2 authored by 蒋林's avatar 蒋林

苏宁订单作业接口

parent f0c864f5
......@@ -75,9 +75,9 @@ $query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.1.181',
'username' => 'pp_share',
'password' => '123456',
'hostname' => '192.168.1.33:3304',
'username' => 'pp_wxh',
'password' => '8v@XRSQ#EMVo!JdRUK@xvZ#Lk',
'database' => 'pp_wxh',
'dbdriver' => 'mysqli',
'dbprefix' => 'wxh_',
......
......@@ -12,7 +12,7 @@ class SourceSuning extends Source
{
private static $account = [];
private static $app = 'suning';
private static $debug = true;
private static $debug = false;
public function __construct($account)
......@@ -21,7 +21,6 @@ class SourceSuning extends Source
self::$cookieFilePath = PUBDIR . "cookie/" . self::$app . "_" . md5(self::$account['username']) . ".cookie";
self::$captchaFilePath = PUBDIR . "captcha/" . self::$app . "_" . md5(self::$account['username']) . ".gif";
//判断是否登陆
$isLogin = $this->IsLogin();
if ($isLogin == false) {
......@@ -29,6 +28,177 @@ class SourceSuning extends Source
}
}
/**
* 服务订单作业条件
* @param int $type 1:待接收; 2:可重派; 3:待核销;
* @return array
*/
public function ServiceOrderCondition($type = 1)
{
$type = $type - 1;
$post = [
'choosedtab' => $type
];
$url = "https://asvp.suning.com/asvp/serviceOrder/toMain.action";
$headers = $this->Header($url);
$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名称
$selectName = ['siteBp','processType'];
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;
}
public function ServiceOrderQuery()
{
$post = [
'mark' => '1',
'partner' => '904102',
'objectId' => '',
'mobPhoneNum' => '',
'startTime' => '',
'endTime' => '',
'printTypeName' => '',
'processType' => '',
'statusName' => '',
'orderStatus' => ''
];
}
/**
* 服务订单作业
* @param int $type 1:待接收; 2:可重派; 3:待核销;
* @return array
*/
public function ServiceOrder($type = 1)
{
$post = [
'choosedFlag' => '', //类型
'siteBp' => '904102', //网点BP
'objectIds' => '', //订单号,多个用(,)隔开
'applyStartTime' => '2016-10-20', //开始时间
'applyEndTime' => '2016-11-10', //结束时间
'choosedtabNow' => '',
'processTypeName' => '', //订单类型名称
'processType' => '' //订单类型编号
];
switch ($type) {
case 1:
$post['choosedFlag'] = '0';
$post['choosedtabNow'] = '0';
$result = $this->ServiceOrderTab1($post);
break;
default:
$result = [];
}
return $result;
}
/**
* 返回待接收的订单数据
* @param $param
* @return array
*/
private function ServiceOrderTab1($param)
{
$url = 'https://asvp.suning.com/asvp/serviceOrder/serviceOrderTab1.action';
$headers = $this->Header($url);
$result = $this->CurlHttpsPost($url, $param, $headers);
//debug
$this->Debug('ServiceOrderTab1-html', $result);
//订单处理
$result = $this->HandelServiceOrder($result['data']);
return $result;
}
/**
* 处理订单列表数据
* @param $orderHtml
* @return array
*/
private function HandelServiceOrder($orderHtml)
{
$order = [];
//table
preg_match('/<table[^>]+class="order-table-search"[^>]*>[\s\S]+?<\/table>/', $orderHtml, $table);
//debug
$this->Debug('ServiceOrderTab1-table', $table);
if (!isset($table[0]) && !$table[0]) {
return $order;
}
//tbody
preg_match('/<tbody[^>]*>[\s\S]+?<\/tbody>/', $table[0], $tbody);
//debug
$this->Debug('ServiceOrderTab1-tbody', $tbody);
if (!isset($tbody[0]) && !$tbody[0]) {
return $order;
}
//order
preg_match_all('/class="order-number"([^>]+)>/', $tbody[0], $srvOrder);
if (!isset($srvOrder[1]) && !$srvOrder[1]) {
return $order;
}
foreach ($srvOrder[1] as $key => $val) {
$val = preg_replace('/"\s+/', '",', trim($val));
$val = explode(',', str_replace('"', '', $val));
if (!empty($val)) {
foreach ($val as $vall) {
$vall = explode("=", $vall);
$order[$key][$vall[0]] = html_entity_decode($vall[1]);
}
}
}
return $order;
}
/**
* 判断是否登录, 及手机验证登录流程
* @return bool
*/
public function IsLogin()
{
$isLogin = $this->IsLoginHtml();
......@@ -73,16 +243,18 @@ class SourceSuning extends Source
return $this->IsLoginHtml();
}
/**
* 判断是否需要登录的页面
* @return bool
*/
public function IsLoginHtml()
{
$url = "https://asvp.suning.com/asvp/portal/jumpToportal.action";
$result = $this->GetUrlContents($url, false);
$result = $this->HandelHtmlScript($result);
//调试
if (self::$debug) {
$this->Debug('IsLoginHtml', $result);
}
//debug
$this->Debug('IsLoginHtml', $result);
$islogin = false;
if (stripos($result, 'showIndex.action') !== false) {
......@@ -92,6 +264,10 @@ class SourceSuning extends Source
return $islogin;
}
/**
* 登录页面处理
* @return array
*/
public function Login()
{
$loginUrl = "https://mpassport.suning.com/ids/login?service=https%3A%2F%2Fasvp.suning.com%2Fasvp%2Fportal%2Flogon.do&loginTheme=asvp";
......@@ -122,6 +298,9 @@ class SourceSuning extends Source
//登陆返回处理
preg_match('/errorCode = "([^"]+)"/', $result['data'], $errorCode);
//debug
$this->Debug('Login', [$post, $result, $errorCode]);
//登陆返回参数
if (isset($errorCode[1]) && $errorCode[1]) {
......@@ -143,13 +322,16 @@ class SourceSuning extends Source
}
}
if (self::$debug) {
$this->Debug('Login', [$post, $result]);
}
return $result;
}
/**
* 登录返回参数处理
* @param $errorCode
* @param $loginHtml
* @param $loginFormData
* @return array
*/
private function HandelLoginReturnMsg($errorCode, $loginHtml, $loginFormData)
{
$result = [];
......@@ -218,14 +400,18 @@ class SourceSuning extends Source
return $result;
}
/**
* 登陆后需要手机验证的页面
* @param $checkPhoneUrl
* @return array
*/
public function CheckPhone($checkPhoneUrl)
{
$result = $this->GetUrlContents($checkPhoneUrl);
$formData = $this->GetFormData($result);
if (self::$debug) {
$this->Debug('CheckPhone', $formData);
}
//debug
$this->Debug('CheckPhone', $formData);
if (empty($formData)) {
return_msg(false, '手机短信验证表单参数错误');
......@@ -234,15 +420,20 @@ class SourceSuning extends Source
return $formData;
}
/**
* 获取手机验证码
* @param int $num
* @return array|bool
*/
public function GetPhoneCode($num = 0)
{
$result = parent::GetPhoneCode();
$result = parent::GetMailPhoneCode();
if ($num > 45) {
return false;
}
if ($result['st'] > 60) {
if (empty($result) || $result['st'] > 15) {
$num++;
sleep(1);
return $this->GetPhoneCode($num);
......@@ -251,6 +442,12 @@ class SourceSuning extends Source
return $result;
}
/**
* 发送手机验证码
* @param $data
* @param $checkPhoneUrl
* @return array
*/
public function SendPhoneCode($data, $checkPhoneUrl)
{
$sendData = [
......@@ -263,9 +460,8 @@ class SourceSuning extends Source
$sendPhoneCodeUrl = "https://masc.suning.com/masc/suspiciousOpt/toSendValCodeSuspiciousLogin.htm";
$result = $this->CurlHttpsPost($sendPhoneCodeUrl, $sendData, $headers);
if (self::$debug) {
$this->Debug('SendPhoneCode', $sendData);
}
//debug
$this->Debug('SendPhoneCode', $sendData);
if ($result['data'] == 6) {
return_msg(false, '您当前累计获取验证码已达到5次,请您1小时后重新获取验证码');
......@@ -274,6 +470,12 @@ class SourceSuning extends Source
return $result;
}
/**
* 检验手机验证码
* @param $data
* @param $checkPhoneUrl
* @return array
*/
public function CheckPhoneCode($data, $checkPhoneUrl)
{
$checkData = [
......@@ -286,13 +488,18 @@ class SourceSuning extends Source
$checkPhoneCodeUrl = "https://masc.suning.com/masc/suspiciousOpt/validateCodeSuspiciousLogin.htm";
$result = $this->CurlHttpsPost($checkPhoneCodeUrl, $checkData, $headers);
if (self::$debug) {
$this->Debug('CheckPhoneCode', $checkData);
}
//debug
$this->Debug('CheckPhoneCode', $checkData);
return $result;
}
/**
* 手机验证码检验通过后,自动登录
* @param $data
* @param $checkPhoneUrl
* @return array
*/
public function ToAutoLogin($data, $checkPhoneUrl)
{
......@@ -310,27 +517,8 @@ class SourceSuning extends Source
$loginUrl = "https://masc.suning.com/masc/suspiciousOpt/toAutoLogin.htm";
$result = $this->CurlHttpsPost($loginUrl, $post, $headers);
return $result;
}
public function OrderList()
{
$url = 'https://asvp.suning.com/asvp/serviceOrder/serviceOrderTab1.action';
$post = [
'choosedFlag' => 0,
'siteBp' => 904102,
'objectIds' => '',
'applyStartTime' => '',
'applyEndTime' => '',
'choosedtabNow' => 0,
'processTypeName' => '',
'processType' => ''
];
$headers = $this->Header($url);
$result = $this->CurlHttpsPost($url, $post, $headers);
//debug
$this->Debug('ToAutoLogin', $data);
return $result;
}
......@@ -363,9 +551,11 @@ class SourceSuning extends Source
private function Debug($function, $data)
{
echo "{$function}<br/>";
echo "<pre>";
print_r($data);
if (self::$debug) {
echo "{$function}<br/>";
echo "<pre>";
print_r($data);
}
}
private function CurlHttpsPost($url, $post, $headers)
......
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