Selaa lähdekoodia

Merge branch 'rshop' of 39.97.239.116:gyfl/xyzshop into dongrshop

dong 1 vuosi sitten
vanhempi
commit
03a31039cf

+ 7 - 9
helper/refill/api/xyz/leyou/RefillCallBack.php

@@ -19,28 +19,26 @@ class RefillCallBack implements refill\IRefillCallBack
     private function sign($params)
     {
         $key = config::APP_KEY;
-        $user_name = config::USER_NAME;
-        $content = "{$user_name}{$params['sys_order_id']}{$params['user_order_id']}{$key}";
+        $content = "{$params['username']}{$params['orderNumber']}{$params['number']}{$params['money']}[{$params['status']}]{$params['endTime']}$key";
         return md5($content);
     }
 
     public function notify($params)
     {
         $status = intval($params['status']);
-        $order_sn = $params['user_order_id'];
+        $order_sn = $params['orderNumber'];
         $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
         if (empty($order_info)) {
             return [false, false, false, false, ''];
         }
         $order_id = $order_info['order_id'];
 
-        if ($status === 200) {
-            $official_sn = strtolower($params['official_order_id']) == 'null' ? '' : $params['official_order_id'];
-            $data['official_sn'] = $official_sn;
-            Model('refill_order')->edit($order_id, $data);
-            return [$order_id, true, false, true, $official_sn];
+        if ($status === 5) {
+            $official_sn = config::extract_official_sn($params['voucher']);
+            Model('refill_order')->edit($order_id, ['official_sn' => $official_sn]);
+            return [$order_id, true, false, true, ''];
         }
-        elseif ($status === 202) {
+        elseif ($status === 6) {
             return [$order_id, false, true, true, ''];
         }
         else {

+ 25 - 14
helper/refill/api/xyz/leyou/RefillOil.php

@@ -80,25 +80,34 @@ class RefillOil extends refill\IRefillOil
         else
         {
             Log::record($resp, Log::DEBUG);
-
             $resp = json_decode($resp, true);
+
             if (empty($resp)) {
                 return [false, '网络错误'];
             }
-
-            $status = $resp['status'];
-
-            if ($status === 122600) {
-                $order_state = ORDER_STATE_SUCCESS;
+            elseif ($resp['status'] === 122600 )
+            {
+                $status = $resp['data']['status'];
+                if ($status === 5) {
+                    $official_sn = config::extract_official_sn($resp['data']['voucher']);
+                    Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $official_sn]);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 6) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } else
+                {
+                    $order_state = ORDER_STATE_SEND;
+                }
+
+                return [true, $order_state];
             }
-            elseif ($status === 122617) {
-                $order_state = ORDER_STATE_NOEXIST;
+            elseif ($resp['status'] === 122617) {
+                return [false, '订单不存在,需人工核实.'];
             }
-            else {
-                return [false, $status];
+            else
+            {
+                return [false, $resp['desc']];
             }
-            return [true, $order_state];
-
         }
     }
 
@@ -123,7 +132,8 @@ class RefillOil extends refill\IRefillOil
             elseif ($resp['status'] === 122600) {
                 return [true, $resp['data']];
             }
-            else {
+            else
+            {
                 return [false, $resp['desc']];
             }
         }
@@ -134,11 +144,12 @@ class RefillOil extends refill\IRefillOil
         $originalStr = '';
         foreach (config::SIGN_KEY_SORT as $key)
         {
-            if (isset($param[$key]) && !empty($param[$key])) {
+            if (!empty($param[$key])) {
                 $originalStr .= $param[$key];
             }
         }
         $originalStr .= config::APP_KEY;
+
         return md5($originalStr);
     }
 }

+ 10 - 0
helper/refill/api/xyz/leyou/config.php

@@ -51,4 +51,14 @@ class config
         'money',
         'orderTime'
     ];
+
+    public static function extract_official_sn($voucher): string
+    {
+        $matches = [];
+        if (preg_match("/\:(\d+)/", $voucher, $matches)) {
+            return $matches[1];
+        } else {
+            return '';
+        }
+    }
 }

+ 29 - 1
test/TestRefill.php

@@ -5341,10 +5341,38 @@ class TestRefill extends TestCase
     public function testLeyou_Query()
     {
         $provider = $this->getProvider('leyou','RefillOil');
-        $net_errno = '';
         [$succ, $val] = $provider->query(['order_sn'=>'Test-Leyou-Oil1693375143']);
     }
 
+    public function testLeyou_Waterno_By_Voucher()
+    {
+        $watorno1 = $this->Leyou_Waterno_By_Voucher('【中国石化】您尾号为211884的加油卡于08月30日 13时59分充值成功,金额50元,订单号:1623083013592106');
+        $watorno2 = $this->Leyou_Waterno_By_Voucher('【中国石化】您尾号为211884的加油卡于08月30日 13时59分充值成功,金额50元,订单号1623083013592106');
+        $watorno3 = $this->Leyou_Waterno_By_Voucher('【中国石化】您尾号为211884的加油卡于08月30日 13时59分充值成功,金额50元,订单号');
+        $watorno4 = $this->Leyou_Waterno_By_Voucher('');
+        $watorno5 = $this->Leyou_Waterno_By_Voucher(null);
+    }
+
+    private function Leyou_Waterno_By_Voucher($voucher):string
+    {
+        $matches = [];
+        $ret = preg_match("/\:(\d+)/",$voucher,$matches);
+        if ($ret === 1 && !empty($matches)){
+            return $matches[1];
+        }
+        return '';
+    }
+
+    public function testLeyou_CallBack()
+    {
+        $body = '{"username":"guoyan","orderNumber":"Test-Leyou-Oil1693375143","number":"1000111100021211884","money":50,"pay":50.6,"recharge":50,"status":5,"desc":"充值成功","voucher":"voucher","endTime":"2023-08-30 13:59:25","sign":"79fc766ae0eaf6539aef9f7ee3ee1f0f"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('leyou', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
+
 }
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test