xiaoyu 2 gadi atpakaļ
vecāks
revīzija
efbf7c94ea

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

@@ -8799,6 +8799,12 @@ $zhongst_doubi_third = ['name' => 'zhongst_doubi', 'store_id' => 296, 'qualitys'
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$weixue_doubi_third = ['name' => 'weixue_doubi', 'store_id' => 307, 'qualitys' => '1',
+    'amount' => [
+        100 => [['goods_id' => 8536, 'price' => 99, 'quality' => 1, 'card_type' => 'third']],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $third_providers = [
     ['name' => 'lingzhthird', 'cfg' => $lingzhthird],
     ['name' => 'jumithird', 'cfg' => $jumithird],
@@ -8813,6 +8819,7 @@ $third_providers = [
     ['name' => 'gdsinopec', 'cfg' => $gdsinopec],
     ['name' => 'tianrui', 'cfg' => $tianrui_third],
     ['name' => 'zhongst_doubi', 'cfg' => $zhongst_doubi_third],
+    ['name' => 'weixue_doubi', 'cfg' => $weixue_doubi_third],
 ];
 $config['third_providers'] = $third_providers;
 

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

@@ -0,0 +1,46 @@
+<?php
+namespace refill\weixue_doubi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/weixue_doubi/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)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$userid}&orderid={$params['orderid']}&sporderid={$params['sporderid']}&merchantsubmittime={$params['merchantsubmittime']}";
+        $content .= "&resultno={$params['resultno']}&key={$key}";
+        return strtoupper(md5($content));
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['resultno']);
+        $order_sn = $params['sporderid'];
+        $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 === 1) {
+            return [$order_id, true, false, true];
+        } elseif ($status === 9) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 184 - 0
helper/refill/api/xyz/weixue_doubi/RefillPhone.php

@@ -0,0 +1,184 @@
+<?php
+
+namespace refill\weixue_doubi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/weixue_doubi/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillThird
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params($phone, int $amount, string $order_sn, $product_code)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['productid'] = $product_code;
+        $params['price'] = $amount;
+        $params['num'] = 1;
+        $params['mobile'] = $phone;
+        $params['spordertime'] = date("YmdHis");
+        $params['sporderid'] = $order_sn;
+        $params['back_url'] = config::NOTIFY_URL;
+
+        return $params;
+    }
+
+    private function getProductAmount($sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProduct(['system_code' => $sys_pcode]);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['refill_amount'];
+        }
+    }
+
+    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'];
+        }
+    }
+
+    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]);
+
+        $amount = $this->getProductAmount($params['product_code']);
+        if(empty($amount)) {
+            return [false, '产品未开启', false];
+        }
+
+        $params = $this->req_params($card_no, $amount, $order_sn, $product_code);
+
+        $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 = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            }
+
+            $resultno = $resp['resultno'];
+            if (in_array($resultno, ['0', '2'], true)) {
+                return [true, $resp['orderid'], false];
+            } elseif (in_array($resultno, config::ERR_NOS, true)) {
+                return [false, $resultno, false];
+            } elseif ($resultno === '9999' || $resultno === '5006') {
+                $net_errno = "HTTP-{$resultno}";
+                return [false, $resultno, true];
+            } else {
+                //未知结果码
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resultno, true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['sporderid'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "userid={$params['userid']}&sporderid={$params['sporderid']}&key={$key}";
+        $params['sign'] = strtoupper(md5($content));
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp))
+            {
+                return [false, '网络错误'];
+            }
+            else
+            {
+                $resultno = $resp['resultno'];
+                if ($resultno === '1') {
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($resultno === '9') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($resultno, ['0','2'], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($resultno === '5007' && (time() - $refill_info['commit_time'] > 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $resultno];
+                }
+
+                return [true, $order_state];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['userid'] = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$params['userid']}&key={$key}";
+        $params['sign'] = strtoupper(md5($content));
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['resultno'] === '1') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['resultno']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$userid}&productid={$params['productid']}&price={$params['price']}&num={$params['num']}&mobile={$params['mobile']}&spordertime={$params['spordertime']}";
+        $content .= "&sporderid={$params['sporderid']}&key={$key}";
+        return strtoupper(md5($content));
+    }
+
+    public function xmlToArray($xml)
+    {
+        $replace_str = str_replace(' ','','encoding="gb2312"');
+        $xml = mb_convert_encoding($xml,"UTF-8","gb2312");
+        $xml = str_replace($replace_str, "encoding='utf-8'", $xml);
+        return refill\util::xmlToArray($xml);
+    }
+}

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

@@ -0,0 +1,22 @@
+<?php
+
+
+namespace refill\weixue_doubi;
+
+class config
+{
+    //https://www.showdoc.com.cn/AQL666666/
+    const ORDER_URL = 'http://121.36.216.15:9086/onlinepay.do';
+    const QUERY_URL= 'http://121.36.216.15:9086/searchpay.do';
+    const BALANCE_URL = 'http://121.36.216.15:9086/searchbalance.do';
+
+    const USER_ID= '10003063';
+    const KEY = 'c72CERahKb2t2kcCcMPY8PbPwM8jGiWY';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_weixue_doubi.php";
+
+    const ERR_NOS = [
+        '5001','5002','5003','5004','5005','5008','5009','5010','5011','5012','7001'
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;'];
+
+}

+ 22 - 0
helper/refill/api/xyz/weixue_doubi/对接文档-yezi.txt

@@ -0,0 +1,22 @@
+下游客户注册和登录地址:
+http://121.36.216.15:7080/
+
+api接口文档地址:
+https://www.showdoc.com.cn/AQL666666/
+
+下单地址:
+http://121.36.216.15:9086/onlinepay.do
+余额查询:
+http://121.36.216.15:9086/searchbalance.do
+订单主动查询地址:
+http://121.36.216.15:9086/searchpay.do
+
+ID:10003063
+秘钥:c72CERahKb2t2kcCcMPY8PbPwM8jGiWY
+登录名:椰子抖币
+密码:123456
+授信:2w
+
+qgdb100y    面值100
+qgdb200y    面值200
+qgdb300y    面值300

+ 4 - 0
mobile/callback/refill_weixue_doubi.php

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

+ 18 - 0
test/TestRefill.php

@@ -3217,6 +3217,24 @@ class TestRefill extends TestCase
 
     }
 
+    public function testweixue_doubi()
+    {
+//        $provider = $this->getProvider('weixue_doubi');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(588073521, 7, 100, [
+//            'order_sn' => $this->make_sn(),
+//            'product_code' => 'XYZ100772',
+//            'goods_id' => '6978'
+//        ]);
+//        $resp = $provider->query(['order_sn' => '99341680249477846685']);
+
+        $body = '{"orderid":"KGM23033115585506241","sporderid":"99341680249477846685","userid":"10003063","merchantsubmittime":"20230331160351","resultno":"1","parvalue":"100","remark1":"{\"OfficialDes\"null,\"OfficialOrderID\"null,\"SellPrice\"1010000}","payno":"{\"OfficialDes\"null,\"OfficialOrderID\"null,\"SellPrice\"1010000}","fundbalance":"-97.5","sign":"C4A87E0C7C3AE4801FDAD746277B342B"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('weixue_doubi','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);