Browse Source

zhenghe_sec update api

xiaoyu 1 year ago
parent
commit
b9af4880d0

+ 2 - 0
data/config/xyz/refill.ini.php

@@ -8842,6 +8842,7 @@ $zhenghe_sec_phone = ['name' => 'zhenghe_sec', 'store_id' => 318, 'qualitys' =>
 //        ],
 //        ],
         30 => [
         30 => [
             ['goods_id' => 8617, 'price' => 30.12, 'quality' => 2, 'card_type' => 'chinamobile'],
             ['goods_id' => 8617, 'price' => 30.12, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8617, 'price' => 30.12, 'quality' => 2, 'card_type' => 'chinaunicom'],
             ['goods_id' => 8617, 'price' => 30.12, 'quality' => 2, 'card_type' => 'chinatelecom'],
             ['goods_id' => 8617, 'price' => 30.12, 'quality' => 2, 'card_type' => 'chinatelecom'],
         ],
         ],
         50 => [
         50 => [
@@ -8866,6 +8867,7 @@ $zhenghe_sec_phone = ['name' => 'zhenghe_sec', 'store_id' => 318, 'qualitys' =>
         ],
         ],
         500 => [
         500 => [
             ['goods_id' => 8622, 'price' => 502, 'quality' => 2, 'card_type' => 'chinamobile'],
             ['goods_id' => 8622, 'price' => 502, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8622, 'price' => 502, 'quality' => 2, 'card_type' => 'chinaunicom'],
             ['goods_id' => 8622, 'price' => 502, 'quality' => 2, 'card_type' => 'chinatelecom'],
             ['goods_id' => 8622, 'price' => 502, 'quality' => 2, 'card_type' => 'chinatelecom'],
         ]
         ]
     ],
     ],

+ 36 - 0
helper/refill/api/xyz/zhenghe_sec/API信息.txt

@@ -0,0 +1,36 @@
+登录参数
+http://api.bjzhengheshun.com.cn:1008/hqorder/login
+账号:200003
+密码:123456(请及时更改初始密码)
+
+接口参数
+ID:200003
+秘钥:b2b737a0262548698229bc67674ecb48
+
+下单地址:http://api.bjzhengheshun.com.cn:1008/hqorder/api/submit
+查询地址:http://api.bjzhengheshun.com.cn:1008/hqorder/api/query
+查询余额地址:http://api.bjzhengheshun.com.cn:1008/hqorder/api/balance
+
+请登录后台查看  产品  产品折扣  产品编码
+
+全国移动30元	1000030
+全国移动50元	1000050
+全国移动100元	1000100
+全国移动200元	1000200
+全国移动300元	1000300
+全国移动500元	1000500
+
+
+全国联通30元	2000030
+全国联通50元	2000050
+全国联通100元	2000100
+全国联通200元	2000200
+全国联通300元	2000300
+全国联通500元	2000500
+
+全国电信30元	3000030
+全国电信50元	3000050
+全国电信100元	3000100
+全国电信200元	3000200
+全国电信300元	3000300
+全国电信500元	3000500

+ 14 - 16
helper/refill/api/xyz/zhenghe_sec/RefillCallBack.php

@@ -9,7 +9,7 @@ class RefillCallBack implements refill\IRefillCallBack
     public function verify($params): bool
     public function verify($params): bool
     {
     {
         $sign = $this->sign($params);
         $sign = $this->sign($params);
-        if ($params['szVerifyString'] == $sign) {
+        if ($params['sign'] == $sign) {
             return true;
             return true;
         } else {
         } else {
             return false;
             return false;
@@ -18,33 +18,31 @@ class RefillCallBack implements refill\IRefillCallBack
 
 
     private function sign($params)
     private function sign($params)
     {
     {
-        $userid = config::USER_ID;
+        $mchid = config::MCHID;
         $key = config::KEY;
         $key = config::KEY;
-        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nDemo={$params['nDemo']}&fSalePrice={$params['fSalePrice']}";
-        $content .= "&nFlag={$params['nFlag']}&szKey={$key}";
+        $content  = "mchid={$mchid}&orderid={$params['orderid']}&oid={$params['oid']}&number={$params['number']}&status={$params['status']}&key={$key}";
         return md5($content);
         return md5($content);
     }
     }
 
 
     public function notify($params)
     public function notify($params)
     {
     {
-        $status = intval($params['nFlag']);
-        $order_sn = $params['szOrderId'];
+        $order_sn = $params['orderid'];
         $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
         $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
         if (empty($order_info)) {
         if (empty($order_info)) {
-            return [false, false, false,false];
+            return [false, false, false, false, ''];
         }
         }
-        $order_id = $order_info['order_id'];
 
 
+        $order_id = $order_info['order_id'];
+        $status = intval($params['status']);
         if ($status === 2) {
         if ($status === 2) {
-            $data['official_sn'] = strtolower($params['szRtnMsg']) == 'null' ? '' : $params['szRtnMsg'];
+            $official_sn = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            $data['official_sn'] = $official_sn;
             Model('refill_order')->edit($order_id, $data);
             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, $official_sn];
+        } elseif ($status === 3) {
+            return [$order_id, false, true, true, ''];
+        } else {
+            return [$order_id, false, false, false, ''];
         }
         }
     }
     }
 }
 }

+ 64 - 60
helper/refill/api/xyz/zhenghe_sec/RefillPhone.php

@@ -16,15 +16,12 @@ class RefillPhone extends refill\IRefillPhone
 
 
     private function req_params(int $phone, int $amount, int $card_type, string $order_sn)
     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['mchid'] = config::MCHID;
+        $params['orderid'] = $order_sn;
+        $params['number'] = $phone;
+        $params['productid'] = config::product_id[$card_type][$amount];
+        $params['timestamp'] = $this->getMillisecond();
+        $params['backurl'] = config::NOTIFY_URL;
         return $params;
         return $params;
     }
     }
 
 
