Explorar el Código

乐友通道-回调处理

zhaoming hace 1 año
padre
commit
ccda204202

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

@@ -19,28 +19,24 @@ 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) {
+            return [$order_id, true, false, true, ''];
         }
-        elseif ($status === 202) {
+        elseif ($status === 6) {
             return [$order_id, false, true, true, ''];
         }
         else {

+ 7 - 5
helper/refill/api/xyz/leyou/RefillOil.php

@@ -69,7 +69,6 @@ class RefillOil extends refill\IRefillOil
 
     public function query($refill_info)
     {
-
         $waterno_by_voucher = function($voucher):string {
             $matches = [];
             $ret = preg_match("/\:(\d+)/",$voucher,$matches);
@@ -104,7 +103,8 @@ class RefillOil extends refill\IRefillOil
                     $order_state = ORDER_STATE_SUCCESS;
                 } elseif ($status === 6) {
                     $order_state = ORDER_STATE_CANCEL;
-                } else {
+                } else
+                {
                     $order_state = ORDER_STATE_SEND;
                 }
 
@@ -113,7 +113,8 @@ class RefillOil extends refill\IRefillOil
             elseif ($resp['status'] === 122617) {
                 return [false, '订单不存在,需人工核实.'];
             }
-            else {
+            else
+            {
                 return [false, $resp['desc']];
             }
         }
@@ -140,7 +141,8 @@ class RefillOil extends refill\IRefillOil
             elseif ($resp['status'] === 122600) {
                 return [true, $resp['data']];
             }
-            else {
+            else
+            {
                 return [false, $resp['desc']];
             }
         }
@@ -151,7 +153,7 @@ 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];
             }
         }

+ 13 - 2
test/TestRefill.php

@@ -5350,10 +5350,11 @@ class TestRefill extends TestCase
         $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('');
-        $watorno4 = $this->Leyou_Waterno_By_Voucher(null);
+        $watorno5 = $this->Leyou_Waterno_By_Voucher(null);
     }
 
-    private function Leyou_Waterno_By_Voucher($voucher):string {
+    private function Leyou_Waterno_By_Voucher($voucher):string
+    {
         $matches = [];
         $ret = preg_match("/\:(\d+)/",$voucher,$matches);
         if ($ret === 1 && !empty($matches)){
@@ -5362,6 +5363,16 @@ class TestRefill extends TestCase
         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