stanley-king il y a 4 mois
Parent
commit
0679097ba0

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

@@ -17,20 +17,16 @@ class RefillCallBack implements refill\IRefillCallBack
         $order_sn = $params['order_sn'];
         $status = intval($params['status']);
         $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
-        if (empty($order_info))
-        {
+        if (empty($order_info)) {
             return [false, false, false, false];
         }
         $order_id = $order_info['order_id'];
-        if ($status === 1)
-        {
+
+        if ($status === 'SUCCESS') {
             return [$order_id, true, false, true];
-        }
-        elseif ($status === 0) {
+        } elseif ($status === 'CANCEL') {
             return [$order_id, false, true, true];
-        }
-        else
-        {
+        } else {
             return [$order_id, false, false, false];
         }
     }

+ 25 - 0
helper/refill/api/xyz/yifutong/RefillPhone.php

@@ -16,9 +16,34 @@ class RefillPhone extends refill\IRefillPhone
 
     public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
     {
+        $mod_refill = Model('refill_order');
+        $order_sn = $params['order_sn'];
+        $refill_info = $mod_refill->getOrderInfo(['order_sn' => $order_sn]);
+        $mch_order = $refill_info['mch_order'];
+
+        $cbparams = refill\util::read_yifutong_order($mch_order);
+        $this->send_normal($order_sn, $cbparams);
         return [true, '', false];
     }
 
+    public static function send_normal($order_sn,$cbparams)
+    {
+        go(function () use ($order_sn,$cbparams)
+        {
+            sleep(1);
+            while (true)
+            {
+                $net_errno = 0;
+                $resp = http_request($cbparams['notify_url'],['status' => $cbparams['status'],'order_sn' => $order_sn],'GET', false, [], $net_errno);
+                if($resp == 'SUCCESS') {
+                    break;
+                }
+            }
+
+            Log::record("resp = $resp",Log::DEBUG);
+        });
+    }
+
     public function query($refill_info): array
     {
         $mod_order = Model('vr_order');

+ 12 - 0
helper/refill/util.php

@@ -1071,4 +1071,16 @@ class util
 
         return $ret;
     }
+
+    public static function write_yifutong_order($mch_order,$params)
+    {
+        wcache('yifutong_order', [$mch_order => serialize($params)], 'yft-');
+    }
+
+    public static function read_yifutong_order($mch_order)
+    {
+        $data = rcache('yifutong_order', 'yft-', $mch_order);
+        $val = empty($data[$mch_order]) ? [] : unserialize($data[$mch_order]);
+        return $val;
+    }
 }

+ 4 - 0
mobile/callback/refill_yifutong.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('yifutong',$_POST);
+echo ('SUCCESS');

+ 71 - 7
test/TestSSH2.php

@@ -9,6 +9,8 @@ define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
 require_once(BASE_ROOT_PATH . '/global.php');
 require_once(BASE_CORE_PATH . '/lrlz.php');
 require_once(BASE_ROOT_PATH . '/fooder.php');
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
 
 function my_ssh_disconnect($reason, $message, $language) {
     printf("Server disconnected with reason code [%d] and message: %s\n",
@@ -46,12 +48,6 @@ class TestSSH2 extends TestCase
         ssh2_disconnect($connection);
     }
 
-    public function testAddOrder()
-    {
-        #卡号|订单号(唯一的)|  状态(只给成功)|  面值  |运营商流水凭证|  手机号| 创建时间|交易成功时间
-    }
-
-
     //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestSSH2::testConnectYFT)( .*)?$/" --test-suffix TestSSH2.php /var/www/html/test
     public function testConnectYFT()
     {
@@ -93,6 +89,9 @@ class TestSSH2 extends TestCase
             Log::record("$remote_file not exist.", Log::DEBUG);
             return false;
         }
+        else {
+            Log::record("find file=$remote_file",LOg::DEBUG);
+        }
 
         $local_file = BASE_DATA_PATH . "/log/$name";
 
@@ -111,6 +110,71 @@ class TestSSH2 extends TestCase
         $cur_time = time();
         $a = strftime("%Y%m%d_000110089970029",$cur_time);
         Log::record("$a", Log::DEBUG);
+        $start_date = strtotime('20241211164754');
+        Log::record("$start_date", Log::DEBUG);
+        $a = strftime("%Y-%m-%d %H:%M:%S",$start_date);
+
     }
-}
 
+    public function testParase()
+    {
+        #卡号|订单号(唯一的)|  状态(只给成功)|  面值  |运营商流水凭证|  手机号| 创建时间|交易成功时间
+        #5|3456.00
+
+        $text = '9629980601009991|62241211164700945495|成功|938|6200945495|13391703053|20241211164725|20241211164754';
+
+        $matcher = function ($input)
+        {
+            $data = explode('|', $input);
+            $count = count($data);
+            if ($count === 8) {
+                return [
+                    'bank_card' => trim($data[0]),
+                    'mch_order' => trim($data[1]),
+                    'status' => 'SUCCESS',
+                    'amount' => 1,
+                    'org_quality' => 2,
+                    'quantity' => intval(trim($data[3])),
+                    'official_sn' => trim($data[4]),
+                    'card_no' => trim($data[5]),
+                    'order_time' => strtotime(trim($data[6])),
+                    'finish_time' => strtotime(trim($data[7]))
+                ];
+            }
+            elseif($count === 2) {
+                return [
+                    'count' => intval(trim($data[0])),
+                    'total' => intval(trim($data[1]))
+                ];
+            }
+            else {
+                return false;
+            }
+        };
+
+        $result = $matcher($text);
+
+        $minfo = $this->mchinfo(1092);
+        $params = array_merge($result,$minfo,['notify_url' => 'https://www.xyzshops.cn/mobile/callback/refill_yifutong.php']);
+        $mch_order = $params['mch_order'];
+        refill\util::write_yifutong_order($mch_order,$params);
+        $val = refill\util::read_yifutong_order($mch_order);
+        refill\util::push_add($params);
+    }
+
+    public function testGetMchinfo()
+    {
+        $minfo = $this->mchinfo(1092);
+
+    }
+
+    private function mchinfo($mchid)
+    {
+        $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
+        if(empty($mchinfo)) {
+            return false;
+        }
+
+        return ['mchid' =>$mchid, 'buyer_id' => intval($mchinfo['admin_id'])];
+    }
+}