小程序之普通链接二维码跳转小程序
微信扫普通链接二维码跳转到小程序,这个功能对用户体验非常大,不用手动搜索小程序,然后再打开,然后再扫码。挺方便的
配置的地方
打开小程序-> 开发管理 -> 扫普通链接二维码打开小程序

添加
说明:
1.从2017年5月开始,微信客户端支持二维码规则根据“子路径匹配”。如原有二维码链接为 http://www.qq.com/a/123456 ,其中123456为业务参数,则可配置规则 http://www.qq.com/a/ 实现扫码打开小程序。所以要想带参数。必须要以 / 为结尾,可以带?的参数也可以直接跟参数
2. 域名必须是合法的域名,且根据说明文档要求将文件上传至服务器指定目录下确保可以这样访问https://www.baidu.com/scanCode/Q2rPMnzjxm.txt,才能正常扫码
3. 测试范围,你勾选的开发版本,扫描后跳转到开发版本上,你勾选的体验版,跳转到体验版本上,你勾选的线上版本,跳转的线上版本。其实小程序有三个版本,体验版和开发版右边有黑白色的小字。如下图所示
4.机器调试
小程序开发版本和体验版本可以调出来调试面板,绿色的小正方体就是:vConsole,可以开到日志,方便排查问题
5.扫码后的跳转页面
扫码后的跳转页面配置在,小程序功能页面那里。就是工程里的页面。
二维码内容获取在小程序后台配置二维码跳转小程序规则之后即可使用微信(6.5.6及其以上客户端版本)扫码打开小程序。二维码链接内容会以参数 q 的形式带给页面,在onLoad事件中提取 q 参数并自行 decodeURIComponent 一次(对于小游戏可使用 wx.getEnterOptionsSync 接口获取),即可获取原二维码的完整内容。同时会附加一个参数 scancode_time(UNIX 时间戳,单位秒),表示用户扫码的时间。
onLoad(options) {
let self = this;
console.log(options);
let url = decodeURIComponent(options.q) // 获取到二维码原始链接内容,decodeURIComponent为系统内置函数
console.log(url);
if (url.indexOf('reservation=') > 0) {
let code = url.split('=')[1];
if (code) {
wx.showLoading({
title: '核销中...',
});
let user = wx.getStorageSync('user');
if (!user) {
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
wx.request({
url: config.host + '/api/mp/wx/login?code=' + res.code,
method: 'GET',
success: (response) => {
let res = response.data;
console.log('Login Response:', res);
wx.setStorageSync('config', res.data.config || '');
wx.setStorageSync('user', res.data.user || '');
wx.setStorageSync('token', res.data.token ? res.data.token.token : '');
if (res.data.token) {
self.verifyCode(code);
} else {
wx.hideLoading();
wx.showModal({
title: '',
content: '没有权限',
showCancel: false,
complete() {
console.log('跳转到首页');
wx.redirectTo({
url: '/pages/index/index',
})
},
});
}
},
fail: (err) => {
console.log(err);
wx.showModal({
title: '',
content: '没有权限',
showCancel: false,
complete() {
console.log('跳转到首页');
wx.redirectTo({
url: '/pages/index/index',
})
},
});
}
})
}
})
} else if (user.type != 1) {
wx.showModal({
title: '',
content: '没有权限',
showCancel: false,
complete() {
console.log('跳转到首页');
wx.redirectTo({
url: '/pages/index/index',
})
},
});
}
}
}
},
============ 欢迎各位老板打赏~ ===========