@@ -34,108 +31,115 @@ class RefillPhone extends refill\IRefillPhone
         $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
         $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
 
 
         $sign = $this->sign($params);
         $sign = $this->sign($params);
-        $params['szVerifyString'] = $sign;
+        $params['sign'] = $sign;
 
 
-        $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders, $net_errno);
 
 
         if (empty($resp)) {
         if (empty($resp)) {
-            return [false, '网络错误', true];
+            return [false, '系统错误', true];
         }
         }
         else
         else
         {
         {
             Log::record($resp, Log::DEBUG);
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
             $resp = json_decode($resp, true);
-
-            $nRtn = $resp['nRtn'];
             if (empty($resp)) {
             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];
+                return [false, '系统错误', true];
+            } elseif ($resp['status'] === 0) {
+                return [true, $resp['oid'], false];
+            } elseif ($resp['status'] === -1) {
+                return [false, $resp['msg'], false];
             } else {
             } 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)
     public function query($refill_info)
     {
     {
-        $params['szAgentId'] = config::USER_ID;
-        $params['szOrderId'] = $refill_info['order_sn'];
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $refill_info['order_sn'];
         $key = config::KEY;
         $key = config::KEY;
-        $content = "szAgentId={$params['szAgentId']}&szOrderId={$params['szOrderId']}&szKey={$key}";
-        $params['szVerifyString'] = md5($content);
+        $content = "mchid={$params['mchid']}&orderid={$params['orderid']}&key={$key}";
+        $params['sign'] = md5($content);
 
 
-        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+        $params = json_encode($params);
+        $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
 
 
         if (empty($resp)) {
         if (empty($resp)) {
-            return [false, '网络错误'];
+            return [false, '系统错误', ''];
         }
         }
         else
         else
         {
         {
             Log::record($resp, Log::DEBUG);
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
             $resp = json_decode($resp, true);
             if (empty($resp)) {
             if (empty($resp)) {
-                return [false, '网络错误'];
+                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']];
+            else {
+                $offical_sn = '';
+                $status = $resp['status'];
+                if ($status === 2) {
+                    $offical_sn = $resp['voucher'];
+                    $updata['official_sn'] = $offical_sn;
+                    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'] > 300)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $status, $offical_sn];
+                }
+                return [true, $order_state, $offical_sn];
             }
             }
-
-            return [true, $order_state];
         }
         }
     }
     }
 
 
     public function balance()
     public function balance()
     {
     {
-        $params['szAgentId'] = config::USER_ID;
+        $params['mchid'] = config::MCHID;
         $key = config::KEY;
         $key = config::KEY;
-        $content = "szAgentId={$params['szAgentId']}&szKey={$key}";
-        $params['szVerifyString'] = md5($content);
+        $content = "mchid={$params['mchid']}&key={$key}";
+        $params['sign'] = md5($content);
+        $params = json_encode($params);
 
 
-        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+        $resp = http_post_data(config::BALANCE_URL, $params , config::ExtHeaders);
 
 
         if (empty($resp)) {
         if (empty($resp)) {
-            return [false, '网络错误'];
+            return [false, '系统错误'];
         }
         }
         else
         else
         {
         {
             Log::record($resp, Log::DEBUG);
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
             $resp = json_decode($resp, true);
             if (empty($resp)) {
             if (empty($resp)) {
-                return [false, '网络错误'];
-            } elseif ($resp['nRtn'] === 0) {
-                return [true, $resp['fBalance']];
+                return [false, '系统错误'];
+            } elseif ($resp['status'] === 1) {
+                return [true, $resp['balance']];
             } else {
             } else {
-                return [false, $resp['szRtnCode']];
+                return [false, $resp['msg']];
             }
             }
         }
         }
     }
     }
 
 
     private function sign($params)
     private function sign($params)
     {
     {
-        $userid = config::USER_ID;
         $key = config::KEY;
         $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}";
+        $content  = "mchid={$params['mchid']}&orderid={$params['orderid']}&number={$params['number']}&productid={$params['productid']}";
+        $content .= "&timestamp={$params['timestamp']}&key={$key}";
         return md5($content);
         return md5($content);
     }
     }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function getMillisecond()
