瀏覽代碼

xyz zhongst_mix

xiaoyu 3 年之前
父節點
當前提交
ce3322c08c

+ 25 - 8
data/config/xyz/refill.ini.php

@@ -2633,14 +2633,31 @@ $shimier_phone = ['name' => 'shimier', 'store_id' => 123,'qualitys' => '1',
 
 $zhongst_mix_phone = ['name' => 'zhongst_mix', 'store_id' => 124, 'qualitys' => '2',
     'amount' => [
-        10 => [['goods_id' => 7084, 'price' => 9.93, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-        20 => [['goods_id' => 7085, 'price' => 19.86, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-        30 => [['goods_id' => 7086, 'price' => 29.79, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-        50 => [['goods_id' => 7087, 'price' => 49.65, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-        100 => [['goods_id' => 7088, 'price' => 99.3, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-        200 => [['goods_id' => 7089, 'price' => 198.6, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-        300 => [['goods_id' => 7090, 'price' => 297.9, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-        500 => [['goods_id' => 7091, 'price' => 496.5, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+//        10 => [['goods_id' => 7084, 'price' => 9.96, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+//        20 => [['goods_id' => 7085, 'price' => 19.92, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [
+            ['goods_id' => 7086, 'price' => 29.88, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 7087, 'price' => 49.8, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7087, 'price' => 49.8, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 7088, 'price' => 99.6, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7088, 'price' => 99.6, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 7089, 'price' => 199.2, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7089, 'price' => 199.2, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 7090, 'price' => 298.8, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7090, 'price' => 298.8, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 7091, 'price' => 498, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7091, 'price' => 498, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ]
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 

+ 34 - 17
helper/refill/api/xyz/zhongst_mix/RefillCallBack.php

@@ -8,8 +8,10 @@ class RefillCallBack implements refill\IRefillCallBack
 {
     public function verify($params): bool
     {
-        $sign = $this->sign($params);
-        if ($params['szVerifyString'] == $sign) {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
             return true;
         } else {
             return false;
@@ -18,33 +20,48 @@ class RefillCallBack implements refill\IRefillCallBack
 
     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}";
+        $params['appSecret'] = config::APP_SECRET;
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content = rtrim($content, '&');
         return md5($content);
     }
 
+    private function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
     public function notify($params)
     {
-        $status = intval($params['nFlag']);
-        $order_sn = $params['szOrderId'];
+        $status = intval($params['orderStatus']);
+        $order_sn = $params['outOrderId'];
         $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
         if (empty($order_info)) {
             return [false, false, false,false];
         }
-        $order_id = $order_info['order_id'];
 
+        $order_id = $order_info['order_id'];
         if ($status === 2) {
-            $data['official_sn'] = strtolower($params['szRtnMsg']) == 'null' ? '' : $params['szRtnMsg'];
+            $data['official_sn'] = strtolower($params['ext1']) == 'null' ? '' : $params['ext1'];
             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];
+            return [$order_id, true, false, true];
+        } elseif ($status === 3) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
         }
     }
 }

+ 69 - 55
helper/refill/api/xyz/zhongst_mix/RefillPhone.php

@@ -16,15 +16,13 @@ class RefillPhone extends refill\IRefillPhone
 
     private function req_params(int $phone, int $amount, int $card_type, string $order_sn)
     {
-        $params['szAgentId'] = config::USER_ID;
-        $params['szOrderId'] = $order_sn;
-        $params['szPhoneNum'] = $phone;
-        $params['nMoney'] = $amount;
-        $params['nSortType'] = config::operator[$card_type];
-        $params['nProductClass'] = 1;
-        $params['nProductType'] = 1;
-        $params['szTimeStamp'] = date("Y-m-d H:i:s");
-        $params['szNotifyUrl'] = config::NOTIFY_URL;
+        $params['appId'] = config::APP_ID;
+        $params['outOrderId'] = $order_sn;
+        $params['uuid'] = $phone;
+        $params['itemId'] = config::PRODUCT[$card_type][$amount];
+        $params['itemFace'] = $amount;
+        $params['callbackUrl'] = config::NOTIFY_URL;
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
         return $params;
     }
 
@@ -32,9 +30,11 @@ class RefillPhone extends refill\IRefillPhone
     {
         $order_sn = $params['order_sn'];
         $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
-
+        if(empty($params['itemId'])) {
+            return [false, '商品编号错误', false];
+        }
         $sign = $this->sign($params);
-        $params['szVerifyString'] = $sign;
+        $params['sign'] = $sign;
 
         $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
 
@@ -45,32 +45,28 @@ class RefillPhone extends refill\IRefillPhone
         {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
-
-            $nRtn = $resp['nRtn'];
             if (empty($resp)) {
                 return [false, '网络错误', true];
-            } elseif ($nRtn === 0) {
-                return [true, '', false];
-            } elseif (in_array($nRtn, config::ERR_NOS, true)) {
-                return [false, $resp['szRtnCode'], false];
-            } elseif (in_array($nRtn, [2050, 999], true)) {
-                $net_errno = "HTTP-{$nRtn}";
-                return [false, $resp['szRtnCode'], true];
+            } elseif ($resp['code'] === '00') {
+                return [true, $resp['orderId'], false];
+            } elseif (in_array($resp['code'], config::ERRCODES, true)) {
+                return [false, $resp['msg'], false];
+            } elseif (in_array($resp['code'], ['-22', '-23', '-99'], true)) {
+                $net_errno = "HTTP-{$resp['code']}";
+                return [false, $resp['msg'], true];
             } else {
-                $err = 998;
-                $net_errno = "HTTP-{$err}";
-                return [false, $resp['szRtnCode'], true];
+                $net_errno = "HTTP-998";
+                return [false, $resp['msg'], true];
             }
         }
     }
 
     public function query($refill_info)
     {
-        $params['szAgentId'] = config::USER_ID;
-        $params['szOrderId'] = $refill_info['order_sn'];
-        $key = config::KEY;
-        $content = "szAgentId={$params['szAgentId']}&szOrderId={$params['szOrderId']}&szKey={$key}";
-        $params['szVerifyString'] = md5($content);
+        $params['appId'] = config::APP_ID;
+        $params['outOrderId'] = $refill_info['order_sn'];
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
+        $params['sign'] = $this->sign($params);
 
         $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
 
@@ -84,32 +80,36 @@ class RefillPhone extends refill\IRefillPhone
             if (empty($resp)) {
                 return [false, '网络错误'];
             }
-
-            $status = $resp['nRtn'];
-            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['code'] === '00')
+            {
+                $status = $resp['orderStatus'];
+                if ($status === '2') {
+                    $updata['official_sn'] = $resp['ext1'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === '3') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === '1') {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($status === '4' && (time() - $refill_info['commit_time'] >= 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
             }
-
-            return [true, $order_state];
         }
     }
 
     public function balance()
     {
-        $params['szAgentId'] = config::USER_ID;
-        $key = config::KEY;
-        $content = "szAgentId={$params['szAgentId']}&szKey={$key}";
-        $params['szVerifyString'] = md5($content);
+        $params['appId'] = config::APP_ID;
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
+        $params['sign'] = $this->sign($params);
 
         $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
 
@@ -122,20 +122,34 @@ class RefillPhone extends refill\IRefillPhone
             $resp = json_decode($resp, true);
             if (empty($resp)) {
                 return [false, '网络错误'];
-            } elseif ($resp['nRtn'] === 0) {
-                return [true, $resp['fBalance']];
+            } elseif ($resp['code'] === '00') {
+                return [true, $resp['balance']];
             } else {
-                return [false, $resp['szRtnCode']];
+                return [false, $resp['msg']];
             }
         }
     }
 
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function get_millisecond()
+    {
+        list($usec, $sec) = explode(" ", microtime());
+        return round($usec*1000);
+    }
+
     private function sign($params)
     {
-        $userid = config::USER_ID;
-        $key = config::KEY;
-        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nMoney={$params['nMoney']}&nSortType={$params['nSortType']}";
-        $content .= "&nProductClass={$params['nProductClass']}&nProductType={$params['nProductType']}&szTimeStamp={$params['szTimeStamp']}&szKey={$key}";
+        $params['appSecret'] = config::APP_SECRET;
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content = rtrim($content, '&');
         return md5($content);
     }
 }

+ 25 - 9
helper/refill/api/xyz/zhongst_mix/api.txt

@@ -1,11 +1,27 @@
-下单地址:http://39.102.121.210:10186/plat/api/old/submitorder
+后台地址:http://112.124.58.225:8888
+帐号:guoyanfanglve2
+密码:893393
+二级密码:mPoV9056
+appId:aKz6PN5XIw
+appSecret:iVVbvDkqlVMhSjev
+后台-商品列表,可查看已配置商品信息
+后台-安全中心,可配置IP白名单
+接口文档:https://www.showdoc.com.cn/1686453783298366/7925312871840290
+话费直充接口:http://112.124.58.225:8911/api/hf/order/submit
+通用直充接口:http://112.124.58.225:8911/api/order/submit
+卡密提取接口:http://112.124.58.225:8911/api/card/get
+查询接口接口:http://112.124.58.225:8911/api/order/query
+余额查询接口:http://112.124.58.225:8911/api/account/balance
 
-查询地址:http://39.102.121.210:10186/plat/api/old/queryorder
+100214 联通混充50
+100215 联通混充100
+100216 联通混充200
+100217 联通混充300
+100218 联通混充500
 
-查询余额地址:http://39.102.121.210:10186/plat/api/old/queryBalance
-后台地址:http://39.102.121.210:10186/plat/index
-账号:changyou
-密码:123456
-ID:200053
-秘钥:3a7d472a266b47a7a929469e46749aa7
-接口文档:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+100219 电信混充30
+100220 电信混充50
+100221 电信混充100
+100222 电信混充200
+100223 电信混充300
+100224 电信混充500

+ 26 - 14
helper/refill/api/xyz/zhongst_mix/config.php

@@ -6,22 +6,34 @@ namespace refill\zhongst_mix;
 use mtopcard;
 class config
 {
-    //995
-    const ORDER_URL = 'http://39.102.121.210:10186/plat/api/old/submitorder';
-    const QUERY_URL= 'http://39.102.121.210:10186/plat/api/old/queryorder';
-    const BALANCE_URL= 'http://39.102.121.210:10186/plat/api/old/queryBalance';
+    const ORDER_URL = 'http://112.124.58.225:8911/api/hf/order/submit';
+    const QUERY_URL = 'http://112.124.58.225:8911/api/order/query';
+    const BALANCE_URL = 'http://112.124.58.225:8911/api/account/balance';
 
-    const USER_ID= '200053';
-    const KEY = '3a7d472a266b47a7a929469e46749aa7';
+    const APP_ID = 'aKz6PN5XIw';
+    const APP_SECRET = 'iVVbvDkqlVMhSjev';
     const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_zhongst_mix.php";
-    const operator = [
-        mtopcard\ChinaMobileCard  => 1,
-        mtopcard\ChinaUnicomCard  => 2,
-        mtopcard\ChinaTelecomCard => 3
-    ];
-    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
 
-    const ERR_NOS = [
-        1000,1001,1003,1004,2001,2002,2003,2020,2021,1006,2030,3003
+    const PRODUCT = [
+        mtopcard\ChinaMobileCard => [
+
+        ],
+        mtopcard\ChinaUnicomCard => [
+            50  => 100214,
+            100 => 100215,
+            200 => 100216,
+            300 => 100217,
+            500 => 100218
+        ],
+        mtopcard\ChinaTelecomCard => [
+            30   => 100219,
+            50   => 100220,
+            100  => 100221,
+            200  => 100222,
+            300  => 100223,
+            500  => 100224
+        ],
     ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+    const ERRCODES = ['-10', '-12', '-13', '-14', '-15', '-16', '-18', '-21'];
 }

+ 3 - 3
test/TestRefill.php

@@ -997,10 +997,10 @@ class TestRefill extends TestCase
     {
 //        $provider = $this->getProvider('zhongst_mix');
 //        $resp = $provider->balance();
-//        $resp = $provider->add(18500608333, 5, 30, ['order_sn' => $this->make_sn()]);
-//        $resp = $provider->query(['order_sn' => '46291631503985151158']);
+//        $resp = $provider->add(18500608333, 5, 50, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '81331649907306739763']);
 
-        $body = '{"szOrderId":"46291631503985151158","fSalePrice":"29.85","szAgentId":"200053","nFlag":"2","szVerifyString":"be07db2c82b63bc2610eee3eac23245b","szPhoneNum":"18500608333","szRtnMsg":"","nDemo":"30"}';
+        $body = '{"orderId":"220414113514628825","appId":"aKz6PN5XIw","outOrderId":"81331649907306739763","sign":"140099d15593e363e6b2682a4c2f24c2","orderStatus":"2","completeTime":"20220414120642","orderDesc":"\u8ba2\u5355\u6210\u529f","ext1":"110103308032204141204470484590"}';
         $params = json_decode($body, true);
         $provider = $this->getProvider('zhongst_mix', 'RefillCallBack');
         $ret = $provider->verify($params);