瀏覽代碼

Merge branch 'rch' into raccount

zhaoming 1 年之前
父節點
當前提交
0f7e903f21
共有 2 個文件被更改,包括 36 次插入1 次删除
  1. 15 1
      helper/refill/api/xyz/xinma/RefillCallBack.php
  2. 21 0
      test/TestRefill.php

+ 15 - 1
helper/refill/api/xyz/xinma/RefillCallBack.php

@@ -26,6 +26,20 @@ class RefillCallBack implements refill\IRefillCallBack
 
     public function notify($params)
     {
+        $extractOfficialSn = function ($officialSnStr) {
+            $officialSn = '';
+
+            $matches = [];
+            if (preg_match_all("/(\d+)/", $officialSnStr, $matches)) {
+                foreach ($matches[1] as $item) {
+                    if (strlen($officialSn) < strlen($item)) {
+                        $officialSn = $item;
+                    }
+                }
+            }
+            return $officialSn;
+        };
+
         $status = intval($params['status']);
         $order_sn = $params['user_order_id'];
         $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
@@ -35,7 +49,7 @@ class RefillCallBack implements refill\IRefillCallBack
         $order_id = $order_info['order_id'];
 
         if ($status === 200) {
-            $official_sn = strtolower($params['official_order_id']) == 'null' ? '' : $params['official_order_id'];
+            $official_sn = $extractOfficialSn($params['official_order_id']);
             $data['official_sn'] = $official_sn;
             Model('refill_order')->edit($order_id, $data);
             return [$order_id, true, false, true, $official_sn];

+ 21 - 0
test/TestRefill.php

@@ -5587,6 +5587,27 @@ class TestRefill extends TestCase
         $s = implode(',',$diff);
     }
 
+    public function testXinmaOfficialSn()
+    {
+        $extractOfficialSn = function ($officialSnStr) {
+            $officialSn = '';
+
+            $matches = [];
+            if (preg_match_all("/(\d+)/", $officialSnStr, $matches)) {
+                foreach ($matches[1] as $item) {
+                    if (strlen($officialSn) < strlen($item)) {
+                        $officialSn = $item;
+                    }
+                }
+            }
+            return $officialSn;
+        };
+
+        $s0 = $extractOfficialSn('');
+        $s1 = $extractOfficialSn('1623091817214688');
+        $s3 = $extractOfficialSn('【中国石化】您尾号为869682的加油卡于09月18日 17时21分充值成功,金额200元,订单号:1623091817214688');
+    }
+
 }
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test