From 390f9f05bae06911a408de84b5db34c228d4eec7 Mon Sep 17 00:00:00 2001 From: tping Date: Tue, 7 Sep 2021 17:04:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/JumpController.class.php | 19 +- .../QrCodePromotionController.class.php | 27 ++- .../Qrcode/View/default/Jump/jumpMp.html | 5 +- .../View/default/QrCodePromotion/jumpMp.html | 202 ------------------ 4 files changed, 39 insertions(+), 214 deletions(-) delete mode 100644 Application/Qrcode/View/default/QrCodePromotion/jumpMp.html diff --git a/Application/Qrcode/Controller/JumpController.class.php b/Application/Qrcode/Controller/JumpController.class.php index f99022df6..1fef70571 100644 --- a/Application/Qrcode/Controller/JumpController.class.php +++ b/Application/Qrcode/Controller/JumpController.class.php @@ -18,12 +18,12 @@ class JumpController extends HomeController public function getURLScheme() { header('Access-Control-Allow-Origin: *'); - $id = I('request.id', 0); + $uniqueStr = I('request.unique_str', ''); $url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=".$this->getAccessToken(); $data = [ 'jump_wxa' => [ 'path' => '/pages/index/index', - 'query' => "id={$id}" + 'query' => "id={$uniqueStr}" ], 'is_expire' => true, "expire_time" => time() + 86400 @@ -50,8 +50,11 @@ class JumpController extends HomeController } public function jumpMp() { - $id = I('request.id', 0); - $this->assign("id", $id); + $uniqueStr = I('server.QUERY_STRING'); + $posStr = 'Qrcode/Jump/jumpMp/'; + $pos = strpos($uniqueStr, $posStr) + strlen($posStr); + $uniqueStr = substr($uniqueStr, $pos, 8); + $this->assign("unique_str", $uniqueStr); $this->display(); } @@ -59,10 +62,10 @@ class JumpController extends HomeController public function getImgs() { $isHttps = is_https(); - $backgroundImg = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/Public/Qrcode/images/b.png"; + $backgroundImg = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/Public/Qrcode/images/b1.png"; $qrCodeImg = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/Public/Qrcode/images/qrcode.png"; - $id = I('request.id', 0); - if (!$id || !is_numeric($id)) { + $id = I('request.id', ''); + if (!$id) { $this->ajaxReturn([ 'id' => $_REQUEST['id'], 'status' => 1, @@ -71,7 +74,7 @@ class JumpController extends HomeController ]); } // 二维码: - $qrcodePromotionList = M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->find(); + $qrcodePromotionList = M('qrcode_promotion_list', 'tab_')->where(['unique_str' => $id])->find(); $qrcode = json_decode($qrcodePromotionList['qrcode_img'], true); $qrcodeCnt = count($qrcode); $intervalMin = $qrcodePromotionList['interval_min']; diff --git a/Application/Qrcode/Controller/QrCodePromotionController.class.php b/Application/Qrcode/Controller/QrCodePromotionController.class.php index db07d80e4..6b853011d 100644 --- a/Application/Qrcode/Controller/QrCodePromotionController.class.php +++ b/Application/Qrcode/Controller/QrCodePromotionController.class.php @@ -202,8 +202,9 @@ class QrCodePromotionController extends BaseController 'interval_min' => $params['interval_min'], ]); if ($id > 0) { - $h5Link = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/index.php?s=/Qrcode/Jump/jumpMp/id/{$id}"; - $expireDate = date('Y-m-d', strtotime("+30 day")); + $uniqueStr = $this->getUniqueStr(); + $h5Link = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/index.php?s=/Qrcode/Jump/jumpMp/{$uniqueStr}"; + $expireDate = date('Y-m-d', strtotime("+90 day")); $shortLink = $this->getShortUrl($h5Link, $expireDate); M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->save([ @@ -220,6 +221,28 @@ class QrCodePromotionController extends BaseController $this->display(); } + private function getUniqueStr() { + while (1) { + $chars = $this->getRandomStr(8); + $find = M('qrcode_promotion_list', 'tab_')->where([ + 'unique_str' => $chars + ])->find(); + if (!$find) return $chars; + } + } + + private function getRandomStr($len){ + static $pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; + + $str = ''; + $max = strlen($pol) - 1; + for ($i = 0; $i < $len; $i++) { + $str .= $pol[mt_rand(0, $max)]; + } + + return $str; + } + public function linkEdit() { $id = I('request.id', 0); diff --git a/Application/Qrcode/View/default/Jump/jumpMp.html b/Application/Qrcode/View/default/Jump/jumpMp.html index c858df213..bf9ab7168 100644 --- a/Application/Qrcode/View/default/Jump/jumpMp.html +++ b/Application/Qrcode/View/default/Jump/jumpMp.html @@ -88,6 +88,7 @@ var buttonEl = document.getElementById('public-web-jump-button') var buttonLoadingEl = document.getElementById('public-web-jump-button-loading') try { + jumpToMp(); await openWeapp(() => { buttonEl.classList.remove('weui-btn_loading') buttonLoadingEl.classList.add('hidden') @@ -120,9 +121,9 @@ dataType: 'json', type: 'POST', //url: 'http://10.0.10.185:8089/index.php?s=/Qrcode/Jump/getURLScheme', - url: 'https://mg.wmtxkj.cn/index.php?s=/Qrcode/Jump/getURLScheme', + url: 'https://mg.wmtxkj.com/index.php?s=/Qrcode/Jump/getURLScheme', data: { - 'id': "{$id}", + 'id': "{$unique_str}", }, success: function(data){ window.location.href = data.openlink; diff --git a/Application/Qrcode/View/default/QrCodePromotion/jumpMp.html b/Application/Qrcode/View/default/QrCodePromotion/jumpMp.html deleted file mode 100644 index f8c6fbb94..000000000 --- a/Application/Qrcode/View/default/QrCodePromotion/jumpMp.html +++ /dev/null @@ -1,202 +0,0 @@ - - - 打开小程序 - - - - - - - - - - - - - - - - -
- - - -
- - \ No newline at end of file