Browse Source

wantong provider add

ayHaru 4 years ago
parent
commit
8e25b50a98

+ 54 - 0
helper/refill/api/xyz/wantong/RefillCallBack.php

@@ -0,0 +1,54 @@
+<?php
+
+
+namespace refill\wantong;
+
+require_once(BASE_HELPER_RAPI_PATH . '/wantong/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['order_id'] . $params['out_order_id'] . config::MCHID . $params['tel'] . $params['price'];
+        $content .= $params['status'] . config::KEY;
+        return md5($content);
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['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'];
+        
+        $data['official_sn'] = strtolower($params['out_order_id']) == 'null' ? '' : $params['out_order_id'];
+
+        if ($status === 1) {
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 0) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 112 - 0
helper/refill/api/xyz/wantong/RefillPhone.php

@@ -0,0 +1,112 @@
+<?php
+
+namespace refill\wantong;
+
+require_once(BASE_HELPER_RAPI_PATH . '/wantong/config.php');
+
+use refill;
+use Log;
+use mtopcard;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount, string $order_sn)
+    {
+        $params['mchid'] = config::MCHID;
+        $params['tel'] = $phone;
+        $params['orderid'] = $order_sn;
+        $params['price'] = $amount;
+        $params['teltype'] = $this->phone_type($phone);
+        $params['timeout'] = 300;
+        $params['notify'] = config::NOTIFY_URL;
+        $params['time'] = time();
+        $params['rand'] = rand(100000, 999999);
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params)
+    {
+        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false);
+        if ($resp === false) {
+            return [false, '系统错误', true];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp == false) {
+                return [false, '系统错误', true];
+            }
+            if ($resp['code'] == 0) {
+                return [true, $resp['order_id'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['orderid'] = $refill_info['order_sn'];
+        $params['mchid'] = config::MCHID;
+
+        $content = $params['mchid'] . $params['orderid'] . config::KEY;
+        $params['sign'] = md5($content);
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp['code'] == 100) {
+                $status = $resp['status'];
+                if ($status == 3) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $updata['official_sn'] = $resp['out_order_id'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                } elseif ($status == 4) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($status, [1, 2])) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    $order_state = -1;
+                }
+                if ($order_state == -1) {
+                    return [false, $resp['data']];
+                }
+                return [true, $order_state];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content = $params['mchid'] . $params['tel'] . $params['price'] . $params['orderid'] . $params['teltype'] . $params['timeout'] . $params['notify'];
+        $content .= $params['time'] . $params['rand'] . $key;
+        return md5($content);
+    }
+
+    private function phone_type($phone)
+    {
+        $card_type = mtopcard\card_type($phone);
+
+        if ($card_type == mtopcard\ChinaMobileCard) {
+            return 0;
+        } elseif ($card_type == mtopcard\ChinaUnicomCard) {
+            return 1;
+        } elseif ($card_type == mtopcard\ChinaTelecomCard) {
+            return 2;
+        }
+    }
+}

+ 6 - 0
helper/refill/api/xyz/wantong/api.txt

@@ -0,0 +1,6 @@
+http://mm.jm618.cn/account/profile
+商户id  10016
+密码123456
+
+话费充值接口文档
+http://mm.jm618.cn/static/download/api1.pdf

+ 16 - 0
helper/refill/api/xyz/wantong/config.php

@@ -0,0 +1,16 @@
+<?php
+
+
+namespace refill\wantong;
+
+
+class config
+{
+    const ORDER_URL = 'https://mm.jm618.cn/api/telpay';
+    const QUERY_URL = 'https://mm.jm618.cn/api/telpay/query';
+
+    const MCHID = 10016;
+    const KEY = '06be014a9c14b12d893663bff36372ba';
+//    const NOTIFY_URL = BASE_SITE_URL . "/mobile/refill_wantong.php";
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+}