xiaoyu 2 年之前
父節點
當前提交
7fd3263940

+ 68 - 0
helper/refill/api/xyz/xuanji/RefillCallBack.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace refill\xuanji;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xuanji/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;
+        }
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($params)
+    {
+        $token = config::TOKEN;
+        ksort($params);
+
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content .= "token={$token}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['morder'];
+        $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) {
+            return [$order_id, true, false, true];
+        } elseif ($status === 3) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 138 - 0
helper/refill/api/xyz/xuanji/RefillOil.php

@@ -0,0 +1,138 @@
+<?php
+
+namespace refill\xuanji;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xuanji/config.php');
+
+use refill;
+use Log;
+
+class RefillOil 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['order'] = $order_sn;
+        $params['card'] = $card_no;
+        $params['api_product'] = 'zshcz_zc';
+        $params['cash'] = $amount;
+        $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['merchant_order_id'] = $refill_info['order_sn'];
+        $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 && (time() - $refill_info['commit_time'] > 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['info']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['appid'] = config::APP_ID;
+        $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)
+    {
+        $token = config::TOKEN;
+        ksort($params);
+
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content .= "token={$token}";
+        return md5($content);
+    }
+}

+ 13 - 0
helper/refill/api/xyz/xuanji/config.php

@@ -0,0 +1,13 @@
+<?php
+namespace refill\xuanji;
+
+class config
+{
+    const ORDER_URL = 'https://server.jumiit.com/gateway/api.handle/submit';
+    const QUERY_URL = 'https://server.jumiit.com/gateway/api.handle/order';
+    const BALANCE_URL = 'https://server.jumiit.com/gateway/api.handle/account';
+
+    const APP_ID = 'CZ27801384';
+    const TOKEN = '62zdsr7j1h7maaflc4c8kgx9j9vxu8';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_xuanji.php";
+}

+ 44 - 0
helper/refill/api/xyz/xuanji/对接文档.txt

@@ -0,0 +1,44 @@
+商户登录地址:https://shanghu.jumiit.com
+商户:椰子
+appid:CZ27801384
+token:62zdsr7j1h7maaflc4c8kgx9j9vxu8
+登录账户名:yezi
+登录密码同上
+对接接口地址:https://server.jumiit.com
+产品:
+中石化:zshcz_zc
+中石油:zsycz_zc
+
+
+余额接口
+
+接口http://server.jumiit.com/gateway/api.handle/account
+参数:
+appid
+time时间两个参数
+
+
+{
+    "code": 1,
+    "info": "ok",
+    "data": {
+        "name": "椰子",
+        "account": "600.00",
+        "credit": "100000.00",
+        "appid": "CZ27801384"
+    }
+}
+account为账户余额(这是提前充值的余额,如果是授信用户可以忽略)
+credit(授信用户余额)
+
+西京:
+signature
+
+西京:
+签名全部是这个
+
+西京:
+不是sign
+
+西京:
+签名参数

二進制
helper/refill/api/xyz/xuanji/玄机充值系统对接文档.docx


+ 4 - 0
mobile/callback/refill_xuanji.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('xuanji',$_POST);
+echo ('success');

+ 14 - 0
test/TestRefill.php

@@ -2839,6 +2839,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testXuanji()
+    {
+//        $provider = $this->getProvider('xuanji', 'RefillOil');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(1000111100021211884, 2, 100, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '73491669603140334285']);
+
+        $body = '{"appid":"CZ27801384","order":"D20221128031516100180983","morder":"73491669603140334285","status":"3","cash":"100","signature":"1e0d2b0dbec37ebc4a8bd03f0afd03dc"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('xuanji','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);