xiaoyu 3 lat temu
rodzic
commit
f6699279a7

+ 14 - 1
data/config/win/refill.ini.php

@@ -1614,6 +1614,18 @@ $yuecheng_phone = ['name' => 'yuecheng', 'store_id' => 93, 'qualitys' => '2',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$cangbukami_phone = ['name' => 'cangbukami', 'store_id' => 83, 'qualitys' => '3',
+    'amount' => [
+        20 => [['goods_id' => 6770, 'price' => 19.08, 'quality' => 3, 'card_type' => 'chinaunicom']],
+        30 => [['goods_id' => 6771, 'price' => 28.62, 'quality' => 3, 'card_type' => 'chinaunicom']],
+        50 => [['goods_id' => 6772, 'price' => 47.7, 'quality' => 3, 'card_type' => 'chinaunicom']],
+        100 => [['goods_id' => 6773, 'price' => 95.4, 'quality' => 3, 'card_type' => 'chinaunicom']],
+        200 => [['goods_id' => 6774, 'price' => 190.8, 'quality' => 3, 'card_type' => 'chinaunicom']],
+        300 => [['goods_id' => 6775, 'price' => 286.2, 'quality' => 3, 'card_type' => 'chinaunicom']],
+        500 => [['goods_id' => 6776, 'price' => 477, 'quality' => 3, 'card_type' => 'chinaunicom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -1678,7 +1690,8 @@ $phone_providers = [
     ['name' => 'hongxudayz996', 'cfg' => $hongxudayz996_phone],
     ['name' => 'hongxudagy996', 'cfg' => $hongxudagy996_phone],
     ['name' => 'bingdht', 'cfg' => $bingdht_phone],
-    ['name' => 'yuecheng', 'cfg' => $yuecheng_phone]
+    ['name' => 'yuecheng', 'cfg' => $yuecheng_phone],
+    ['name' => 'cangbukami', 'cfg' => $cangbukami_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

BIN
helper/refill/api/xyz/cangbukami/APIdoc直冲.docx


+ 71 - 0
helper/refill/api/xyz/cangbukami/RefillCallBack.php

@@ -0,0 +1,71 @@
+<?php
+namespace refill\cangbukami;
+
+require_once(BASE_HELPER_RAPI_PATH . '/cangbukami/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];
+        }
+    }
+}

+ 117 - 0
helper/refill/api/xyz/cangbukami/RefillPhone.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace refill\cangbukami;
+
+require_once(BASE_HELPER_RAPI_PATH . '/cangbukami/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, string $order_sn)
+    {
+        $params['customerId'] = config::MCH_ID;
+        $params['timestamp'] = time();
+        $params['orderno'] = $order_sn;
+        $params['itemId'] = config::operator[$amount];
+        $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, $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 == 'success') {
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status == 'failed') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status == 'wait') {
+                    $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']];
+            }
+        }
+    }
+
+    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);
+    }
+}

+ 6 - 0
helper/refill/api/xyz/cangbukami/account.txt

@@ -0,0 +1,6 @@
+地址https://huadan.irecycle.top/   
+账户18500608333  
+密码123456
+
+mchid 112
+key zs53xG61NinhlrXskhR0xnAaOyM7yG

+ 24 - 0
helper/refill/api/xyz/cangbukami/config.php

@@ -0,0 +1,24 @@
+<?php
+
+
+namespace refill\cangbukami;
+
+use mtopcard;
+class config
+{
+    //yd 950 dl949
+    const ORDER_URL = 'https://ori.irecycle.top/queryBuy';
+    const QUERY_URL= 'https://api.irecycle.top/queryBizOrder';
+
+    const MCH_ID= '112';
+    const KEY = 'zs53xG61NinhlrXskhR0xnAaOyM7yG';
+//    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_cangbukami.php";
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+    const operator = [
+        20  => 'xydclt20',
+        30  => 'xydclt30',
+        50  => 'xydclt50',
+        100 => 'xydclt100'
+    ];
+    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded' , 'Accept: application/json;charset=UTF-8'];
+}

+ 7 - 0
test/TestRefill.php

@@ -494,6 +494,13 @@ class TestRefill extends TestCase
         refill\RefillFactory::instance()->notify('cangbu',$params);
     }
 
+    public function testCangbukami()
+    {
+        $providers = new refill\cangbukami\RefillPhone([]);
+        $resp = $providers->add(18500608333, 5, 20, ['order_sn' => $this->make_sn()]);
+//        $resp = $providers->query(['order_sn' => '35041626071052333060']);
+    }
+
     public function testTongykamiPhone()
     {
         $providers = new refill\tongykami\RefillPhone([]);