xiaoyu 3 年 前
コミット
64e99472e2

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

@@ -4582,6 +4582,51 @@ $ruierxun_phone = ['name' => 'ruierxun', 'store_id' => 189,'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$ningying_phone = ['name' => 'ningying', 'store_id' => 190,'qualitys' => '1',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 7609, 'price' => 9.7, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7609, 'price' => 9.58, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7609, 'price' => 9.67, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 7610, 'price' => 19.4, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7610, 'price' => 19.16, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7610, 'price' => 19.34, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+        30 => [
+            ['goods_id' => 7611, 'price' => 29.1, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7611, 'price' => 28.74, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7611, 'price' => 29.01, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 7612, 'price' => 48.5, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7612, 'price' => 47.9, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7612, 'price' => 48.35, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 7613, 'price' => 97, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7613, 'price' => 95.8, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7613, 'price' => 96.7, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 7614, 'price' => 194, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7614, 'price' => 191.6, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7614, 'price' => 193.4, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+//        300 => [
+//            ['goods_id' => 7615, 'price' => 291, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7615, 'price' => 287.4, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7615, 'price' => 290.1, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+//        500 => [
+//            ['goods_id' => 7616, 'price' => 485, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7616, 'price' => 479, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7616, 'price' => 483.5, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -4734,6 +4779,7 @@ $phone_providers = [
     ['name' => 'ruixunda_lt', 'cfg' => $ruixunda_lt_phone],
     ['name' => 'ruizhi', 'cfg' => $ruizhi_phone],
     ['name' => 'ruierxun', 'cfg' => $ruierxun_phone],
+    ['name' => 'ningying', 'cfg' => $ningying_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

+ 67 - 0
helper/refill/api/xyz/ningying/RefillCallBack.php

@@ -0,0 +1,67 @@
+<?php
+namespace refill\ningying;
+
+require_once(BASE_HELPER_RAPI_PATH . '/ningying/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)
+    {
+        $params['appSecret'] = config::APP_SECRET;
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content = rtrim($content, '&');
+        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['orderStatus']);
+        $order_sn = $params['outOrderId'];
+        $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['ext1']) == 'null' ? '' : $params['ext1'];
+            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];
+        }
+    }
+}

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

@@ -0,0 +1,155 @@
+<?php
+
+namespace refill\ningying;
+
+require_once(BASE_HELPER_RAPI_PATH . '/ningying/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['appId'] = config::APP_ID;
+        $params['outOrderId'] = $order_sn;
+        $params['uuid'] = $phone;
+        $params['itemId'] = config::PRODUCT[$card_type][$amount];
+        $params['itemFace'] = $amount;
+        $params['callbackUrl'] = config::NOTIFY_URL;
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
+        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['itemId'])) {
+            return [false, '商品编号错误', false];
+        }
+        $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'] === '00') {
+                return [true, $resp['orderId'], false];
+            } elseif (in_array($resp['code'], config::ERRCODES, true)) {
+                return [false, $resp['msg'], false];
+            } elseif (in_array($resp['code'], ['-22', '-23', '-99'], true)) {
+                $net_errno = "HTTP-{$resp['code']}";
+                return [false, $resp['msg'], true];
+            } else {
+                $net_errno = "HTTP-998";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['appId'] = config::APP_ID;
+        $params['outOrderId'] = $refill_info['order_sn'];
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
+        $params['sign'] = $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'] === '00')
+            {
+                $status = $resp['orderStatus'];
+                if ($status === '2') {
+                    $updata['official_sn'] = $resp['ext1'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === '3') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === '1') {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($status === '4' && (time() - $refill_info['commit_time'] >= 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['appId'] = config::APP_ID;
+        $params['timestamp'] = date("YmdHis").$this->get_millisecond();
+        $params['sign'] = $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'] === '00') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function get_millisecond()
+    {
+        list($usec, $sec) = explode(" ", microtime());
+        return round($usec*1000);
+    }
+
+    private function sign($params)
+    {
+        $params['appSecret'] = config::APP_SECRET;
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content = rtrim($content, '&');
+        return md5($content);
+    }
+}

+ 38 - 0
helper/refill/api/xyz/ningying/config.php

@@ -0,0 +1,38 @@
+<?php
+
+
+namespace refill\ningying;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://47.97.218.21:8911/api/hf/order/submit';
+    const QUERY_URL = 'http://47.97.218.21:8911/api/order/query';
+    const BALANCE_URL = 'http://47.97.218.21:8911/api/account/balance';
+
+    const APP_ID = 'O8y6eOzWY1';
+    const APP_SECRET = 'qkTxoSgYBBXZDjYy';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_ningying.php";
+    const PRODUCT = [
+        mtopcard\ChinaMobileCard => [
+            30  => 100001,
+            50  => 100002,
+            100 => 100003,
+            200 => 100004
+        ],
+        mtopcard\ChinaUnicomCard => [
+            30  => 100007,
+            50  => 100008,
+            100 => 100009,
+            200 => 100010
+        ],
+        mtopcard\ChinaTelecomCard => [
+            30  => 100013,
+            50  => 100014,
+            100 => 100015,
+            200 => 100016
+        ],
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+    const ERRCODES = ['-10', '-12', '-13', '-14', '-15', '-16', '-18', '-21'];
+}

+ 36 - 0
helper/refill/api/xyz/ningying/开户信息.txt

@@ -0,0 +1,36 @@
+后台地址:http://47.97.218.21:8888
+帐号:椰子
+密码:398381
+二级密码:RovB4678
+appId:O8y6eOzWY1
+appSecret:qkTxoSgYBBXZDjYy
+后台-商品列表,可查看已配置商品信息
+后台-安全中心,可配置IP白名单
+接口文档:https://www.showdoc.com.cn/1686453783298366/7925312871840290
+话费直充接口:http://47.97.218.21:8911/api/hf/order/submit
+通用直充接口:http://47.97.218.21:8911/api/order/submit
+卡密提取接口:http://47.97.218.21:8911/api/card/get
+查单接口接口:http://47.97.218.21:8911/api/order/query
+余额接口接口:http://47.97.218.21:8911/api/account/balance
+
+
+
+
+100001 全国移动30
+100002 全国移动50
+100003 全国移动100
+100004 全国移动200
+
+
+
+100007 全国联通30
+100008 全国联通50
+100009 全国联通100
+100010 全国联通200
+
+
+
+100013 全国电信30
+100014 全国电信50
+100015 全国电信100
+100016 全国电信200

+ 4 - 0
mobile/callback/refill_ningying.php

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

+ 14 - 0
test/TestRefill.php

@@ -1806,6 +1806,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testNingying()
+    {
+//        $provider = $this->getProvider('ningying');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '59481645434420716297']);
+
+        $body = '{"orderId":"220221170704698128","appId":"O8y6eOzWY1","outOrderId":"59481645434420716297","sign":"7476bd7d6cb51a5b25a183145d4a0ada","orderStatus":"3","completeTime":"20220221171148","orderDesc":"\u8ba2\u5355\u5931\u8d25"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('ningying','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);