xiaoyu il y a 3 ans
Parent
commit
da2d2ba0b1

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

@@ -4627,6 +4627,51 @@ $ningying_phone = ['name' => 'ningying', 'store_id' => 190,'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$cangxin_yi_phone = ['name' => 'cangxin_yi', 'store_id' => 191,'qualitys' => '2',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 7617, 'price' => 9.95, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7617, 'price' => 9.95, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7617, 'price' => 9.95, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 7618, 'price' => 19.9, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7618, 'price' => 19.9, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7618, 'price' => 19.9, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+        30 => [
+            ['goods_id' => 7619, 'price' => 29.85, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7619, 'price' => 29.85, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7619, 'price' => 29.85, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 7620, 'price' => 49.75, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7620, 'price' => 49.75, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7620, 'price' => 49.75, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 7621, 'price' => 99.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7621, 'price' => 99.5, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7621, 'price' => 99.5, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 7622, 'price' => 199, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7622, 'price' => 199, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7622, 'price' => 199, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 7623, 'price' => 298.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7623, 'price' => 298.5, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7623, 'price' => 298.5, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 7624, 'price' => 497.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7624, 'price' => 497.5, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7624, 'price' => 497.5, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],

+ 66 - 0
helper/refill/api/xyz/cangxin_yi/RefillCallBack.php

@@ -0,0 +1,66 @@
+<?php
+namespace refill\cangxin_yi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/cangxin_yi/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['verifyString']);
+        $sign = $this->sign($input);
+        if ($params['verifyString'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content = $content . "key=" . config::Key;
+        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['status']);
+        $order_sn = $params['clientOrderNo'];
+        $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 === 4) {
+            $data['official_sn'] = strtolower($params['officialOrderNo']) == 'null' ? '' : $params['officialOrderNo'];
+            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];
+        }
+    }
+}

+ 134 - 0
helper/refill/api/xyz/cangxin_yi/RefillPhone.php

@@ -0,0 +1,134 @@
+<?php
+
+namespace refill\cangxin_yi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/cangxin_yi/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['clientId'] = config::clientId;
+        $params['clientOrderNo'] = $order_sn;
+        $params['account'] = $phone;
+        $params['skuCode'] = config::PRODUCT[$card_type][$amount];
+        $params['amount'] = $amount;
+        $params['callbackUrl'] = config::NOTIFY_URL;
+        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);
+        if(empty($params['skuCode'])) {
+            return [false, '商品编号错误', false];
+        }
+        $sign = $this->sign($params);
+        $params['verifyString'] = $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'] === 200) {
+                return [true, $resp['data']['sysOrderNo'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['clientId'] = config::clientId;
+        $params['clientOrderNo'] = $refill_info['order_sn'];
+        $params['verifyString'] = $this->sign($params);
+
+        $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, '网络错误'];
+            }
+            elseif ($resp['code'] === 200)
+            {
+                $data = $resp['data'];
+                $status = $data['status'];
+                if ($status === '4') {
+                    $updata['official_sn'] = $data['officialOrderNo'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === '3') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === '0' || $status === '2') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            }
+            elseif ($resp['code'] === -9 && (time() - $refill_info['commit_time'] >= 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['clientId'] = config::clientId;
+        $params['verifyString'] = $this->sign($params);
+
+        $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'] === 200) {
+                return [true, $resp['data']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $str = urldecode(http_build_query($params));
+        $str .= '&key=' . config::Key;
+        return md5($str);
+    }
+}

+ 43 - 0
helper/refill/api/xyz/cangxin_yi/config.php

@@ -0,0 +1,43 @@
+<?php
+
+
+namespace refill\cangxin_yi;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://47.98.184.74:9527/order/submit';
+    const QUERY_URL = 'http://47.98.184.74:9527/order/query';
+    const BALANCE_URL = 'http://47.98.184.74:9527/order/balance';
+
+    const clientId = '10043';
+    const Key = 'QEi05vA28aPVA5OIKE2srKaCWWtHMPQL';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_cangxin_yi.php";
+    const PRODUCT = [
+        mtopcard\ChinaMobileCard => [
+            30  => 1320030,
+            50  => 1320050,
+            100 => 1320100,
+            200 => 1320200,
+            300 => 1320300,
+            500 => 1320500,
+        ],
+        mtopcard\ChinaUnicomCard => [
+            30  => 3320030,
+            50  => 3320050,
+            100 => 3320100,
+            200 => 3320200,
+            300 => 3320300,
+            500 => 3320500,
+        ],
+        mtopcard\ChinaTelecomCard => [
+            30  => 2320030,
+            50  => 2320050,
+            100 => 2320100,
+            200 => 2320200,
+            300 => 2320300,
+            500 => 2320500,
+        ],
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+}

+ 24 - 0
helper/refill/api/xyz/cangxin_yi/开户信息.txt

@@ -0,0 +1,24 @@
+商户id 10043
+QEi05vA28aPVA5OIKE2srKaCWWtHMPQL
+对接文档https://www.showdoc.com.cn/1720387349860903/8044417869640483
+
+1320030  全国移动30元
+1320050  全国移动50元
+1320100  全国移动100元
+1320200  全国移动200元
+1320300  全国移动300元
+1320500  全国移动500元
+
+3320030  全国联通30元
+3320050  全国联通50元
+3320100  全国联通100元
+3320200  全国联通200元
+3320300  全国联通300元
+3320500  全国联通500元
+
+2320030  全国电信30元
+2320050  全国电信50元
+2320100  全国电信100元
+2320200  全国电信200元
+2320300  全国电信300元
+2320500  全国电信500元

+ 4 - 0
mobile/callback/refill_cangxin_yi.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('cangxin_yi',$_POST);
+echo ('OK');

+ 14 - 0
test/TestRefill.php

@@ -1820,6 +1820,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testCangxin_yi()
+    {
+//        $provider = $this->getProvider('cangxin_yi');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 50, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '98761645683605613490']);
+
+        $body = '{"sysOrderNo":"R1645683614014oToK4ua","officialOrderNo":"","clientId":"10043","verifyString":"4040530613390299cf5d432a59dad348","clientOrderNo":"98761645683605613490","status":"4"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('cangxin_yi','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);