微信中进入定页面的,判断时通过扫二维码进入的,还是点小程序名称进入的
onLoad(options) { //options.scene="priceid%3D3%26pricenumber%3D4013ce57"; if(!options || !options.scene){ //options.scene是在后台生成二维码的时候添加的,一定不能为空, console.log('请通过扫码进入'); return; } let that=this; this.setData({qrscene: decodeURIComponent(options.scene ? options.scene : '')}); }, onShow:function(){ if(!this.data.qrscene){return;} }
参考:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html
调用的接口:https://api.weixin.qq.com/wxa/getwxacodeunlimit
此方法不能完全解决问题,譬如:

点重新进入小程序,仍然还会 携带 options.scene 中的数据。
建议最好时 二维码弄成动态的,生成二维码的时候scene带上 token,前端获取token传到后端进行校验,一个token对应一个手机号只允许使用一次。
浙公网安备 33010602011771号