xiaoyu 3 years ago
parent
commit
e006d448d5

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

@@ -4931,6 +4931,51 @@ $ningying_normal_phone = ['name' => 'ningying_normal', 'store_id' => 197,'qualit
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$yuanrun_phone = ['name' => 'yuanrun', 'store_id' => 198,'qualitys' => '2',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 7665, 'price' => 10.37, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7665, 'price' => 10.37, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7665, 'price' => 10.37, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 7666, 'price' => 20.74, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7666, 'price' => 20.74, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7666, 'price' => 20.74, 'quality' => 2, 'card_type' => 'chinatelecom']
+//        ],
+        30 => [
+//            ['goods_id' => 7667, 'price' => 31.11, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7667, 'price' => 31.11, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7667, 'price' => 31.11, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+//            ['goods_id' => 7668, 'price' => 51.85, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7668, 'price' => 51.85, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7668, 'price' => 51.85, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 7669, 'price' => 103.7, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7669, 'price' => 103.7, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7669, 'price' => 103.7, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 7670, 'price' => 207.4, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7670, 'price' => 207.4, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7670, 'price' => 207.4, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        300 => [
+            ['goods_id' => 7671, 'price' => 311.1, 'quality' => 2, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7671, 'price' => 311.1, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7671, 'price' => 311.1, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ],
+        500 => [
+            ['goods_id' => 7672, 'price' => 518.5, 'quality' => 2, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7672, 'price' => 518.5, 'quality' => 2, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7672, 'price' => 518.5, 'quality' => 2, 'card_type' => 'chinatelecom']
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -5089,6 +5134,7 @@ $phone_providers = [
     ['name' => 'lexiang', 'cfg' => $lexiang_phone],
     ['name' => 'kuaikuai', 'cfg' => $kuaikuai_phone],
     ['name' => 'jianjiao', 'cfg' => $jianjiao_phone],
+    ['name' => 'yuanrun', 'cfg' => $yuanrun_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 38 - 0
helper/refill/api/xyz/yuanrun/API信息.txt

@@ -0,0 +1,38 @@
+下单接口: http://121.89.202.158/api/do
+主动查询: http://121.89.202.158/api/queryorder
+余额查询: http://121.89.202.158/api/querybalance
+CPID: 49449
+CPKEY:1a3239f76e20480fa
+
+后台查单:http://121.89.202.158/
+帐号: qudaiwa
+密码: 123456
+接口文档: http://api.whale123.com/doc/jsoft.pdf
+
+
+20001	全国移动10元
+20002	全国移动20元
+20003	全国移动30元
+20004	全国移动50元
+20005	全国移动100元
+20006	全国移动200元
+20007	全国移动300元
+20008	全国移动500元
+
+20009	全国联通10元
+20010	全国联通20元
+20011	全国联通30元
+20012	全国联通50元
+20013	全国联通100元
+20014	全国联通200元
+20015	全国联通300元
+20016	全国联通500元
+
+20017	全国电信10元
+20018	全国电信20元
+20019	全国电信30元
+20020	全国电信50元
+20021	全国电信100元
+20022	全国电信200元
+20023	全国电信300元
+20024	全国电信500元

+ 41 - 0
helper/refill/api/xyz/yuanrun/RefillCallBack.php

@@ -0,0 +1,41 @@
+<?php
+namespace refill\yuanrun;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yuanrun/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = config::sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function notify($params)
+    {
+        $order_sn = $params['ret_para'];
+        $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'];
+        $status = $params['status'];
+        if ($status === 'success') {
+            $data['official_sn'] = strtolower($params['sz_order_no']) == 'null' ? '' : $params['sz_order_no'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 'failed') {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 129 - 0
helper/refill/api/xyz/yuanrun/RefillPhone.php

@@ -0,0 +1,129 @@
+<?php
+namespace refill\yuanrun;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yuanrun/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, int $amount, string $order_sn)
+    {
+        $params['cpid'] = config::CP_ID;
+        $params['create_time'] = date("YmdHis");
+        $params['mobile'] = $phone;
+        $params['type'] = 1;
+        $params['product_id'] = config::Product[$card_type][$amount];
+        $params['amount'] = $amount;
+        $params['op'] = config::operator[$card_type];
+        $params['ret_para'] = $order_sn;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $amount, $input['order_sn']);
+        $params['sign'] = config::sign($params);
+
+        $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);
+            $status = $resp['status'];
+
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($status === '0') {
+                return [true, $resp['order_no'], false];
+            } elseif (in_array($status, config::ERR_STATUS, true)){
+                return [false, $resp['msg'], false];
+            } elseif (in_array($status, config::NET_ERR_STATUS, true)) {
+                $net_errno = "HTTP-{$status}";
+                return [false, '查-' . $resp['msg'], true];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['cpid'] = config::CP_ID;
+        $params['order_no'] = $refill_info['order_sn'];
+        $params['mobile'] = $refill_info['card_no'];
+        $params['create_time'] = date("YmdHis");
+        $params['datetime'] = date("YmdHis", $refill_info['commit_time']);
+        $params['sign'] = config::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, '系统错误'];
+            }
+            elseif($resp['status'] === '0')
+            {
+                $status = $resp['data'];
+                if ($status === 'success') {
+                    $updata['official_sn'] = $resp['operator_serial_number'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 'failed') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 'untreated') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['cpid'] = config::CP_ID;
+        $params['create_time'] = date("YmdHis");
+        $params['sign'] = config::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'] === '0') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+}

+ 79 - 0
helper/refill/api/xyz/yuanrun/config.php

@@ -0,0 +1,79 @@
+<?php
+namespace refill\yuanrun;
+
+use mtopcard;
+class config
+{
+    //回调地址需 上游配置
+    const ORDER_URL = 'http://121.89.202.158/api/do';
+    const QUERY_URL = 'http://121.89.202.158/api/queryorder';
+    const BALANCE_URL = 'http://121.89.202.158/api/querybalance';
+
+    const CP_ID = '49449';
+    const CP_KEY = '1a3239f76e20480fa';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yuanrun.php";
+    const operator = [
+        mtopcard\ChinaMobileCard  => 1,
+        mtopcard\ChinaUnicomCard  => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+    const Product = [
+        mtopcard\ChinaMobileCard => [
+            10  => 20001,
+            20  => 20002,
+            30  => 20003,
+            50  => 20004,
+            100 => 20005,
+            200 => 20006,
+            300 => 20007,
+            500 => 20008
+        ],
+        mtopcard\ChinaUnicomCard => [
+            10  => 20009,
+            20  => 20010,
+            30  => 20011,
+            50  => 20012,
+            100 => 20013,
+            200 => 20014,
+            300 => 20015,
+            500 => 20016
+        ],
+        mtopcard\ChinaTelecomCard => [
+            10  => 20017,
+            20  => 20018,
+            30  => 20019,
+            50  => 20020,
+            100 => 20021,
+            200 => 20022,
+            300 => 20023,
+            500 => 20024
+        ],
+    ];
+    const ERR_STATUS = ['-10001', '-10002', '-10003', '-10004', '-10013', '-10005', '-10006', '-10007', '-10008', '-10009', '-10011', '-10012', '-10015', '-10016'];
+    const NET_ERR_STATUS = ['-10010', '-10000', '-999'];
+
+    public static function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if(self::check_empty($value) === false) {
+                $content .= "{$key}{$value}";
+            }
+        }
+        $content .= config::CP_KEY;
+        return md5($content);
+    }
+
+    public static function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+}

+ 4 - 0
mobile/callback/refill_yuanrun.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('yuanrun',$_POST);
+echo json_encode(['status' => 'success']);

+ 14 - 0
test/TestRefill.php

@@ -1917,6 +1917,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testYuanrun()
+    {
+//        $provider = $this->getProvider('yuanrun');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(18500608333, 5, 30, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '25801646616116681917', 'card_no' => 18500608333, 'commit_time' => 1646616131]);
+
+        $body = '{"cpid":"49449","order_no":"22030709220549449952471675","mobile":"18500608333","amount":"30","status":"success","sz_order_no":"100101101042203070922143047338","ret_para":"25801646616116681917","sign":"2fd2661ce353e4cb554d7d3ca3f09f4d"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('yuanrun','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);