xiaoyu 3 years ago
parent
commit
49e8806041

+ 7 - 10
helper/refill/api/xyz/dingxin/RefillCallBack.php

@@ -2,7 +2,6 @@
 namespace refill\dingxin;
 
 require_once(BASE_HELPER_RAPI_PATH . '/dingxin/config.php');
-
 use refill;
 
 class RefillCallBack implements refill\IRefillCallBack
@@ -10,7 +9,7 @@ class RefillCallBack implements refill\IRefillCallBack
     public function verify($params): bool
     {
         $sign = $this->sign($params);
-        if ($params['sign'] == $sign) {
+        if ($params['userkey'] == $sign) {
             return true;
         } else {
             return false;
@@ -21,26 +20,24 @@ class RefillCallBack implements refill\IRefillCallBack
     {
         $userid = config::USER_ID;
         $key = config::KEY;
-        $content = "{$params['bizId']}{$params['downstreamSerialno']}{$params['ejId']}{$params['status']}{$userid}{$key}";
-        return md5($content);
+        $content = "userid{$userid}pwd{$key}orderid{$params['orderid']}state{$params['state']}account{$params['account']}{$key}";
+        return strtoupper(md5($content));
     }
 
     public function notify($params)
     {
-        $status = intval($params['status']);
-        $order_sn = $params['downstreamSerialno'];
+        $status = intval($params['state']);
+        $order_sn = $params['orderid'];
         $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'];
 
-        if ($status === 2) {
-            $data['official_sn'] = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
-            Model('refill_order')->edit($order_id, $data);
+        if ($status === 1) {
             return [$order_id, true, false,true];
         }
-        elseif ($status === 3) {
+        elseif ($status === 2) {
             return [$order_id, false, true,true];
         }
         else {

+ 35 - 47
helper/refill/api/xyz/dingxin/RefillPhone.php

@@ -2,7 +2,6 @@
 declare(strict_types=0);
 
 namespace refill\dingxin;
-
 require_once(BASE_HELPER_RAPI_PATH . '/dingxin/config.php');
 
 use refill;
@@ -17,13 +16,13 @@ class RefillPhone extends refill\IRefillPhone
 
     private function req_params(int $phone, int $amount, int $card_type, string $order_sn)
     {
-        $params['userId'] = config::USER_ID;
-        $params['itemId'] = config::Products[$card_type][$amount];
-        $params['checkItemFacePrice'] = $amount * 1000;
-        $params['amt'] = 1;
-        $params['uid'] = $phone;
-        $params['serialno'] = $order_sn;
-        $params['dtCreate'] = date("YmdHis");
+        $params['userid'] = config::USER_ID;
+        $params['pwd'] = config::PWD;
+        $params['orderid'] = $order_sn;
+        $params['face'] = $amount;
+        $params['account'] = $phone;
+        $params['amount'] = 1;
+        $params['operator'] = config::operator[$card_type];
 
         return $params;
     }
@@ -33,7 +32,7 @@ class RefillPhone extends refill\IRefillPhone
         $order_sn = $params['order_sn'];
         $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
         $sign = $this->sign($params);
-        $params['sign'] = $sign;
+        $params['userkey'] = $sign;
 
         $resp = http_request(config::ORDER_URL, $params, 'GET', false, [], $net_errno);
 
@@ -47,29 +46,26 @@ class RefillPhone extends refill\IRefillPhone
             if (empty($resp)) {
                 return [false, '网络错误', true];
             }
-            $status = $resp['status'];
-            $code   = $resp['code'];
 
-            if (!in_array($status, ['success', 'failed'])) {
-                return [false, '网络错误', true];
-            } elseif ($code === '00') {
-                return [true, $resp['bizOrderId'], false];
-            } elseif (in_array($code, [23, 31])) {
-                $net_errno = "HTTP-{$code}";
-                return [false, $code, false];
+            if ($resp['error'] === '0' && in_array($resp['state'], [0, 8])) {
+                return [true, $resp['Porderid'], false];
+            } elseif ($resp['error'] === '9999') {
+                $net_errno = "HTTP-{$resp['error']}";
+                return [false, $resp['error'], false];
             } else {
-                return [false, $code, false];
+                return [false, $resp['error'], false];
             }
         }
     }
 
     public function query($refill_info)
     {
-        $params['userId'] = config::USER_ID;
-        $params['serialno'] = $refill_info['order_sn'];
+        $params['userid'] = config::USER_ID;
+        $params['pwd'] = config::PWD;
+        $params['orderid'] = $refill_info['order_sn'];
         $key = config::KEY;
-        $content = "{$params['userId']}{$params['serialno']}{$key}";
-        $params['sign'] = md5($content);
+        $content = "userid{$params['userid']}pwd{$params['pwd']}orderid{$params['orderid']}{$key}";
+        $params['userkey'] = strtoupper(md5($content));
 
         $resp = http_request(config::QUERY_URL, $params);
 
@@ -86,32 +82,25 @@ class RefillPhone extends refill\IRefillPhone
             }
             else
             {
-                $status = $resp['status'];
-                $code   = $resp['code'];
-
-                if (!in_array($status, ['success', 'failed'])) {
-                    return [false, $status];
-                }
-                elseif($code === '00')
+                if($resp['error'] === '0')
                 {
-                    $status = intval($resp['data']['status']);
-                    if ($status === 2) {
-                        Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $resp['data']['outOrderNo']]);
+                    $status = intval($resp['state']);
+                    if ($status === 1) {
                         $order_state = ORDER_STATE_SUCCESS;
-                    } elseif ($status === 3) {
+                    } elseif ($status === 2) {
                         $order_state = ORDER_STATE_CANCEL;
-                    } elseif (in_array($status, [0, 1, 4, 9])) {
+                    } elseif ($status === 0) {
                         $order_state = ORDER_STATE_SEND;
                     } else {
                         return [false, $status];
                     }
                     return [true, $order_state];
                 }
-                elseif ($code === '22' && (time() - $refill_info['commit_time'] >= 600)) {
+                elseif ($resp['error'] === '1007' && (time() - $refill_info['commit_time'] >= 120)) {
                     return [true, ORDER_STATE_NOEXIST];
                 }
                 else {
-                    return [false, $code];
+                    return [false, $resp['error']];
                 }
             }
         }
@@ -119,10 +108,11 @@ class RefillPhone extends refill\IRefillPhone
 
     public function balance()
     {
-        $params['userId'] = config::USER_ID;
+        $params['userid'] = config::USER_ID;
+        $params['pwd'] = config::PWD;
         $key = config::KEY;
-        $body = "{$params['userId']}{$key}";
-        $params['sign'] = md5($body);
+        $body = "userid{$params['userid']}pwd{$params['pwd']}{$key}";
+        $params['userkey'] = strtoupper(md5($body));
 
         $resp = http_request(config::BALANCE_URL, $params);
 
@@ -135,21 +125,19 @@ class RefillPhone extends refill\IRefillPhone
             $resp = $this->xmlToArray($resp);
             if (empty($resp)) {
                 return [false, '网络错误'];
-            } elseif ($resp['status'] === 'success' && $resp['code'] === '00') {
-                return [true, $resp['balance']/1000];
+            } elseif ($resp['error'] === '0') {
+                return [true, $resp['lastMoney']];
             } else {
-                return [false, $resp['code']];
+                return [false, $resp['error']];
             }
         }
     }
 
     private function sign($params)
     {
-        $userid = config::USER_ID;
         $key = config::KEY;
-        $content = "{$params['amt']}{$params['checkItemFacePrice']}{$params['dtCreate']}{$params['itemId']}{$params['itemPrice']}{$params['serialno']}";
-        $content .= "{$params['uid']}{$userid}{$key}";
-        return md5($content);
+        $content = "userid{$params['userid']}pwd{$params['pwd']}orderid{$params['orderid']}face{$params['orderid']}account{$params['account']}amount{$params['amount']}{$key}";
+        return strtoupper(md5($content));
     }
 
     public function xmlToArray($xml)

+ 2 - 1
helper/refill/api/xyz/dingxin/api18513846008.txt

@@ -5,4 +5,5 @@ pwd:ZyhaHyQspd68ndfbRfJH8errzaBmdMFm
 key:HPwK74Y4dhNRtktmQDZa7xj2twNTMkfx
 
 www.ejiaofei.cn
-18513846008
+18513846008
+yezi123456

+ 11 - 29
helper/refill/api/xyz/dingxin/config.php

@@ -7,36 +7,18 @@ use mtopcard;
 class config
 {
     //回调地址需配置
-    const ORDER_URL = 'http://47.114.209.57/unicomAync/buy.do';
-    const QUERY_URL= 'http://47.114.209.57/unicomAync/queryBizOrder.do';
-    const BALANCE_URL = 'http://47.114.209.57/unicomAync/queryBalance.do';
+    const ORDER_URL = 'http://api.ejiaofei.net:11140/chongzhi_jkorders.do';
+    const QUERY_URL= 'http://api.ejiaofei.net:11140/query_jkorders.do';
+    const BALANCE_URL = 'http://api.ejiaofei.net:11140/money_jkuser.do';
 
-    const USER_ID= '80800346';
-    const KEY = 'bb9c64bbd8937e03ca73f9d7b29a17af';
-    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_dashang.php";
+    const USER_ID= '18513846008';
+    const PWD = 'ZyhaHyQspd68ndfbRfJH8errzaBmdMFm';
+    const KEY = 'HPwK74Y4dhNRtktmQDZa7xj2twNTMkfx';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_dingxin.php";
 
-    const Products = [
-        mtopcard\ChinaUnicomCard =>
-            [
-                10  => 90330010,
-                20  => 90330020,
-                30  => 90330030,
-                50  => 90330050,
-                100 => 90330100,
-                200 => 90330200,
-                300 => 90330300,
-                500 => 90330500
-            ],
-        mtopcard\ChinaTelecomCard =>
-            [
-                10  => 90290010,
-                20  => 90290020,
-                30  => 90290030,
-                50  => 90290050,
-                100 => 90290100,
-                200 => 90290200,
-                300 => 90290300,
-                500 => 90290500
-            ]
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'mobile',
+        mtopcard\ChinaUnicomCard  => 'unicom',
+        mtopcard\ChinaTelecomCard => 'telecom'
     ];
 }

+ 6 - 0
test/TestRefill.php

@@ -1117,6 +1117,12 @@ class TestRefill extends TestCase
         $resp = $providers->notify($params);
     }
 
+    public function testDingxin()
+    {
+        $providers = $this->getProvider('dingxin');
+        $resp = $providers->balance();
+    }
+
     public function testAmingjd()
     {
 //        $providers = new refill\amingjd\RefillPhone([]);