xiaoyu %!s(int64=3) %!d(string=hai) anos
pai
achega
3eda4fe09d

+ 60 - 0
helper/refill/api/xyz/yichangt_hf/RefillCallBack.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace refill\yichangt_hf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yichangt_hf/config.php');
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['signature']);
+        $sign = $this->sign($input);
+        if ($params['signature'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $params['token'] = sha1(config::APP_ID . '|' . config::APP_SECRET);
+        ksort($params);
+
+        $signature_string = '';
+        foreach ($params as $k => $v) {
+            if (strlen($v)) {
+                $signature_string .= $k . '=' . $v . '&';
+            }
+        }
+        $signature_string = substr($signature_string, 0, -1);
+
+        return sha1($signature_string);
+    }
+
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['merchant_order_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'];
+
+        if ($status === 2) {
+            $data['official_sn'] = strtolower($params['number']) == 'null' ? '' : $params['number'];
+            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];
+        }
+    }
+}

+ 147 - 0
helper/refill/api/xyz/yichangt_hf/RefillPhone.php

@@ -0,0 +1,147 @@
+<?php
+
+namespace refill\yichangt_hf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yichangt_hf/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $card_no, string $order_sn, int $amount)
+    {
+        $params['appid'] = config::APP_ID;
+        $params['api_product'] = 'zshcz';
+        $params['order'] = $order_sn;
+        $params['cash'] = $amount;
+        $params['card'] = $card_no;
+        $params['nonce'] = rand(100000,999999);
+        $params['time'] = time();
+        $params['notify'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $params['order_sn'], $amount);
+
+        $sign = $this->sign($params);
+        $params['signature'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $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['code'] === 1) {
+                return [true, $resp['data']['order'], false];
+            } else {
+                return [false, $resp['info'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['appid'] = config::APP_ID;
+        $params['api_product'] = 'query';
+        $params['merchant_order_id'] = $refill_info['order_sn'];
+        $params['nonce'] = rand(100000,999999);
+        $params['time'] = time();
+        $sign = $this->sign($params);
+        $params['signature'] = $sign;
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST');
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp))
+            {
+                return [false, '系统错误'];
+            }
+            elseif ($resp['code'] === 1)
+            {
+                $data = $resp['data'];
+                $status = $data['status'];
+                if ($status === 2) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($status, [1, 4], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['info']];
+                }
+
+                return [true, $order_state];
+            }
+            elseif ($resp['code'] === -101)
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['info']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['appid'] = config::APP_ID;
+        $params['api_product'] = 'query';
+        $params['nonce'] = rand(100000,999999);
+        $params['time'] = time();
+        $sign = $this->sign($params);
+        $params['signature'] = $sign;
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST');
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp ,true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === 1) {
+                return [true, $resp['data']['account'], false];
+            } else {
+                return [false, $resp['info'], false];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $params['token'] = sha1(config::APP_ID . '|' . config::APP_SECRET);
+        ksort($params);
+
+        $signature_string = '';
+        foreach ($params as $k => $v) {
+            if (strlen($v)) {
+                if($k == 'notify') {
+                    $v = urlencode($v);
+                }
+                $signature_string .= "{$k}={$v}&";
+            }
+        }
+        $signature_string = substr($signature_string, 0, -1);
+
+        return sha1($signature_string);
+    }
+}

+ 14 - 0
helper/refill/api/xyz/yichangt_hf/config.php

@@ -0,0 +1,14 @@
+<?php
+namespace refill\yichangt_hf;
+
+class config
+{
+    const ORDER_URL = 'http://api.yhfka.com/gateway/api.handle/submit';
+    const QUERY_URL = 'http://api.yhfka.com/gateway/api.handle/order';
+    const BALANCE_URL = 'http://api.yhfka.com/gateway/api.handle/account';
+
+    const APP_ID = 'app153238905711';
+    const APP_SECRET = 'PCRO4LPH6H1DCH0R5W8T4FPAHPQTEAHE';
+//    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yichangt_hf.php";
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+}

+ 8 - 0
helper/refill/api/xyz/yichangt_hf/对接文档.txt

@@ -0,0 +1,8 @@
+查看【椰子】的商户信息
+接口文档 http://xiaoyaoji.cn/project/1kzDAjrEhP6/1kzDAlGf9Sy 
+接口域名 http://api.yhfka.com 
+APPID app153238905711 
+APPSECRET PCRO4LPH6H1DCH0R5W8T4FPAHPQTEAHE 
+商户后台 http://sh.yhfka.com/ 
+后台账户 yezi 
+后台密码 yezi