Selaa lähdekoodia

cangxin doubi

haru haru 2 vuotta sitten
vanhempi
commit
e1064378ce

+ 66 - 0
helper/refill/api/xyz/cangxin_doubi/RefillCallBack.php

@@ -0,0 +1,66 @@
+<?php
+namespace refill\cangxin_doubi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/cangxin_doubi/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['verifyString']);
+        $sign = $this->sign($input);
+        if ($params['verifyString'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content = $content . "key=" . config::Key;
+        return md5($content);
+    }
+
+    private function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['clientOrderNo'];
+        $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['official_sn'] = strtolower($params['officialOrderNo']) == 'null' ? '' : $params['officialOrderNo'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 3) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 149 - 0
helper/refill/api/xyz/cangxin_doubi/RefillPhone.php

@@ -0,0 +1,149 @@
+<?php
+
+namespace refill\cangxin_doubi;
+
+require_once(BASE_HELPER_RAPI_PATH . '/cangxin_doubi/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillThird
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount, int $card_type, string $order_sn)
+    {
+        $params['clientId'] = config::clientId;
+        $params['clientOrderNo'] = $order_sn;
+        $params['account'] = $phone;
+        $params['skuCode'] = config::PRODUCT[$amount];
+        $params['amount'] = $amount;
+        $params['callbackUrl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    private function getProductAmount($sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProduct(['system_code' => $sys_pcode]);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['refill_amount'];
+        }
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $amount = $this->getProductAmount($params['product_code']);
+        if(empty($amount)) {
+            return [false, '产品未开启', false];
+        }
+        $order_sn = $params['order_sn'];
+        $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
+        if(empty($params['skuCode'])) {
+            return [false, '商品编号错误', false];
+        }
+        $sign = $this->sign($params);
+        $params['verifyString'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false, 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, $resp['data']['sysOrderNo'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['clientId'] = config::clientId;
+        $params['clientOrderNo'] = $refill_info['order_sn'];
+        $params['verifyString'] = $this->sign($params);
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false, 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)
+            {
+                $data = $resp['data'];
+                $status = $data['status'];
+                if ($status === '4') {
+                    $updata['official_sn'] = $data['officialOrderNo'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === '3') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === '0' || $status === '2') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            }
+            elseif ($resp['code'] === -9 && (time() - $refill_info['commit_time'] >= 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['clientId'] = config::clientId;
+        $params['verifyString'] = $this->sign($params);
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, 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['data']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $str = urldecode(http_build_query($params));
+        $str .= '&key=' . config::Key;
+        return md5($str);
+    }
+}

+ 22 - 0
helper/refill/api/xyz/cangxin_doubi/config.php

@@ -0,0 +1,22 @@
+<?php
+
+
+namespace refill\cangxin_doubi;
+
+class config
+{
+    const ORDER_URL = 'http://47.98.184.74:9527/order/submit';
+    const QUERY_URL = 'http://47.98.184.74:9527/order/query';
+    const BALANCE_URL = 'http://47.98.184.74:9527/order/balance';
+
+    const clientId = '10065';
+    const Key = 'K8edcR5gO5OCPkT3E416a3ouqxN106cC';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_cangxin_doubi.php";
+    const PRODUCT = [
+        100 => 5000100,
+        200 => 5000200,
+        300 => 5000300,
+        500 => 5000500,
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+}

+ 8 - 0
helper/refill/api/xyz/cangxin_doubi/开户信息.txt

@@ -0,0 +1,8 @@
+商户号  10065
+K8edcR5gO5OCPkT3E416a3ouqxN106cC
+对接文档https://www.showdoc.com.cn/1720387349860903/8044417869640483
+
+抖音100编码 5000100
+抖音200编码 5000200
+抖音300编码 5000300
+抖音500编码 5000500

+ 4 - 0
mobile/callback/refill_cangxin_doubi.php

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