xiaoyu 2 年 前
コミット
4b2d6fc403

+ 10 - 28
helper/refill/api/xyz/oufei/RefillCallBack.php

@@ -8,43 +8,25 @@ class RefillCallBack implements refill\IRefillCallBack
 {
     public function verify($params): bool
     {
-        $sign = $this->sign($params);
-        if ($params['szVerifyString'] == $sign) {
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    private function sign($params)
-    {
-        $userid = config::USER_ID;
-        $key = config::KEY;
-        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nDemo={$params['nDemo']}&fSalePrice={$params['fSalePrice']}";
-        $content .= "&nFlag={$params['nFlag']}&szKey={$key}";
-        return md5($content);
+        return true;
     }
 
     public function notify($params)
     {
-        $status = intval($params['nFlag']);
-        $order_sn = $params['szOrderId'];
+        $status = intval($params['ret_code']);
+        $order_sn = $params['sporder_id'];
         $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
         if (empty($order_info)) {
-            return [false, false, false,false];
+//            return [false, false, false,false];
         }
         $order_id = $order_info['order_id'];
 
-        if ($status === 2) {
-            $data['official_sn'] = strtolower($params['szRtnMsg']) == 'null' ? '' : $params['szRtnMsg'];
-            Model('refill_order')->edit($order_id, $data);
-            return [$order_id, true, false,true];
-        }
-        elseif ($status === 3) {
-            return [$order_id, false, true,true];
-        }
-        else {
-            return [$order_id, false, false,false];
+        if ($status === 1) {
+            return [$order_id, true, false, true];
+        } elseif ($status === 9) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
         }
     }
 }

+ 39 - 26
helper/refill/api/xyz/oufei/RefillOil.php

@@ -7,7 +7,7 @@ require_once(BASE_HELPER_RAPI_PATH . '/oufei/config.php');
 use refill;
 use Log;
 
-class RefillPhone extends refill\IRefillPhone
+class RefillOil extends refill\IRefillPhone
 {
     public function __construct($cfgs)
     {
@@ -44,16 +44,16 @@ class RefillPhone extends refill\IRefillPhone
         else
         {
             Log::record($resp, Log::DEBUG);
-            $resp = refill\util::xmlToArray($resp);
+            $resp = $this->xmlToArray($resp);
 
             $retCode = $resp['retCode'];
             if (empty($resp)) {
                 return [false, '网络错误', true];
-            } elseif ($retCode === 1) {
+            } elseif ($retCode === '1') {
                 return [true, $resp['orderId'], false];
             } elseif (in_array($retCode, config::ERR_NOS, true)) {
                 return [false, $resp['errMsg'], false];
-            } elseif ($retCode === 9999) {
+            } elseif ($retCode === '9999') {
                 $net_errno = "HTTP-{$retCode}";
                 return [false, $resp['errMsg'], true];
             } else {
@@ -67,13 +67,12 @@ class RefillPhone extends refill\IRefillPhone
     public function query($refill_info)
     {
         $params['userid'] = config::USER_ID;
-        $params['userPws'] = md5(config::USER_PWS);
+        $params['userpws'] = md5(config::USER_PWS);
         $params['sporder_id'] = $refill_info['order_sn'];
         $params['version'] = '6.0';
-        $params['format'] = 'json';
 
         $key = config::KEY;
-        $content = "{$params['userid']}{$params['userPws']}{$params['sporder_id']}{$key}";
+        $content = "{$params['userid']}{$params['userpws']}{$params['sporder_id']}{$key}";
         $params['md5_str'] = strtoupper(md5($content));
 
         $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
@@ -84,34 +83,40 @@ class RefillPhone extends refill\IRefillPhone
         else
         {
             Log::record($resp, Log::DEBUG);
-            $resp = json_decode($resp, true);
+            $resp = $this->xmlToArray($resp, 'GB2312');
             if (empty($resp)) {
                 return [false, '网络错误'];
             }
-
-            $status = $resp['retcode'];
-            if ($status === 5012) {
-                $updata['official_sn'] = $resp['szRtnMsg'];
-                Model('refill_order')->edit($refill_info['order_id'], $updata);
-                $order_state = ORDER_STATE_SUCCESS;
-            } elseif ($status === 5013) {
-                $order_state = ORDER_STATE_CANCEL;
-            } elseif (in_array($status, [5011,5019],true)) {
-                $order_state = ORDER_STATE_SEND;
-            } elseif ($status === 5005 && (time() - $refill_info['commit_time'] >= 300)) {
-                $order_state = ORDER_STATE_NOEXIST;
-            } else {
-                return [false, $resp['szRtnMsg']];
+            elseif ($resp['retcode'] === '1')
+            {
+                $status = $resp['game_state'];
+                if ($status === '1') {
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === '9') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === '0') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['err_msg']];
+                }
+                return [true, $order_state];
             }
+            elseif ($resp['retcode'] === '1010' && (time() - $refill_info['commit_time'] > 300))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['err_msg']];
 
-            return [true, $order_state];
+            }
         }
     }
 
     public function balance()
     {
         $params['userid'] = config::USER_ID;
-        $params['userPws'] = md5(config::USER_PWS);
+        $params['userps'] = md5(config::USER_PWS);
         $params['version'] = '6.0';
 
         $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
@@ -122,11 +127,11 @@ class RefillPhone extends refill\IRefillPhone
         else
         {
             Log::record($resp, Log::DEBUG);
-            $resp = refill\util::xmlToArray($resp);
+            $resp = $this->xmlToArray($resp, 'GB2312');
 
             if (empty($resp)) {
                 return [false, '网络错误'];
-            } elseif ($resp['retcode'] === 1) {
+            } elseif ($resp['retcode'] === '1') {
                 return [true, $resp['totalBalance']];
             } else {
                 return [false, $resp['err_msg']];
@@ -141,4 +146,12 @@ class RefillPhone extends refill\IRefillPhone
         $content .= $key;
         return strtoupper(md5($content));
     }
+
+    public function xmlToArray($xml, $encode = 'GBK')
+    {
+        $replace_str = str_replace(' ','','encoding="'.$encode.'"');
+        $xml = mb_convert_encoding($xml,"utf-8","{$encode}");
+        $xml = str_replace($replace_str, "encoding='utf-8'", $xml);
+        return refill\util::xmlToArray($xml);
+    }
 }

+ 7 - 21
helper/refill/api/xyz/oufei/config.php

@@ -7,13 +7,14 @@ use mtopcard;
 class config
 {
     const ORDER_URL = 'http://apitest.ofpay.com/newOnlineOrder.do';
-    const QUERY_URL= 'http://apitest.ofpay.com/api/query.do';
+    const QUERY_URL= 'http://apitest.ofpay.com/queryOrderInfo.do';
     const BALANCE_URL = 'http://apitest.ofpay.com/newqueryuserinfo.do';
 
     const USER_ID = 'A08566';
     const USER_PWS = 'of111111';
     const KEY = 'OFCARD';
-    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_oufei.php";
+//    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_oufei.php";
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
 
     const operator = [
         mtopcard\ChinaMobileCard  => 1,
@@ -23,30 +24,15 @@ class config
     const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
 
     const ERR_NOS = [
-        1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 319, 321, 331, 9998, 4001
+        '1001', '1002', '1003', '1004', '1005', '1006', '1007', '1008', '319', '321', '331', '9998', '4001'
     ];
 
     const Product = [
-        mtopcard\ChinaMobileCard => [
-            10  => 1000010,
-            20  => 1000020,
-            50  => 1000050,
-            100 => 1000100,
-            200 => 1000200,
+        mtopcard\PetroChinaCard => [
+            200 => 64157003,
         ],
-        mtopcard\ChinaUnicomCard => [
-            30  => 2000030,
-            50  => 2000050,
-            100 => 2000100,
+        mtopcard\SinopecCard => [
             200 => 2000200,
-            300 => 2000300,
-            500 => 2000500,
-        ],
-        mtopcard\ChinaTelecomCard => [
-            30  => 3000030,
-            50  => 3000050,
-            100 => 3000100,
-            200 => 3000200,
         ],
     ];
 }

+ 14 - 0
test/TestRefill.php

@@ -3320,6 +3320,20 @@ class TestRefill extends TestCase
 //        $resp = $provider->notify($params);
     }
 
+    public function testOufei()
+    {
+//        $provider = $this->getProvider('oufei', 'RefillOil');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(9030230005180327, 1, 200, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '18141682668825332400']);
+
+        $body = '{"err_msg":"","ordersuccesstime":"20230428161615","sporder_id":"18141682668825332400","ret_code":"1"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('oufei', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);