+    {
+        $cur = microtime (true);
+        return intval($cur * 1000);
+    }
 }
 }

+ 0 - 15
helper/refill/api/xyz/zhenghe_sec/api.txt

@@ -1,15 +0,0 @@
-后台参数
-客户地址:http://47.98.208.128:10186/plat/index
-gywzf
-123456
-
-对接参数
-id:200044
-密钥:572bb75e0512437b834c6c174e48064c
-
-正式环境:
-话费下单地址:http://47.98.208.128:10186/plat/api/old/submitorder
-查询地址:http://47.98.208.128:10186/plat/api/old/queryorder
-查询余额地址:http://47.98.208.128:10186/plat/api/old/queryBalance
-
-对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ

+ 31 - 13
helper/refill/api/xyz/zhenghe_sec/config.php

@@ -6,21 +6,39 @@ namespace refill\zhenghe_sec;
 use mtopcard;
 use mtopcard;
 class config
 class config
 {
 {
-    const ORDER_URL = 'http://47.98.208.128:10186/plat/api/old/submitorder';
-    const QUERY_URL= 'http://47.98.208.128:10186/plat/api/old/queryorder';
-    const BALANCE_URL = 'http://47.98.208.128:10186/plat/api/old/queryBalance';
+    const ORDER_URL = 'http://api.bjzhengheshun.com.cn:1008/hqorder/api/submit';
+    const QUERY_URL = 'http://api.bjzhengheshun.com.cn:1008/hqorder/api/query';
+    const BALANCE_URL = 'http://api.bjzhengheshun.com.cn:1008/hqorder/api/balance';
 
 
-    const USER_ID= '200044';
-    const KEY = '572bb75e0512437b834c6c174e48064c';
+    const MCHID = '200003';
+    const KEY = 'b2b737a0262548698229bc67674ecb48';
     const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_zhenghe_sec.php";
     const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_zhenghe_sec.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 ExtHeaders = ['Content-Type: application/json'];
 
 
-    const ERR_NOS = [
-        1000,1001,1003,1004,2001,2002,2003,2020,2021,1006,2030,3003
+    const product_id = [
+        mtopcard\ChinaMobileCard => [
+            30 => 1000030,
+            50 => 1000050,
+            100 => 1000100,
+            200 => 1000200,
+            300 => 1000300,
+            500 => 1000500
+        ],
+        mtopcard\ChinaUnicomCard => [
+            30 => 2000030,
+            50 => 2000050,
+            100 => 2000100,
+            200 => 2000200,
+            300 => 2000300,
+            500 => 2000500
+        ],
+        mtopcard\ChinaTelecomCard => [
+            30 => 3000030,
+            50 => 3000050,
+            100 => 3000100,
+            200 => 3000200,
+            300 => 3000300,
+            500 => 3000500
+        ],
     ];
     ];
 }
 }

BIN
helper/refill/api/xyz/zhenghe_sec/hq接口文档V1.0.docx


+ 3 - 2
mobile/callback/refill_zhenghe_sec.php

@@ -1,4 +1,5 @@
 <?php
 <?php
-
-refill\util::push_notify('zhenghe_sec',$_POST);
+$content = $_SERVER['post_content'] ?? [];
+$input = json_decode($content,true);
+refill\util::push_notify('zhenghe_sec',$input);
 echo ('ok');
 echo ('ok');

+ 15 - 0
test/TestRefill.php

@@ -3557,6 +3557,21 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
         $resp = $provider->notify($params);
     }
     }
 
 
+    public function testZhenghe_sec()
+    {
+//        $provider = $this->getProvider('zhenghe_sec');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 50, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
+//        $resp = $provider->query(['order_sn' => '16261690182981011717']);
+
+        $body = '{"number":"15811535608","mchid":"200003","orderid":"16261690182981011717","price":"50.25","voucher":"","sign":"556d199d03e7c46c40c90b9bd6fc7618","oid":2000000705,"status":"3"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('zhenghe_sec','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+
+    }
+
     public function testAmingjd()
     public function testAmingjd()
     {
     {
 //        $provider = new refill\amingjd\RefillPhone([]);
 //        $provider = new refill\amingjd\RefillPhone([]);