xiaoyu před 3 roky
rodič
revize
53a80a8757

+ 46 - 0
helper/refill/api/xyz/pushang/RefillCallBack.php

@@ -0,0 +1,46 @@
+<?php
+namespace refill\pushang;
+
+require_once(BASE_HELPER_RAPI_PATH . '/pushang/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 = $params['extOrderId'] . $params['orderId'] . $params['state'] . config::KEY;
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['state']);
+        $order_sn = $params['extOrderId'];
+        $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 === 4) {
+            $data['ch_trade_no'] = strtolower($params['orderId']) == 'null' ? '' : $params['orderId'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 5) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 124 - 0
helper/refill/api/xyz/pushang/RefillPhone.php

@@ -0,0 +1,124 @@
+<?php
+
+namespace refill\pushang;
+
+require_once(BASE_HELPER_RAPI_PATH . '/pushang/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, int $card_type, string $order_sn, int $amount)
+    {
+        $params['merchantId'] = config::MCH_ID;
+        $params['amt'] = $amount;
+        $params['phone'] = $card_no;
+        $params['extOrderId'] = $order_sn;
+        $params['operator'] = config::operator[$card_type];
+        $params['notifyUrl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $params['order_sn'], $amount);
+
+        $sign = $this->sign($params);
+        $params['md5'] = $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'] == 0) {
+                return [true, '', false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['merchantId'] = config::MCH_ID;
+        $params['extOrderId'] = $refill_info['order_sn'];
+
+        $content = $params['extOrderId'] . $params['merchantId'] . config::KEY;
+        $params['sign'] = md5($content);
+
+        $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'] == 0)
+            {
+                $status = intval($resp['data']);
+                if ($status === 4) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 5) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['msg']];
+                }
+
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['merchantId'] = config::MCH_ID;
+
+        $content = $params['merchantId'] . config::KEY;
+        $params['sign'] = md5($content);
+
+        $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 ($resp['code'] == 0) {
+                return [true, $resp['ext']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = $params['amt'] . $params['extOrderId'] . $params['merchantId'] . $params['notifyUrl'] . $params['phone'];
+        $content .= config::KEY;
+        return md5($content);
+    }
+}

+ 19 - 0
helper/refill/api/xyz/pushang/config.php

@@ -0,0 +1,19 @@
+<?php
+namespace refill\pushang;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://121.43.128.122:8080/api/jyk/makeOrder';
+    const QUERY_URL = 'http://121.43.128.122:8080/api/queryOrder';
+    const BALANCE_URL = 'http://121.43.128.122:8080/api/queryOrder';
+
+    const MCH_ID = 'M00107';
+    const KEY = 'n42TtiQDUsKfKwsUJiRmN5oNey4YXSqH';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_pushang.php";
+    const operator = [
+        mtopcard\ChinaMobileCard => '移动',
+        mtopcard\ChinaUnicomCard => '联通',
+        mtopcard\ChinaTelecomCard => '电信'
+    ];
+}

+ 9 - 0
helper/refill/api/xyz/pushang/对接文档.txt

@@ -0,0 +1,9 @@
+接口文档地址 http://121.43.128.122:8080/doc/api.html
+http://121.43.128.122:8080
+
+商户号:M00107
+密钥:n42TtiQDUsKfKwsUJiRmN5oNey4YXSqH
+
+客户后台:http://218.244.159.217:7777
+商户号:M00107
+密码:123456