Browse Source

chuangyu_qdw

xiaoyu 2 years ago
parent
commit
c555387e04

+ 29 - 0
helper/refill/api/xyz/chuangyu_qdw/API信息.txt

@@ -0,0 +1,29 @@
+https://docs.qq.com/doc/DWXBtRkJyQXFCbkJj
+
+商户后台地址 : http://120.55.55.137:8080/merchant/main
+登陆账号 : quyou
+登陆密码 : 123456
+mch_id:1007
+secret_key:2f8b622f4bcee63fecc4020178f30994
+直冲下单地址:http://120.55.55.137:8080/api/charge
+卡密下单地址:http://120.55.55.137:8080/api/card
+订单查询地址:http://120.55.55.137:8080/api/query
+余额查询地址:http://120.55.55.137:8080/api/balance
+
+
+10003	移动50
+10004	移动100
+10005	移动200
+10006	移动300
+10007	移动500
+
+10011	联通50
+10012	联通100
+10013	联通200
+10014	联通300
+
+10019	电信50
+10020	电信100
+10021	电信200
+10022	电信300
+10023	电信500

+ 42 - 0
helper/refill/api/xyz/chuangyu_qdw/RefillCallBack.php

@@ -0,0 +1,42 @@
+<?php
+namespace refill\chuangyu_qdw;
+
+require_once(BASE_HELPER_RAPI_PATH . '/chuangyu_qdw/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['signature']);
+        $sign = config::sign($input);
+        if ($params['signature'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function notify($params)
+    {
+        $status = $params['order_status'];
+        $order_sn = $params['customer_order_no'];
+        $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 === 'success') {
+            $official_sn = strtolower($params['serial_number']) == 'null' ? '' : $params['serial_number'];
+            $data['official_sn'] = $official_sn;
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true, $official_sn];
+        } elseif ($status === 'fail') {
+            return [$order_id, false, true, true, ''];
+        } else {
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 129 - 0
helper/refill/api/xyz/chuangyu_qdw/RefillPhone.php

@@ -0,0 +1,129 @@
+<?php
+
+namespace refill\chuangyu_qdw;
+
+require_once(BASE_HELPER_RAPI_PATH . '/chuangyu_qdw/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, int $card_type, string $order_sn)
+    {
+        $params['mch_id'] = config::MCH_ID;
+        $params['timestamp'] = date("Y-m-d H:i:s");
+        $params['account'] = $phone;
+        $params['account_type'] = 1;
+        $params['product_id'] = config::ProductIdS[$card_type][$amount];
+        $params['customer_order_no'] = $order_sn;
+        $params['notify_url'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $amount, $card_type, $params['order_sn']);
+        $sign = config::sign($params);
+        $params['signature'] = $sign;
+
+        $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);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === 200) {
+                return [true, '', false];
+            } elseif (in_array($resp['code'], ['1004', '5000'], true)) {
+                $net_errno = "HTTP-{$resp['code']}";
+                return [false, $resp['msg'], true];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mch_id'] = config::MCH_ID;
+        $params['timestamp'] = date("Y-m-d H:i:s");
+        $params['customer_order_no'] = $refill_info['order_sn'];
+        $sign = config::sign($params);
+        $params['signature'] = $sign;
+
+        $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'] === 200)
+            {
+                $offical_sn = '';
+                $status = $resp['result']['order_status'];
+                if ($status === 'success') {
+                    $offical_sn = $resp['result']['serial_number'];
+                    $updata['official_sn'] = $offical_sn;
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 'fail') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 'recharging') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status, $offical_sn];
+                }
+                return [true, $order_state, $offical_sn];
+            }
+            else {
+                return [false, $resp['msg'], ''];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['mch_id'] = config::MCH_ID;
+        $params['timestamp'] = date("Y-m-d H:i:s");
+        $sign = config::sign($params);
+        $params['signature'] = $sign;
+
+        $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'] === 200) {
+                return [true, $resp['result']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+}

+ 68 - 0
helper/refill/api/xyz/chuangyu_qdw/config.php

@@ -0,0 +1,68 @@
+<?php
+namespace refill\chuangyu_qdw;
+
+use mtopcard;
+class config
+{
+    //回调地址需在商户后台配置
+    const ORDER_URL = 'http://120.55.55.137:8080/api/charge';
+    const QUERY_URL = 'http://120.55.55.137:8080/api/query';
+    const BALANCE_URL = 'http://120.55.55.137:8080/api/balance';
+
+    const MCH_ID = '1007';
+    const SECRET_KEY = '2f8b622f4bcee63fecc4020178f30994';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_chuangyu_qdw.php";
+
+    const ExtHeaders = ['Content-Type: application/json'];
+
+    const ProductIdS = [
+        mtopcard\ChinaMobileCard =>
+            [
+                50  => '10003',
+                100 => '10004',
+                200 => '10005',
+                300 => '10006',
+                500 => '10007',
+            ],
+        mtopcard\ChinaUnicomCard =>
+            [
+                50  => '10011',
+                100 => '10012',
+                200 => '10013',
+                300 => '10014',
+            ],
+        mtopcard\ChinaTelecomCard =>
+            [
+                50  => '10019',
+                100 => '10020',
+                200 => '10021',
+                300 => '10022',
+                500 => '10023',
+            ],
+    ];
+
+    public static function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if(self::check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content .= 'secret_key=' . config::SECRET_KEY;
+        return md5(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;
+    }
+}

+ 7 - 0
mobile/callback/refill_chuangyu_qdw.php

@@ -0,0 +1,7 @@
+<?php
+
+$content = $_SERVER['post_content'];
+$input = json_decode($content,true) ?? [];
+refill\util::push_notify('chuangyu_qdw',$input);
+
+echo 'success';