xiaoyu 3 years ago
parent
commit
c6f9693305

+ 47 - 0
helper/refill/api/xyz/shuoruan/RefillCallBack.php

@@ -0,0 +1,47 @@
+<?php
+namespace refill\shuoruan;
+
+require_once(BASE_HELPER_RAPI_PATH . '/shuoruan/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)
+    {
+        $key = config::KEY;
+        $content = "Orderid={$params['Orderid']}&Chargeid={$params['Chargeid']}&Orderstatu_int={$params['Orderstatu_int']}&Errorcode={$params['Errorcode']}&Password={$key}";
+        return md5($content);
+    }
+
+
+    public function notify($params)
+    {
+        $status = intval($params['Orderstatu_int']);
+        $order_sn = $params['Orderid'];
+        $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 (in_array($status, [11, 16])) {
+            return [$order_id, true, false,true];
+        }
+        elseif (in_array($status, [20, 21, 26])) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 129 - 0
helper/refill/api/xyz/shuoruan/RefillPhone.php

@@ -0,0 +1,129 @@
+<?php
+
+namespace refill\shuoruan;
+
+require_once(BASE_HELPER_RAPI_PATH . '/shuoruan/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    //统一请求
+    private function url_request($params, $action)
+    {
+        $params['action'] = $action;
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+        $params['agentAccount'] = config::ACCOUNT;
+        $params = json_encode($params);
+
+        $url = config::API_URL;
+        return http_post_data($url, $params, config::ExtHeaders, $net_errno);
+    }
+
+    private function req_params(int $phone,int $amount, string $order_sn)
+    {
+        $params['orderId'] = $order_sn;
+        $params['chargeAcct'] = $phone;
+        $params['chargeCash'] = $amount;
+        $params['chargeType'] = 0;
+        $params['retUrl'] = urlencode(config::NOTIFY_URL);
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $resp = $this->url_request($params,'CZ');
+
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif (intval($resp['errorCode']) === 1) {
+                return [true, $resp['chargeId'], false];
+            } elseif (in_array($resp['errorCode'], [-992, -993, -994, -995, -996, -997, -998])) {
+                $net_errno = $resp['errorCode'];
+                return [false, $resp['errorDesc'], false];
+            } else {
+                return [false, $resp['errorDesc'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $resp = $this->url_request($refill_info['order_sn'],'CX');
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif (intval($resp['errorCode']) === 1) {
+                $status = $resp['orderStatuInt'];
+                if (in_array($status, [11, 16])) {
+                    $updata['official_sn'] = $resp['transo'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif (in_array($status, [20, 21, 26])) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($status, [0, 1, 2, 6])) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['errorDesc']];
+                }
+                return [true, $order_state];
+            } elseif (intval($resp['errorCode']) === -201 && (time() - $refill_info['commit_time'] >= 180)) {
+                return [true, ORDER_STATE_NOEXIST];
+            } else {
+                return [false, $resp['errorDesc']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $resp = $this->url_request([],'YE');
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif (intval($resp['errorCode']) === 1) {
+                return [true, $resp['agentBalance']];
+            } else {
+                return [false, $resp['errorDesc']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $json_str = json_encode($params);
+        $content  = $json_str . config::KEY;
+        return md5($content);
+    }
+}

+ 15 - 0
helper/refill/api/xyz/shuoruan/config.php

@@ -0,0 +1,15 @@
+<?php
+
+
+namespace refill\shuoruan;
+
+
+class config
+{
+    const API_URL = 'http://api.sohan.hk:50080/API';
+
+    const ACCOUNT = '18600608333';
+    const KEY = '471D690CFB902BD8';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_shuoruan.php";
+    const ExtHeaders = ['Content-Type: application/json'];
+}

+ 7 - 0
helper/refill/api/xyz/shuoruan/北京椰子.txt

@@ -0,0 +1,7 @@
+密钥:471D690CFB902BD8
+账号:18600608333
+
+开发接口资料
+接口文档网址:http://apidoc.sy666.com/web/#/3
+接口订单提交地址:
+http://api.sohan.hk:50080/API