xiaoyu 2 år sedan
förälder
incheckning
795e493c78

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

@@ -0,0 +1,48 @@
+<?php
+namespace refill\douxun;
+
+require_once(BASE_HELPER_RAPI_PATH . '/douxun/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)
+    {
+        $content = "id={$params['id']}&userid={$params['userid']}&status={$params['status']}&code={$params['code']}";
+        $content .= config::KEY;
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['code']);
+        $order_sn = $params['id'];
+        $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'];
+        $data['official_sn'] = strtolower($params['operatorid']) == 'null' ? '' : $params['operatorid'];
+
+        if ($status === 8888) {
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 8030) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 126 - 0
helper/refill/api/xyz/douxun/RefillPhone.php

@@ -0,0 +1,126 @@
+<?php
+namespace refill\douxun;
+
+require_once(BASE_HELPER_RAPI_PATH . '/douxun/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, string $order_sn)
+    {
+        $params['cpid'] = config::CP_ID;
+        $params['gamegoodid'] = 'qg';
+        $params['createtime'] = date("YmdHis");
+        $params['account'] = $phone;
+        $params['orderid'] = $order_sn;
+        $params['buynum'] = 1;
+        $params['buyerIp'] = config::API_IP;
+        $params['returnurl'] = config::NOTIFY_URL;
+        $params['buyvalue'] = $amount;
+        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, $order_sn);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::PAY_PHONE_URL, $params, 'GET', false, [], $net_errno);
+
+        if (empty($resp)) {
+            return [false, '网络错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = refill\util::xmlToArray($resp);
+            $code = $resp['Code'];
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($code === '0000') {
+                return [true, $resp['order_no'], false];
+            } elseif (in_array($code, config::ERR_CODE)){
+                return [false, $resp['msg'], false];
+            } elseif (in_array($code, ['8008','8010','8017'])){
+                $net_errno = "HTTP-{$code}";
+                return [false, $resp['msg'], true];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['OrderID'] = $refill_info['order_sn'];
+        $params['cpid'] = config::CP_ID;
+        $content = $params['cpid'] . $params['OrderID'] . config::KEY;
+        $params['sign'] = md5($content);
+
+        $resp = http_request(config::QUERY_URL, $params);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = refill\util::xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['state'] === '8888') {
+                $order_state = ORDER_STATE_SUCCESS;
+                $updata['official_sn'] = $resp['operatorid'];
+                Model('refill_order')->edit($refill_info['order_id'], $updata);
+            } elseif ($resp['state'] === '8030') {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif ($resp['state'] === '0000') {
+                $order_state = ORDER_STATE_SEND;
+            } else {
+                return [false, $resp['msg']];
+            }
+            return [true, $order_state];
+        }
+    }
+
+    public function balance()
+    {
+        $params['cpid'] = config::CP_ID;
+        $content = $params['cpid'] . config::KEY;
+        $params['sign'] = md5($content);
+
+        $resp = http_request(config::BALANCE_URL, $params);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = refill\util::xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }else {
+                return [true, $resp['balance']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $cpid = config::CP_ID;
+        $content = "cpid={$cpid}&gamegoodid={$params['gamegoodid']}&createtime={$params['createtime']}&account={$params['account']}&orderid={$params['orderid']}&buynum={$params['buynum']}";
+        $content .= config::KEY;
+        return md5($content);
+    }
+}

+ 17 - 0
helper/refill/api/xyz/douxun/config.php

@@ -0,0 +1,17 @@
+<?php
+namespace refill\douxun;
+
+class config
+{
+    const PAY_PHONE_URL = 'https://openapi.xunyin.com/openapi/submit';
+    const QUERY_URL= 'https://openapi.xunyin.com/openapi/query';
+    const BALANCE_URL= 'http://openapi.xunyin.com/openapi/QueryMerchant';
+    const CP_ID= '8417';
+    const KEY = 'd4317a37ad90bc38cd346c6ad3056a7f';
+    const API_IP = NET_IP;
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/refill_xunyin.php";
+    const ERR_CODE = [
+        '8001','8002','8003','8004','8005','8006','8007','8009','8011','8012','8013','8016','8020','9001','9002','9003','9004','9005','9006'
+    ];
+}
+

BIN
helper/refill/api/xyz/douxun/新豆讯话费网关平台接口文档V2.1.doc


BIN
helper/refill/api/xyz/douxun/话费产品编码.xls