xiaoyu 3 vuotta sitten
vanhempi
commit
02c087eedf

+ 52 - 0
helper/refill/api/xyz/youhedf/RefillCallBack.php

@@ -0,0 +1,52 @@
+<?php
+
+
+namespace refill\youhedf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/youhedf/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['szVerifyString'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nDemo={$params['nDemo']}&fSalePrice={$params['fSalePrice']}";
+        $content .= "&nFlag={$params['nFlag']}&szKey={$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['nFlag']);
+        $order_sn = $params['szOrderId'];
+        $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['szRtnMsg']) == 'null' ? '' : $params['szRtnMsg'];
+            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];
+        }
+    }
+}

+ 152 - 0
helper/refill/api/xyz/youhedf/RefillPhone.php

@@ -0,0 +1,152 @@
+<?php
+
+namespace refill\youhedf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/youhedf/config.php');
+
+use refill;
+use Log;
+use mtopcard;
+
+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, $regin_no)
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $params['szOrderId'] = $order_sn;
+        $params['szPhoneNum'] = $phone;
+        $params['nMoney'] = $amount;
+        $params['nSortType'] = $card_type;
+        $params['nProductClass'] = 1;
+        $params['nProductType'] = 1;
+        $params['szProductId'] = config::Product[$amount];
+        $params['szTimeStamp'] = date("Y-m-d H:i:s");
+        $params['szNotifyUrl'] = config::NOTIFY_URL;
+
+        $data = [
+            'province' => mtopcard\ProvinceList[$regin_no],
+            'area' => mtopcard\ProvinceList[$regin_no],
+        ];
+        $params['params'] = json_encode($data, JSON_UNESCAPED_UNICODE);
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $regin_no = $params['regin_no'] ?? -1;
+        if($regin_no <= 0) {
+            return [false, '省份获取错误', false];
+        }
+        $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $regin_no);
+
+        $sign = $this->sign($params);
+        $params['szVerifyString'] = $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);
+
+            $nRtn = $resp['nRtn'];
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($nRtn === 0) {
+                return [true, '', false];
+            } elseif (in_array($nRtn, config::ERR_NOS, true)) {
+                return [false, $resp['szRtnCode'], false];
+            } elseif (in_array($nRtn, [2050, 999], true)) {
+                $net_errno = "HTTP-{$nRtn}";
+                return [false, $resp['szRtnCode'], true];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resp['szRtnCode'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $params['szOrderId'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "szAgentId={$params['szAgentId']}&szOrderId={$params['szOrderId']}&szKey={$key}";
+        $params['szVerifyString'] = 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 = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }
+
+            $status = $resp['nRtn'];
+            if ($status === 5012) {
+                $updata['official_sn'] = $resp['szRtnMsg'];
+                Model('refill_order')->edit($refill_info['order_id'], $updata);
+                $order_state = ORDER_STATE_SUCCESS;
+            } elseif ($status === 5013) {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif (in_array($status, [5011,5019],true)) {
+                $order_state = ORDER_STATE_SEND;
+            } elseif ($status === 5005 && (time() - $refill_info['commit_time'] >= 300)) {
+                $order_state = ORDER_STATE_NOEXIST;
+            } else {
+                return [false, $resp['szRtnMsg']];
+            }
+
+            return [true, $order_state];
+        }
+    }
+
+    public function balance()
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$params['szAgentId']}&szKey={$key}";
+        $params['szVerifyString'] = 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 = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['nRtn'] === 0) {
+                return [true, $resp['fBalance']];
+            } else {
+                return [false, $resp['szRtnCode']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nMoney={$params['nMoney']}&nSortType={$params['nSortType']}";
+        $content .= "&nProductClass={$params['nProductClass']}&nProductType={$params['nProductType']}&szTimeStamp={$params['szTimeStamp']}&szKey={$key}";
+        return md5($content);
+    }
+}

+ 26 - 0
helper/refill/api/xyz/youhedf/account.txt

@@ -0,0 +1,26 @@
+正式API id : 200044
+正式API 密钥:940500a70ce346e6838fa314adf104cc
+
+测试ID:200000
+秘钥:2a7533687d974571a2051ad555bfd2f5
+
+登陆地址:http://118.31.168.250:10186/plat/index
+账户名:yzdf
+初始密码(建议首次登陆之后修改):Ly4Urmh9crCN$gXM
+
+接口IP:118.31.168.250
+
+话费下单地址:http://118.31.168.250:10186/plat/api/old/submitorder
+电费下单地址http://118.31.168.250:10186/plat/api/df/submitorder
+查询地址:http://118.31.168.250:10186/plat/api/old/queryorder
+查询余额地址:http://118.31.168.250:10186/plat/api/old/queryBalance
+
+对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+
+
+通用电费50元   -  101030050
+通用电费100元   -  101030100
+通用电费200元   -  101030200
+通用电费300元   -  101030300
+通用电费500元   -  101030500
+通用电费1000元   -  1010301000

+ 37 - 0
helper/refill/api/xyz/youhedf/config.php

@@ -0,0 +1,37 @@
+<?php
+
+
+namespace refill\youhedf;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://118.31.168.250:10186/plat/api/df/submitorder';
+    const QUERY_URL= 'http://118.31.168.250:10186/plat/api/old/queryorder';
+    const BALANCE_URL = 'http://118.31.168.250:10186/plat/api/old/queryBalance';
+
+    const USER_ID= '200044';
+    const KEY = '940500a70ce346e6838fa314adf104cc';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_youhedf.php";
+
+    const operator = [
+        mtopcard\ChinaMobileCard  => 1,
+        mtopcard\ChinaUnicomCard  => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+
+    const ERR_NOS = [
+        1000,1001,1003,1004,2001,2002,2003,2020,2021,1006,2030,3003
+    ];
+
+    const Product = [
+        50      => 101030050,
+        100     => 101030100,
+        200     => 101030200,
+        300     => 101030300,
+        500     => 101030500,
+        1000    => 1010301000,
+
+    ];
+}

+ 4 - 0
mobile/callback/refill_youhedf.php

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

+ 14 - 0
test/TestRefill.php

@@ -2103,6 +2103,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testYouhedf()
+    {
+//        $provider = $this->getProvider('youhedf');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(1004638637, 101, 50, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
+//        $resp = $provider->query(['order_sn' => '80821649748836825835']);
+
+        $body = '{"szOrderId":"27341649750036121132","fSalePrice":"46.5","szAgentId":"200044","nFlag":"3","szVerifyString":"52b9057e467f09cf21eaceacddb475e6","szPhoneNum":"1004638637","szRtnMsg":"","nDemo":"50"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('youhedf','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);