xiaoyu 2 年之前
父節點
當前提交
d00d561741

+ 11 - 0
helper/refill/api/xyz/yongjia/API信息.txt

@@ -0,0 +1,11 @@
+测试参数
+ID:1
+秘钥:52e4fd509410446a8259fd8a93de6c85
+
+
+下单地址:http://123.56.68.57:1008/hqorder/api/submit
+查询地址:http://123.56.68.57:1008/hqorder/api/query
+查询余额地址:http://123.56.68.57:1008/hqorder/api/balance
+
+测试产品(需传产品编码)
+3000200	全国电信200元

+ 48 - 0
helper/refill/api/xyz/yongjia/RefillCallBack.php

@@ -0,0 +1,48 @@
+<?php
+namespace refill\yongjia;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yongjia/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)
+    {
+        $mchid = config::MCHID;
+        $key = config::KEY;
+        $content  = "mchid={$mchid}&orderid={$params['orderid']}&oid={$params['oid']}&number={$params['number']}&status={$params['status']}&key={$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $order_sn = $params['orderid'];
+        $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'];
+        $status = intval($params['status']);
+        if ($status === 2) {
+            $official_sn = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            $data['official_sn'] = $official_sn;
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true, $official_sn];
+        } elseif ($status === 3) {
+            return [$order_id, false, true, true, ''];
+        } else {
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 143 - 0
helper/refill/api/xyz/yongjia/RefillOil.php

@@ -0,0 +1,143 @@
+<?php
+
+namespace refill\yongjia;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yongjia/config.php');
+
+use refill;
+use Log;
+
+class RefillOil extends refill\IRefillOil
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $card_type, int $amount, string $order_sn)
+    {
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $order_sn;
+        $params['number'] = $phone;
+        $params['productid'] = config::PRODUCT[$card_type][$amount];
+        $params['timestamp'] = $this->getMillisecond();
+        $params['backurl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $amount, $input['order_sn']);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params , 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['status'] === 0) {
+                return [true, $resp['oid'], false];
+            } elseif ($resp['status'] === -1) {
+                return [false, $resp['msg'], false];
+            } else {
+                $net_errno = "HTTP-998";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "mchid={$params['mchid']}&orderid={$params['orderid']}&key={$key}";
+        $params['sign'] = md5($content);
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '系统错误', ''];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误', ''];
+            }
+            else {
+                $offical_sn = '';
+                $status = $resp['status'];
+                if ($status === 2) {
+                    $offical_sn = $resp['voucher'];
+                    $updata['official_sn'] = $offical_sn;
+                    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'] > 300)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $status, $offical_sn];
+                }
+                return [true, $order_state, $offical_sn];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['mchid'] = config::MCHID;
+        $key = config::KEY;
+        $content = "mchid={$params['mchid']}&key={$key}";
+        $params['sign'] = md5($content);
+        $params = json_encode($params);
+
+        $resp = http_post_data(config::BALANCE_URL, $params , 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['status'] === 1) {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content  = "mchid={$params['mchid']}&orderid={$params['orderid']}&number={$params['number']}&productid={$params['productid']}";
+        $content .= "&timestamp={$params['timestamp']}&key={$key}";
+        return md5($content);
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function getMillisecond()
+    {
+        $cur = microtime (true);
+        return intval($cur * 1000);
+    }
+}

+ 30 - 0
helper/refill/api/xyz/yongjia/config.php

@@ -0,0 +1,30 @@
+<?php
+
+
+namespace refill\yongjia;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://123.56.68.57:1008/hqorder/api/submit';
+    const QUERY_URL = 'http://123.56.68.57:1008/hqorder/api/query';
+    const BALANCE_URL = 'http://123.56.68.57:1008/hqorder/api/balance';
+
+    const MCHID = '1';
+    const KEY = '52e4fd509410446a8259fd8a93de6c85';
+//    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yongjia.php";
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+
+    const PRODUCT = [
+        mtopcard\ChinaMobileCard => [
+
+        ],
+        mtopcard\ChinaUnicomCard => [
+
+        ],
+        mtopcard\ChinaTelecomCard => [
+            200 => 3000200
+        ]
+    ];
+    const ExtHeaders = ['Content-Type: application/json'];
+}

+ 15 - 0
test/TestRefill.php

@@ -3249,6 +3249,21 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testYongjia()
+    {
+//        $provider = $this->getProvider('yongjia','RefillOil');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(18074608795, 6, 200, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '67461681184143372378']);
+
+        $body = '{"number":"18074608795","mchid":"1","orderid":"67461681184143372378","price":"200.0","voucher":"","sign":"b9c011c70734707b88351ec5efd96d98","oid":134,"status":"3"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('yongjia', 'RefillCallback');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);