xiaoyu 3 سال پیش
والد
کامیت
40e8e593dd

BIN
helper/refill/api/xyz/cangbuyd/APIdoc直充.docx


+ 69 - 0
helper/refill/api/xyz/cangbuyd/RefillCallBack.php

@@ -0,0 +1,69 @@
+<?php
+namespace refill\cangbuyd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/cangbuyd/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if(false === $this->check_empty($val)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+
+
+    protected 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['code']);
+        $order_sn = $params['tmporder'];
+        $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 === 1) {
+            $data['official_sn'] = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            $data['ch_trade_no'] = strtolower($params['orderno']) == 'null' ? '' : $params['orderno'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === -1) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 144 - 0
helper/refill/api/xyz/cangbuyd/RefillPhone.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace refill\cangbuyd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/cangbuyd/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount, int $card_type, string $order_sn)
+    {
+        $params['customerId'] = config::MCH_ID;
+        $params['timestamp'] = time();
+        $params['orderno'] = $order_sn;
+        $params['itemId'] = config::operator[$card_type];
+        $params['checkItemFacePrice'] = $amount;
+        $params['number'] = $phone;
+        $params['amt'] = 1;
+        $params['notify_url'] = config::NOTIFY_URL;
+        $params['overtime'] = 1;
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
+
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
+
+        if (empty($resp)) {
+            return [false, '网络错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($resp['code'] === 1) {
+                return [true, '', false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['customerId'] = config::MCH_ID;
+        $params['timestamp'] = time();
+        $params['orderno'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }
+
+            if($resp['code'] === 1)
+            {
+                $status = $resp['data']['status'];
+                if ($status === 2) {
+                    Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $resp['data']['officialOrderNo'], 'ch_trade_no' => $resp['data']['agentOrderNo']]);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($status, [0, 1], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            elseif($resp['code'] === -1 && $resp['msg'] == '没有该订单')
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['customerId'] = config::MCH_ID;
+        $params['timestamp'] = time();
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+        if(empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['code'] === 1) {
+                return [true, $resp['data']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if(false === $this->check_empty($val)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+}

+ 4 - 0
helper/refill/api/xyz/cangbuyd/account.txt

@@ -0,0 +1,4 @@
+账户15811535608
+密码123456
+安全码123456
+后台地址https://huadan.irecycle.top/

+ 23 - 0
helper/refill/api/xyz/cangbuyd/config.php

@@ -0,0 +1,23 @@
+<?php
+
+
+namespace refill\cangbuyd;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'https://api.irecycle.top/queryBuy';
+    const QUERY_URL= 'https://api.irecycle.top/queryBizOrder';
+    const BALANCE_URL= 'https://api.irecycle.top//queryBalance';
+
+    const MCH_ID= '220';
+    const KEY = '5lEtcVlnQJpEObGYPJF6qf0SqJObB0';
+//    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_cangbuyd.php";
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'MOBILE',
+        mtopcard\ChinaUnicomCard  => 'UNICOM',
+        mtopcard\ChinaTelecomCard => 'TELECOM'
+    ];
+    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded' , 'Accept: application/json;charset=UTF-8'];
+}

+ 8 - 0
test/TestRefill.php

@@ -1525,6 +1525,14 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testCangbuYd()
+    {
+        $provider = $this->getProvider('cangbuyd');
+//        $resp = $provider->balance();
+        $resp = $provider->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '79931638775980503797']);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);