Explorar o código

back kdn_helper

stanley-king %!s(int64=6) %!d(string=hai) anos
pai
achega
019a3d56bc

+ 1 - 1
crontab/control/command.php

@@ -320,7 +320,7 @@ class commandControl extends BaseCronControl
                 if (isset($deliver_info['Success']) && $deliver_info['Success'] == false)
                 {
                     Log::record("重新订阅 {$e_name}::{$order['shipping_code']}, order:{$order['order_sn']}",Log::DEBUG);
-                    kdn_helper_new::req_subscribe($e_code, $order['shipping_code'],$order['order_sn']);
+                    kdn_helper::req_subscribe($e_code, $order['shipping_code'],$order['order_sn']);
                 }
             }
         }

+ 1 - 1
data/logic/queue.logic.php

@@ -594,7 +594,7 @@ class queueLogic
         }
 
         try {
-            kdn_helper_new::subscribe($param['order_sn']);
+            kdn_helper::subscribe($param['order_sn']);
         } catch (Exception $e) {
             Log::record("kdn_helper_new: fall error\treturn:" . $e->getMessage() . "\t param:" . json_encode($param));
         }

+ 3 - 109
helper/kdn_helper.php

@@ -2,119 +2,13 @@
 /**
  * Created by PhpStorm.
  * User: stanley-king
- * Date: 16/3/30
- * Time: 下午5:10
+ * Date: 2018/8/9
+ * Time: 下午7:52
  */
 
 require_once (BASE_CORE_PATH . "/framework/function/http.php");
