Browse Source

oufei test

xiaoyu 2 years ago
parent
commit
631785f1ad

+ 50 - 0
helper/refill/api/xyz/oufei/RefillCallBack.php

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

+ 144 - 0
helper/refill/api/xyz/oufei/RefillOil.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace refill\oufei;
+
+require_once(BASE_HELPER_RAPI_PATH . '/oufei/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['userId'] = config::USER_ID;
+        $params['userPws'] = md5(config::USER_PWS);
+        $params['cardId'] = config::Product[$card_type][$amount];
+        $params['buyNum'] = 1;
+        $params['spOrderId'] = $order_sn;
+        $params['orderTime'] = date("YmdHis");
+        $params['customerNo'] = $phone;
+        $params['retUrl'] = config::NOTIFY_URL;
+        $params['version'] = '6.0';
+        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);
+
+        $sign = $this->sign($params);
+        $params['md5Str'] = $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 = refill\util::xmlToArray($resp);
+
+            $retCode = $resp['retCode'];
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($retCode === 1) {
+                return [true, $resp['orderId'], false];
+            } elseif (in_array($retCode, config::ERR_NOS, true)) {
+                return [false, $resp['errMsg'], false];
+            } elseif ($retCode === 9999) {
+                $net_errno = "HTTP-{$retCode}";
+                return [false, $resp['errMsg'], true];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resp['errMsg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['userPws'] = md5(config::USER_PWS);
+        $params['sporder_id'] = $refill_info['order_sn'];
+        $params['version'] = '6.0';
+        $params['format'] = 'json';
+
+        $key = config::KEY;
+        $content = "{$params['userid']}{$params['userPws']}{$params['sporder_id']}{$key}";
+        $params['md5_str'] = 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 = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }
+
+            $status = $resp['retcode'];
+            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['userid'] = config::USER_ID;
+        $params['userPws'] = md5(config::USER_PWS);
+        $params['version'] = '6.0';
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = refill\util::xmlToArray($resp);
+
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['retcode'] === 1) {
+                return [true, $resp['totalBalance']];
+            } else {
+                return [false, $resp['err_msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content = "{$params['userId']}{$params['userPws']}{$params['cardId']}{$params['buyNum']}{$params['spOrderId']}{$params['orderTime']}{$params['customerNo']}";
+        $content .= $key;
+        return strtoupper(md5($content));
+    }
+}

+ 10 - 0
helper/refill/api/xyz/oufei/api.txt

@@ -0,0 +1,10 @@
+测试环境账号:
+userid:A08566
+userpws:of111111    需要 MD5 小写
+秘钥(keystr):OFCARD
+
+64349807  全国中石油加油卡卡密200元
+
+加油卡直充200元的商品编号 64157003
+
+http://apitest.ofpay.com/newOnlineOrder.do

+ 52 - 0
helper/refill/api/xyz/oufei/config.php

@@ -0,0 +1,52 @@
+<?php
+
+
+namespace refill\oufei;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://apitest.ofpay.com/newOnlineOrder.do';
+    const QUERY_URL= 'http://apitest.ofpay.com/api/query.do';
+    const BALANCE_URL = 'http://apitest.ofpay.com/newqueryuserinfo.do';
+
+    const USER_ID = 'A08566';
+    const USER_PWS = 'of111111';
+    const KEY = 'OFCARD';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_oufei.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 = [
+        1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 319, 321, 331, 9998, 4001
+    ];
+
+    const Product = [
+        mtopcard\ChinaMobileCard => [
+            10  => 1000010,
+            20  => 1000020,
+            50  => 1000050,
+            100 => 1000100,
+            200 => 1000200,
+        ],
+        mtopcard\ChinaUnicomCard => [
+            30  => 2000030,
+            50  => 2000050,
+            100 => 2000100,
+            200 => 2000200,
+            300 => 2000300,
+            500 => 2000500,
+        ],
+        mtopcard\ChinaTelecomCard => [
+            30  => 3000030,
+            50  => 3000050,
+            100 => 3000100,
+            200 => 3000200,
+        ],
+    ];
+}