haru haru vor 3 Jahren
Ursprung
Commit
04dc79a64f

+ 15 - 0
helper/refill/api/yl/shantong/API信息.txt

@@ -0,0 +1,15 @@
+域名
+http://wf-recharge-api.shantongdata.com
+代理商账户ID
+agentId: 1003
+代理商交易密码
+transactionPin: Qwer@1234
+代理商交互加密接口ID
+appId: cz_1003
+代理商交互加密接口密钥
+appKey: 2de7e2b1-c759-4fed-af35-3d3ca6f7aa95
+
+
+后台登录地址:http://wf-prepaid-web.shantongdata.com/
+后台登录用户:椰林网络
+后台登录密码:Wf@2022A

+ 40 - 0
helper/refill/api/yl/shantong/RefillCallBack.php

@@ -0,0 +1,40 @@
+<?php
+namespace refill\shantong;
+
+require_once(BASE_HELPER_RAPI_PATH . '/shantong/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = config::sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function notify($params)
+    {
+        $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'];
+        $status = intval($params['orderStatus']);
+        if ($status === 3) {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['ispVoucherId']]);
+            return [$order_id, true, false, true];
+        } elseif ($status === 99) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 130 - 0
helper/refill/api/yl/shantong/RefillPhone.php

@@ -0,0 +1,130 @@
+<?php
+namespace refill\shantong;
+
+require_once(BASE_HELPER_RAPI_PATH . '/shantong/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['mobile'] = $phone;
+        $params['perValue'] = $amount;
+        $params['orderId'] = $order_sn;
+        $params['orderDate'] = date("Y-m-d H:i:s");
+        $params['agentId'] = config::AGENT_ID;
+        $params['transactionPin'] = config::transactionPin;
+        $params['notifyUrl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
+    {
+        $params = config::pub_params();
+        $data = $this->req_params($card_no, $amount, $input['order_sn']);
+        $params['reqData'] = json_encode($data);
+        $params['sign'] = config::sign($params);
+
+        $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);
+            $code = $resp['code'];
+
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($code === 1) {
+                return [true, $resp['data']['businessOrderId'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params = config::pub_params();
+
+        $data['orderId'] = $refill_info['order_sn'];
+        $data['agentId'] = config::AGENT_ID;
+        $data['transactionPin'] = config::transactionPin;
+        $params['reqData'] = json_encode($data);
+        $params['sign'] = config::sign($params);
+
+        $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, '系统错误'];
+            }
+            elseif($resp['code'] === 1)
+            {
+                $status = $resp['data']['orderStatus'];
+                if ($status === 3) {
+                    $updata['official_sn'] = $resp['data']['ispVoucherId'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 99) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 1 || $status === 2) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params = config::pub_params();
+
+        $data['agentId'] = config::AGENT_ID;
+        $data['transactionPin'] = config::transactionPin;
+        $params['reqData'] = json_encode($data);
+        $params['sign'] = config::sign($params);
+
+        $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['code'] === 1) {
+                return [true, $resp['data']['currentBalance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+}

+ 60 - 0
helper/refill/api/yl/shantong/config.php

@@ -0,0 +1,60 @@
+<?php
+namespace refill\shantong;
+
+class config
+{
+    const ORDER_URL = 'http://wf-recharge-api.shantongdata.com/api/v1/mobile/order/apply';
+    const QUERY_URL = 'http://wf-recharge-api.shantongdata.com/api/v1/mobile/order/query';
+    const BALANCE_URL = 'http://wf-recharge-api.shantongdata.com/api/v1/agent/balance/enquiry';
+
+    const AGENT_ID = '1003';
+    const transactionPin = 'Qwer@1234';
+    const APP_ID = 'cz_1003';
+    const APP_KEY = '2de7e2b1-c759-4fed-af35-3d3ca6f7aa95';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_shantong.php";
+    const ExtHeaders = ['Content-Type: application/json;charset=UTF-8'];
+
+    private static function createNoncestr( $length = 32 )
+    {
+        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+        $str ="";
+        for ( $i = 0; $i < $length; $i++ )  {
+            $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
+        }
+        return $str;
+    }
+
+    public static function pub_params()
+    {
+        $params['appId'] = config::APP_ID;
+        $params['nonceStr'] = self::createNoncestr();
+        $params['timeStamp'] = time();
+
+        return $params;
+    }
+
+    public static function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if(self::check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content .= 'appKey='.config::APP_KEY;
+        return md5($content);
+    }
+
+    public static function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+}

BIN
helper/refill/api/yl/shantong/话费充值接口文档V2.1.6.pdf


+ 6 - 0
test/TestRefillYl.php

@@ -676,4 +676,10 @@ class TestRefillYl extends TestCase
         $provider = $this->getProvider('jumeng');
         $resp = $provider->balance();
     }
+
+    public function testShantong()
+    {
+        $provider = $this->getProvider('shantong');
+        $resp = $provider->balance();
+    }
 }