推广二维码标识

master
tping 3 years ago
parent f3992c963b
commit 390f9f05ba

@ -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'];

@ -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);

@ -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;

@ -1,202 +0,0 @@
<html>
<head>
<title>打开小程序</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script>
window.onerror = e => {
console.error(e)
alert('发生错误' + e)
}
</script>
<!-- weui 样式 -->
<link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css"></link>
<!-- 调试用的移动端 console -->
<!-- <script src="https://cdn.jsdelivr.net/npm/eruda"></script> -->
<!-- <script>eruda.init();</script> -->
<!-- 公众号 JSSDK -->
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<!-- 云开发 Web SDK -->
<script src="https://res.wx.qq.com/open/js/cloudbase/1.1.0/cloud.js"></script>
<script>
function docReady(fn) {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
fn()
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
docReady(async function() {
var ua = navigator.userAgent.toLowerCase()
var isWXWork = ua.match(/wxwork/i) == 'wxwork'
var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
var isMobile = false
var isDesktop = false
if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i)) {
isMobile = true
} else {
isDesktop = true
}
if (isWeixin) {
var containerEl = document.getElementById('wechat-web-container')
containerEl.classList.remove('hidden')
containerEl.classList.add('full', 'wechat-web-container')
var launchBtn = document.getElementById('launch-btn')
launchBtn.addEventListener('ready', function (e) {
console.log('开放标签 ready')
})
launchBtn.addEventListener('launch', function (e) {
console.log('开放标签 success')
})
launchBtn.addEventListener('error', function (e) {
console.log('开放标签 fail', e.detail)
})
wx.config({
// debug: true, // 调试时可开启
appId: 'wxab40e4470236e599', // <!-- replace -->
timestamp: 0, // 必填,填任意数字即可
nonceStr: 'nonceStr', // 必填,填任意非空字符串即可
signature: 'signature', // 必填,填任意非空字符串即可
jsApiList: ['chooseImage'], // 必填,随意一个接口即可
openTagList:['wx-open-launch-weapp'], // 填入打开小程序的开放标签名
})
} else if (isDesktop) {
// 在 pc 上则给提示引导到手机端打开
var containerEl = document.getElementById('desktop-web-container')
containerEl.classList.remove('hidden')
containerEl.classList.add('full', 'desktop-web-container')
} else {
var containerEl = document.getElementById('public-web-container')
containerEl.classList.remove('hidden')
containerEl.classList.add('full', 'public-web-container')
var c = new cloud.Cloud({
// 必填,表示是未登录模式
identityless: true,
// 资源方 AppID
resourceAppid: 'wxab40e4470236e599', // <!-- replace -->
// 资源方环境 ID
resourceEnv: 'tg-6gj0rw634dc8d837', // <!-- replace -->
})
await c.init()
window.c = c
var buttonEl = document.getElementById('public-web-jump-button')
var buttonLoadingEl = document.getElementById('public-web-jump-button-loading')
try {
await openWeapp(() => {
buttonEl.classList.remove('weui-btn_loading')
buttonLoadingEl.classList.add('hidden')
})
} catch (e) {
buttonEl.classList.remove('weui-btn_loading')
buttonLoadingEl.classList.add('hidden')
throw e
}
}
})
async function openWeapp(onBeforeJump) {
var c = window.c
const res = await c.callFunction({
name: 'public',
data: {
action: 'getUrlScheme',
},
})
console.warn(res)
if (onBeforeJump) {
onBeforeJump()
}
location.href = res.result.openlink
}
</script>
<style>
.hidden {
display: none;
}
.full {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.public-web-container {
display: flex;
flex-direction: column;
align-items: center;
}
.public-web-container p {
position: absolute;
top: 40%;
}
.public-web-container a {
position: absolute;
bottom: 40%;
}
.wechat-web-container {
display: flex;
flex-direction: column;
align-items: center;
}
.wechat-web-container p {
position: absolute;
top: 40%;
}
.wechat-web-container wx-open-launch-weapp {
position: absolute;
bottom: 40%;
left: 0;
right: 0;
display: flex;
flex-direction: column;
align-items: center;
}
.desktop-web-container {
display: flex;
flex-direction: column;
align-items: center;
}
.desktop-web-container p {
position: absolute;
top: 40%;
}
</style>
</head>
<body>
<div class="page full">
<div id="public-web-container" class="hidden">
<p class="">正在打开 “填入你的小程序名称”...</p> <!-- replace -->
<a id="public-web-jump-button" href="javascript:" class="weui-btn weui-btn_primary weui-btn_loading" onclick="openWeapp()">
<span id="public-web-jump-button-loading" class="weui-primary-loading weui-primary-loading_transparent"><i class="weui-primary-loading__dot"></i></span>
打开小程序
</a>
</div>
<div id="wechat-web-container" class="hidden">
<p class="">点击以下按钮打开 “填入你的小程序名称”</p> <!-- replace -->
<!-- 跳转小程序的开放标签。文档 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html -->
<wx-open-launch-weapp id="launch-btn" username="gh_0d9d0461048c" path="\pages\index"> <!-- replace -->
<template>
<button style="width: 200px; height: 45px; text-align: center; font-size: 17px; display: block; margin: 0 auto; padding: 8px 24px; border: none; border-radius: 4px; background-color: #07c160; color:#fff;">打开小程序</button>
</template>
</wx-open-launch-weapp>
</div>
<div id="desktop-web-container" class="hidden">
<p class="">请在手机打开网页链接</p>
</div>
</div>
</body>
</html>
Loading…
Cancel
Save