Browse Source

xyz yuntian

xiaoyu 1 year ago
parent
commit
c8febe410e

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

@@ -9119,6 +9119,51 @@ $qiantu_phone = ['name' => 'qiantu', 'store_id' => 342, 'qualitys' => '2',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$yuntian_phone = ['name' => 'yuntian', 'store_id' => 345, 'qualitys' => '1',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 8752, 'price' => 9.5, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8752, 'price' => 10.01, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8752, 'price' => 9.6, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 8753, 'price' => 19, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8753, 'price' => 20.02, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8753, 'price' => 19.2, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+        30 => [
+//            ['goods_id' => 8754, 'price' => 28.95, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8754, 'price' => 28.2, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8754, 'price' => 29.1, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 8755, 'price' => 48.5, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8755, 'price' => 47.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8755, 'price' => 48.5, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 8756, 'price' => 97, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8756, 'price' => 95, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8756, 'price' => 97, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 8757, 'price' => 194, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8757, 'price' => 190, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8757, 'price' => 194, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+//        300 => [
+//            ['goods_id' => 8758, 'price' => 300.15, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8758, 'price' => 300.15, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8758, 'price' => 300.15, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+//        500 => [
+//            ['goods_id' => 8759, 'price' => 500.25, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 8759, 'price' => 500.25, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 8759, 'price' => 500.25, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -9401,6 +9446,8 @@ $phone_providers = [
     ['name' => 'meixu_sec', 'cfg' => $meixu_sec_phone],
     ['name' => 'tianchen_trd', 'cfg' => $tianchen_trd_phone],
     ['name' => 'qiantu', 'cfg' => $qiantu_phone],
+    ['name' => 'yuntian', 'cfg' => $yuntian_phone],
+
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 46 - 0
helper/refill/api/xyz/yuntian/RefillCallBack.php

@@ -0,0 +1,46 @@
+<?php
+namespace refill\yuntian;
+require_once(BASE_HELPER_RAPI_PATH . '/yuntian/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $signature = [config::KEY, $params['timestamp'], config::ACCOUNT];
+        sort($signature, SORT_STRING);
+        $signature = implode($signature);
+        return sha1($signature);
+    }
+
+    public function notify($params)
+    {
+        $status = $params['status'];
+        $order_sn = $params['consumerNo'];
+        $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
+
+        $order_id = $order_info['order_id'];
+        if ($status === '001') {
+            $data['official_sn'] = strtolower($params['voucherNo']) == 'null' ? '' : $params['voucherNo'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif (in_array($status,config::NotifyErrCodes, true)) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 155 - 0
helper/refill/api/xyz/yuntian/RefillPhone.php

@@ -0,0 +1,155 @@
+<?php
+
+namespace refill\yuntian;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yuntian/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 $card_type, string $order_sn)
+    {
+        $params['account'] = config::ACCOUNT;
+        $params['consumerNo'] = $order_sn;
+        $params['mobile'] = $phone;
+        $params['ispCode'] = config::operator[$card_type];
+        $params['cbkUrl'] = config::NOTIFY_URL;
+        $params['timestamp'] = $this->get_millisecond();
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $params['order_sn']);
+        $params['flowCode'] = config::ProductIDS[$card_type][$amount];
+        if (empty($params['flowCode'])) {
+            return [false, '产品编号错误', false];
+        }
+
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'GET', false, [], $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['status'] === '001') {
+                return [true, $resp['orderNo'], false];
+            } else {
+                return [false, $resp['status'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['account'] = config::ACCOUNT;
+        $params['consumerNo'] = $refill_info['order_sn'];
+        $params['timestamp'] = $this->get_millisecond();
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::QUERY_URL, $params);
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            }
+
+            $status = $resp['status'];
+            if ($status === '001')
+            {
+                $order_state = ORDER_STATE_SUCCESS;
+                $save['official_sn'] = strtolower($resp['voucherNo']) == 'null' ? '' : $resp['voucherNo'];
+                Model('refill_order')->edit($refill_info['order_id'], $save);
+            }
+            elseif (in_array($status,config::QueryErrCodes, true))
+            {
+                if ($status === '026')
+                {
+                    //订单不存在状态,三小时内查询可失败,超过则返回充值中.不可以在下单后的同时立马发起查询,否则返回该状态处理为充值中,至少隔30秒以上再发起查询
+                    $commit_secs = time() - $refill_info['commit_time'];
+                    if ($commit_secs > 0 && $commit_secs <= 180) {
+                        return [false, '时长不足'];
+                    } elseif ($commit_secs > 180 && $commit_secs <= 10800) {
+                        $order_state = ORDER_STATE_NOEXIST;
+                    } else {
+                        $order_state = ORDER_STATE_SEND;
+                    }
+                }
+                else {
+                    $order_state = ORDER_STATE_CANCEL;
+                }
+            }
+            elseif ($status === '002') {
+                $order_state = ORDER_STATE_SEND;
+            }
+            else {
+                return [false, $status];
+            }
+
+            return [true, $order_state];
+        }
+    }
+
+    public function balance()
+    {
+        $params['account'] = config::ACCOUNT;
+        $params['timestamp'] = $this->get_millisecond();
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::BALANCE_URL, $params);
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif ($resp['status'] === 'success') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['descriptor']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $signature = [config::KEY, $params['timestamp'], config::ACCOUNT];
+        sort($signature, SORT_STRING);
+        $signature = implode($signature);
+        return sha1($signature);
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function get_millisecond()
+    {
+        $cur = microtime (true);
+        return intval($cur * 1000);
+    }
+}

+ 48 - 0
helper/refill/api/xyz/yuntian/config.php

@@ -0,0 +1,48 @@
+<?php
+
+
+namespace refill\yuntian;
+use mtopcard;
+
+class config
+{
+    const ORDER_URL = 'http://47.108.209.201/flow-receiver/api/recharge/feecbk';
+    const QUERY_URL = 'http://47.108.209.201/flow-receiver/api/query/feecbk';
+    const BALANCE_URL = 'http://47.108.209.201/flow-receiver/api/balance/feecbk';
+    const NOTIFY_URL = BASE_SITE_URL . '/mobile/callback/refill_yuntian.php';
+
+    const ACCOUNT = 'ytyzqg';
+    const KEY = 'c87130d0ce7a4792ba91aab8b8f9ef7e';
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'CMCC',
+        mtopcard\ChinaUnicomCard  => 'CUCC',
+        mtopcard\ChinaTelecomCard => 'CTCC'
+    ];
+    const ProductIDS = [
+        mtopcard\ChinaMobileCard => [
+            50 => 'CMCCALLr50r',
+            100 => 'CMCCALLr100r',
+            200 => 'CMCCALLr200r',
+        ],
+        mtopcard\ChinaUnicomCard => [
+            30 => 'CUCCALLr30r',
+            50 => 'CUCCALLr50r',
+            100 => 'CUCCALLr100r',
+            200 => 'CUCCALLr200r',
+        ],
+        mtopcard\ChinaTelecomCard => [
+            30 => 'CTCCALLr30r',
+            50 => 'CTCCALLr50r',
+            100 => 'CTCCALLr100r',
+            200 => 'CTCCALLr200r',
+        ],
+    ];
+
+    const NotifyErrCodes = [
+        '003','004','005','006','007','008','015','016','017','018','019','020','021','022','023','025','027','028','098','099'
+    ];
+
+    const QueryErrCodes = [
+        '003','004','005','006','007','008','015','016','017','018','019','020','021','022','023','024','025','026','027','028','098','099'
+    ];
+}

+ 34 - 0
helper/refill/api/xyz/yuntian/椰子.txt

@@ -0,0 +1,34 @@
+
+账号:ytyzqg
+
+密钥:c87130d0ce7a4792ba91aab8b8f9ef7e
+
+
+下单地址
+http://47.108.209.201/flow-receiver/api/recharge/feecbk
+查询地址
+http://47.108.209.201/flow-receiver/api/query/feecbk
+余额查询地址
+http://47.108.209.201/flow-receiver/api/balance/feecbk
+
+
+请务必绑定我们回调IP:47.108.209.201
+
+
+全国移动:
+CMCCALLr50r
+CMCCALLr100r
+CMCCALLr200r
+
+全国联通:
+CUCCALLr30r
+CUCCALLr50r
+CUCCALLr100r
+CUCCALLr200r
+
+
+全国电信:
+CTCCALLr30r
+CTCCALLr50r
+CTCCALLr100r
+CTCCALLr200r

BIN
helper/refill/api/xyz/yuntian/话费API接口文档.docx


+ 4 - 0
mobile/callback/refill_yuntian.php

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

+ 15 - 0
test/TestRefill.php

@@ -3528,6 +3528,21 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testYuntian()
+    {
+//        $provider = $this->getProvider('yuntian');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 30, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
+//        $resp = $provider->query(['order_sn' => '89151688372671258257']);
+
+
+        $body = '{"status":"019","orderNo":"F2307031624355807256","consumerNo":"89151688372671258257","mobile":"15811535608","voucherNo":"null","account":"ytyzqg","timestamp":"1688372676004","sign":"b9b3e1643052fb4d2162d20311ec140f57790384"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('yuntian','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);