-class kdn_helper
-{
-    const req_url = 'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx';
-
-//1256766   22c88d88-3565-4023-b5ac-0201792869ed
-//1256767   e02cd836-3146-4958-b1dc-c1585fa05b9e
-//1256768   e7eb7d2f-0525-484e-80ba-c8f5b5a90af3
-
-    static public function query($shipperCode, $logisticCode)
-    {
-        $requestData = json_encode(array('ShipperCode' => $shipperCode,'LogisticCode' => $logisticCode));
-
-        $account = self::get_account();
-        Log::record("EBusinessID={$account}",Log::DEBUG);
-        $datas = array(
-            'EBusinessID' => $account['EBusinessID'],
-            'RequestType' => '1002',
-            'RequestData' => urlencode($requestData),
-            'DataType' => '2',
-            'DataSign' => self::encrypt($requestData, $account['AppID'])
-        );
-        $result = http_post_data(self::req_url,$datas);
-        return $result;
-    }
-    static public function cur_businessid() {
-        $account = self::get_account();
-        return $account['EBusinessID'];
-    }
-
-    static public function get_account()
-    {
-        if(defined('MOBILE_PUBLISH') && MOBILE_PUBLISH == true) {
-            return array('EBusinessID' => '1256766','AppID' => '22c88d88-3565-4023-b5ac-0201792869ed');
-        } else {
-            return array('EBusinessID' => '1256051','AppID' => '6718d260-e2b6-4329-ad78-daff173309ac');
-        }
-    }
 
-    static private function encrypt($data, $appkey)
-    {
-        return urlencode(base64_encode(md5($data . $appkey)));
-    }
-
-    static public function subscribe($order_sn)
-    {
-        $model_order = Model('order');
-        $condition['order_sn'] = $order_sn;
-        $order_info = $model_order->getOrderInfo($condition, array('order_common', 'order_goods'));
-        // 发送快递鸟订阅回调
-        $express = rkcache('express', true);
-        $e_code = $express[$order_info['extend_order_common']['shipping_express_id']]['e_kdn_code'];
-        if(empty($e_code)) {
-            Log::record("找不到该单号的快递公司编码—— ordersn={$order_sn}",Log::ERR);
-            return;
-        }
-        // 通知订阅, 快递鸟定时回调
-        $ret = self::req_subscribe($e_code, $order_info['shipping_code'], $order_sn);
-        if($ret === false) {
-            Log::record("kdn_helper::subscribe order_sn={$order_sn} error.",Log::ERR);
-        } else {
-            Log::record("kdn_helper::subscribe ret={$ret}",Log::DEBUG);
-        }
-    }
-
-    static public function req_subscribe($e_code, $logisticCode, $order_sn)
-    {
-        $datas = array(array('Code' => $e_code,'Item' => array(array('No' => $logisticCode,'Bk' => $order_sn))));
-        $requestData = json_encode($datas);
-
-        $account = self::get_account();
-        $datas = array(
-            'EBusinessID' => $account['EBusinessID'],
-            'RequestType' => '1005',
-            'RequestData' => urlencode($requestData),
-            'DataType' => '2',
-            'DataSign' => self::encrypt($requestData, $account['AppID'])
-        );
-        $result = http_post_data(self::req_url, $datas);
-        return $result;
-    }
-
-    static public function onCallback($data)
-    {
-        $order_sn = $data['CallBack'];
-        if(empty($order_sn)) return;
-
-        $e_code = $data['ShipperCode'];
-        $shipping_code = $data['LogisticCode'];
-        $key = "express_{$e_code}_{$shipping_code}";
-        wkcache($key, $data);
-        // 数据解析
-        switch ($data['State'])
-        {
-            case '3':	// 已签收, 设置为已收货
-                Log::record(__METHOD__ . " order_sn={$order_sn},code = {$data['LogisticCode']} 已签收.",Log::ERR);
-                break;
-            case '4':	// 问题件
-                Log::record(__METHOD__ . " order_sn={$order_sn},code = {$data['LogisticCode']} 问题件.",Log::ERR);
-                break;
-            default: {
-                Log::record(__METHOD__ . ' query_status false');
-                break;
-            }
-        }
-    }
-}
-
-class kdn_helper_new
+class kdn_helper
 {
     private static $EBusinessID = 1366783;
     private static $AppKey    = "e62955d6-4871-4740-9ec9-62068a544ab5";

+ 116 - 0
helper/kdn_helper_back.php

@@ -0,0 +1,116 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/3/30
+ * Time: 下午5:10
+ */
+
+require_once (BASE_CORE_PATH . "/framework/function/http.php");
+class kdn_helper_back
+{
+    const req_url = 'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx';
+
+//1256766   22c88d88-3565-4023-b5ac-0201792869ed
+//1256767   e02cd836-3146-4958-b1dc-c1585fa05b9e
+//1256768   e7eb7d2f-0525-484e-80ba-c8f5b5a90af3
+
+    static public function query($shipperCode, $logisticCode)
+    {
+        $requestData = json_encode(array('ShipperCode' => $shipperCode,'LogisticCode' => $logisticCode));
+
+        $account = self::get_account();
+        Log::record("EBusinessID={$account}",Log::DEBUG);
+        $datas = array(
+            'EBusinessID' => $account['EBusinessID'],
+            'RequestType' => '1002',
+            'RequestData' => urlencode($requestData),
+            'DataType' => '2',
+            'DataSign' => self::encrypt($requestData, $account['AppID'])
+        );
+        $result = http_post_data(self::req_url,$datas);
+        return $result;
+    }
+    static public function cur_businessid() {
+        $account = self::get_account();
+        return $account['EBusinessID'];
+    }
+
+    static public function get_account()
+    {
+        if(defined('MOBILE_PUBLISH') && MOBILE_PUBLISH == true) {
+            return array('EBusinessID' => '1256766','AppID' => '22c88d88-3565-4023-b5ac-0201792869ed');
+        } else {
+            return array('EBusinessID' => '1256051','AppID' => '6718d260-e2b6-4329-ad78-daff173309ac');
+        }
+    }
+
+    static private function encrypt($data, $appkey)
+    {
+        return urlencode(base64_encode(md5($data . $appkey)));
+    }
+
+    static public function subscribe($order_sn)
+    {
+        $model_order = Model('order');
+        $condition['order_sn'] = $order_sn;
+        $order_info = $model_order->getOrderInfo($condition, array('order_common', 'order_goods'));
+        // 发送快递鸟订阅回调
+        $express = rkcache('express', true);
+        $e_code = $express[$order_info['extend_order_common']['shipping_express_id']]['e_kdn_code'];
+        if(empty($e_code)) {
+            Log::record("找不到该单号的快递公司编码—— ordersn={$order_sn}",Log::ERR);
+            return;
+        }
+        // 通知订阅, 快递鸟定时回调
+        $ret = self::req_subscribe($e_code, $order_info['shipping_code'], $order_sn);
+        if($ret === false) {
+            Log::record("kdn_helper::subscribe order_sn={$order_sn} error.",Log::ERR);
+        } else {
+            Log::record("kdn_helper::subscribe ret={$ret}",Log::DEBUG);
+        }
+    }
+
+    static public function req_subscribe($e_code, $logisticCode, $order_sn)
+    {
+        $datas = array(array('Code' => $e_code,'Item' => array(array('No' => $logisticCode,'Bk' => $order_sn))));
+        $requestData = json_encode($datas);
+
+        $account = self::get_account();
+        $datas = array(
+            'EBusinessID' => $account['EBusinessID'],
+            'RequestType' => '1005',
+            'RequestData' => urlencode($requestData),
+            'DataType' => '2',
+            'DataSign' => self::encrypt($requestData, $account['AppID'])
+        );
+        $result = http_post_data(self::req_url, $datas);
+        return $result;
+    }
+
+    static public function onCallback($data)
+    {
+        $order_sn = $data['CallBack'];
+        if(empty($order_sn)) return;
+
+        $e_code = $data['ShipperCode'];
+        $shipping_code = $data['LogisticCode'];
+        $key = "express_{$e_code}_{$shipping_code}";
+        wkcache($key, $data);
+        // 数据解析
+        switch ($data['State'])
+        {
+            case '3':	// 已签收, 设置为已收货
+                Log::record(__METHOD__ . " order_sn={$order_sn},code = {$data['LogisticCode']} 已签收.",Log::ERR);
+                break;
+            case '4':	// 问题件
+                Log::record(__METHOD__ . " order_sn={$order_sn},code = {$data['LogisticCode']} 问题件.",Log::ERR);
+                break;
+            default: {
+                Log::record(__METHOD__ . ' query_status false');
+                break;
+            }
+        }
+    }
+}
+

+ 1 - 1
mobile/control/member_order.php

@@ -346,7 +346,7 @@ class member_orderControl extends mbMemberControl
         $deliver_info = rkcache($key);
         if (empty($deliver_info))
         {
-            $deliver_info = kdn_helper_new::query($e_code, $order_info['shipping_code']);
+            $deliver_info = kdn_helper::query($e_code, $order_info['shipping_code']);
             if ($deliver_info === false || empty($deliver_info)) {
                 return self::outsuccess(NULL,'express/error','wap');
             }

+ 4 - 4
mobile/kdniao_notify.php

@@ -27,18 +27,18 @@ if (!empty($requestData))
     {
         Log::record("start handle....",Log::DEBUG);
         $count = intval($deliver_info['Count']);
-        if($count <= 0 || $deliver_info['EBusinessID'] != kdn_helper_new::cur_businessid()) {
+        if($count <= 0 || $deliver_info['EBusinessID'] != kdn_helper::cur_businessid()) {
             $success = false;
-            $reson = "count={$count} or EBusinessID = {$deliver_info['EBusinessID']} != " . kdn_helper_new::cur_businessid();
+            $reson = "count={$count} or EBusinessID = {$deliver_info['EBusinessID']} != " . kdn_helper::cur_businessid();
         }
         else
         {
             foreach($deliver_info['Data'] as $item) {
-                kdn_helper_new::onCallback($item);
+                kdn_helper::onCallback($item);
             }
         }
     }
 
-    echo (json_encode(array('EBusinessID' => kdn_helper_new::cur_businessid(),'UpdateTime' => strftime("%Y-%m-%d %H:%M:%S",time()), 'Success' => $success,'Reason' => $reson)));
+    echo (json_encode(array('EBusinessID' => kdn_helper::cur_businessid(),'UpdateTime' => strftime("%Y-%m-%d %H:%M:%S",time()), 'Success' => $success,'Reason' => $reson)));
 }
 ?>

+ 2 - 2
test/TestKdniao.php

@@ -29,7 +29,7 @@ class TestKdniao extends PHPUnit_Framework_TestCase
         $e_code     = "ZTO";
         $logisticCode   = "457209987858";
 
-        $ret = kdn_helper_new::query($e_code, $logisticCode);
+        $ret = kdn_helper::query($e_code, $logisticCode);
 
         var_dump($ret);
     }
@@ -40,7 +40,7 @@ class TestKdniao extends PHPUnit_Framework_TestCase
         $e_code     = "ZTO";
         $logisticCode   = "457209987858";
 
-        $subs = kdn_helper_new::req_subscribe($e_code, $logisticCode, $order_sn);
+        $subs = kdn_helper::req_subscribe($e_code, $logisticCode, $order_sn);
 
         var_dump($subs);
     }