Browse Source

bingguang_third

xiaoyu 1 năm trước cách đây
mục cha
commit
41f7e71b0d

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

@@ -9290,6 +9290,11 @@ $bingguang_third = ['name' => 'bingguang', 'store_id' => 321, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$bingguang_third_third = ['name' => 'bingguang_third', 'store_id' => 324, 'qualitys' => '1',
+    'amount' => [
+        100 => [['goods_id' => 8653, 'price' => 99, 'quality' => 1, 'card_type' => 'third']],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
 
 $third_providers = [
     ['name' => 'lingzhthird', 'cfg' => $lingzhthird],
@@ -9307,6 +9312,7 @@ $third_providers = [
     ['name' => 'zhongst_doubi', 'cfg' => $zhongst_doubi_third],
     ['name' => 'weixue_doubi', 'cfg' => $weixue_doubi_third],
     ['name' => 'bingguang', 'cfg' => $bingguang_third],
+    ['name' => 'bingguang_third', 'cfg' => $bingguang_third_third],
 ];
 $config['third_providers'] = $third_providers;
 

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

@@ -0,0 +1,67 @@
+<?php
+namespace refill\bingguang_third;
+
+require_once(BASE_HELPER_RAPI_PATH . '/bingguang_third/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')->getOrderInfoForNotify(['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];
+        }
+    }
+}

+ 171 - 0
helper/refill/api/xyz/bingguang_third/RefillPhone.php

@@ -0,0 +1,171 @@
+<?php
+
+namespace refill\bingguang_third;
+
+require_once(BASE_HELPER_RAPI_PATH . '/bingguang_third/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillThird
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function getProductCode($goods_id, $sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProviderProduct($this->mStoreID,$goods_id,$sys_pcode);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['channel_code'];
+        }
+    }
+
+    private function req_params($phone, string $order_sn, $product_code)
+    {
+        $params['appId'] = config::APP_ID;
+        $params['outOrderId'] = $order_sn;
+        $params['uuid'] = $phone;
+        $params['itemId'] = $product_code;
+        $params['amount'] = 1;
+        $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'];
+        $goods_id = intval($params['goods_id']);
+
+        $product_code = $this->getProductCode($goods_id, $params['product_code']);
+        Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
+
+        $params = $this->req_params($card_no, $order_sn, $product_code);
+        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);
+    }
+}

+ 18 - 0
helper/refill/api/xyz/bingguang_third/config.php

@@ -0,0 +1,18 @@
+<?php
+
+
+namespace refill\bingguang_third;
+
+class config
+{
+    const ORDER_URL = 'http://120.79.190.232:8911/api/order/submit';
+    const QUERY_URL = 'http://120.79.190.232:8911/api/order/query';
+    const BALANCE_URL = 'http://120.79.190.232:8911/api/account/balance';
+
+    const APP_ID = 'lMIQD9hkWG';
+    const APP_SECRET = 'nKFiCyiTcZAIXXvx';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_bingguang_third.php";
+
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+    const ERRCODES = ['-10', '-12', '-13', '-14', '-15', '-16', '-18', '-21'];
+}

+ 14 - 0
helper/refill/api/xyz/bingguang_third/开户信息.txt

@@ -0,0 +1,14 @@
+后台地址:http://120.79.190.232:8888
+帐号:bjgyqyzcxy
+密码:159447
+二级密码:fcFv4104
+appId:lMIQD9hkWG
+appSecret:nKFiCyiTcZAIXXvx
+后台-商品列表,可查看已配置商品信息
+后台-安全中心,可配置IP白名单
+接口文档:https://www.showdoc.com.cn/2167197494741781/9729864782737996
+通用直充接口地址:http://120.79.190.232:8911/api/order/submit
+话费直充接口地址:http://120.79.190.232:8911/api/hf/order/submit
+卡密提取接口地址:http://120.79.190.232:8911/api/card/get
+查询接口接口地址:http://120.79.190.232:8911/api/order/query
+余额查询接口地址:http://120.79.190.232:8911/api/account/balance

+ 4 - 0
mobile/callback/refill_bingguang_third.php

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

+ 13 - 0
test/TestRefill.php

@@ -3373,7 +3373,20 @@ class TestRefill extends TestCase
         $provider = $this->getProvider('zhongst_oil', 'RefillCallBack');
         $ret = $provider->verify($params);
         $resp = $provider->notify($params);
+    }
+
+    public function testBingguang_third()
+    {
+//        $provider = $this->getProvider('bingguang_third');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(608168539, 7, 30, [ 'order_sn' => $this->make_sn(), 'product_code' => 'XYZ100777', 'goods_id' => '6978', ]);
+//        $resp = $provider->query(['order_sn' => '92481683880348681476']);
 
+        $body = ' {"orderId":"230512163238675676","appId":"lMIQD9hkWG","outOrderId":"92481683880348681476","sign":"37a3b416c25f4272b4375a544168033b","orderStatus":"3","completeTime":"20230512164216","orderDesc":"\u8ba2\u5355\u5931\u8d25"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('bingguang_third','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
     }
 
     public function testAmingjd()