ayHaru пре 4 година
родитељ
комит
787d4b8610

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

@@ -593,6 +593,19 @@ $suyuan_phone = ['name' => 'suyuan', 'store_id' => 39, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$xunao_phone = ['name' => 'xunao', 'store_id' => 44, 'qualitys' => '1',
+    'amount' => [
+        10 => [['goods_id' => 6504, 'price' => 9.45, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 6505, 'price' => 18.9, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 6506, 'price' => 28.35, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 6507, 'price' => 47.25, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 6508, 'price' => 94.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 6509, 'price' => 189, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 6510, 'price' => 283.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 6511, 'price' => 472.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -618,5 +631,6 @@ $phone_providers = [
     ['name' => 'afandfs', 'cfg' => $afandfs_phone],
     ['name' => 'yunlingfs', 'cfg' => $yunlingfs_phone],
     ['name' => 'tiancheng', 'cfg' => $tiancheng_phone],
+    ['name' => 'xunao', 'cfg' => $xunao_phone],
 ];
 $config['phone_providers'] = $phone_providers;

+ 59 - 0
helper/refill/api/xyz/xunao/RefillCallBack.php

@@ -0,0 +1,59 @@
+<?php
+
+
+namespace refill\xunao;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xunao/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($data)
+    {
+        $str = "";
+        ksort($data);
+        foreach($data as $k => $v){
+            if($v){
+                $str .= urldecode($v);
+            }
+        }
+        return md5($str.config::KEY);
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['orderNo'];
+        $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['ticketNo']) == 'null' ? '' : $params['ticketNo'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif (in_array($status, [0,1,3])) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 108 - 0
helper/refill/api/xyz/xunao/RefillPhone.php

@@ -0,0 +1,108 @@
+<?php
+
+namespace refill\xunao;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xunao/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['supplierId'] = config::USER_ID;
+        $params['orderNo'] = $order_sn;
+        $params['company'] = config::operator[$card_type];
+        $params['amount'] = $amount;
+        $params['phoneNo'] = $phone;
+        $params['notifyUrl'] = config::NOTIFY_URL;
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params)
+    {
+        $params = $this->req_params($card_no, $amount, $card_type, $params['order_sn']);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $params = json_encode($params);
+
+        $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders);
+
+        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']['orderId'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['supplierId'] = config::USER_ID;
+        $params['orderNo'] = $refill_info['order_sn'];
+        $params['phoneNo'] = $refill_info['card_no'];
+        $params['company'] = config::operator[$refill_info['card_type']];
+        $params['sign'] = $this->sign($params);
+        $params = json_encode($params);
+
+        $resp = http_post_data(config::QUERY_URL, $params , 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) {
+                $status = intval($resp['data']['status']);
+                if ($status === 2) {
+                    $updata['official_sn'] = $resp['data']['ticketNo'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($status, [0,1])) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            } else {
+                return [false, $resp['msg']];
+            }
+
+        }
+    }
+
+    private function sign($data)
+    {
+        $str = "";
+        ksort($data);
+        foreach($data as $k => $v){
+            if($v){
+                $str .= $v;
+            }
+        }
+        return md5($str.config::KEY);
+    }
+}

+ 8 - 0
helper/refill/api/xyz/xunao/api.txt

@@ -0,0 +1,8 @@
+后台:http://47.118.36.120/supplier/
+账号:yzdz01 
+密码:12345678 
+接口网关:http://47.118.36.120:9009/prod-produce/api/provide
+
+对接文档
+访问地址: https://www.showdoc.com.cn/1236371818470662?page_id=6222602518495888
+访问密码: 123456

+ 22 - 0
helper/refill/api/xyz/xunao/config.php

@@ -0,0 +1,22 @@
+<?php
+
+
+namespace refill\xunao;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://47.118.36.120:9009/prod-produce/api/provide';
+    const QUERY_URL = 'http://47.118.36.120:9009/prod-produce/api/query';
+
+    const USER_ID = '10';
+    const KEY = 'e4aa17f34d5ef57271b3fce13d938185';
+//    const NOTIFY_URL = BASE_SITE_URL . "/mobile/refill_xunao.php";
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+    const ExtHeaders = ['Content-Type: application/json'];
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'yd',
+        mtopcard\ChinaUnicomCard  => 'lt',
+        mtopcard\ChinaTelecomCard => 'dx'
+    ];
+}

+ 10 - 0
test/TestRefill.php

@@ -488,6 +488,16 @@ class TestRefill extends TestCase
         refill\RefillFactory::instance()->notify('zhongst',$input);
     }
 
+    public function testXunaoPhone()
+    {
+        $providers = new refill\xunao\RefillPhone([]);
+//        $resp = $providers->add(18074608795, 6, 10, ['order_sn' => $this->make_sn()]);
+//        $resp = $providers->query(['order_sn' => '40021619431386253803', 'card_no' => 18074608795, 'card_type' => 6]);
+        $data = '{"amount":"10.00","orderNo":"40021619431386253803","supplierId":"10","orderId":"S20210426180311761051424910","notifyTime":"1619431456411","sign":"c4eef22091831104be7ae95a0292c703","discountAmount":"0.50","phoneNo":"18074608795","queryUrl":"https:\/\/www.189.cn\/client\/wap\/wapproject\/wapclient\/feecharge\/feecharge_result.html?sessionid=f633d8a270aa4e5892d0f7ca6f09e95e","payType":"alipay","ticketNo":"1000000083421042618356072935","company":"dx","status":"2"}';
+        $input = json_decode($data, true);
+        refill\RefillFactory::instance()->notify('xunao',$input);
+    }
+
     public function testLuqianPhone()
     {
         $providers = new refill\luqian\RefillPhone([]);