微信小程序扫描小程序码获取参数的问题?

小程序 文章 2021-03-31 17:02 820 0 全屏看文

AI助手支持GPT4.0

微信小程序扫描小程序码获取参数的问题?The WeChat applet scans the applet code to get the parameters?

微信小程序扫描小程序码获取参数的问题?

在后端生成小程序码,用到的接口是 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html

首先后台scene这个参数是传了的,要不然不可能生成二维码。

生成之后前台进行扫描,在开发者工具里边扫描获取到的参数是

为什么scene这个参数在路径后边拼接的呢?

就算是拼接的我进行了截取,测试截取没问题,小程序上线之后就直接报 截取的错误, 本人是通过正则匹配来截取的 match

请问怎么解决呢?

In the back-end generation of small code, the interface is used https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html First of all, the background scene parameter is passed, otherwise it is impossible to generate a two-dimensional code. After generation, the foreground is scanned, and the parameters obtained by scanning in the developer tool are why the scene parameter is spliced behind the path? Even if it's spliced, I intercepted it. The test intercepted it no problem. After the small program went online, I directly reported the error of interception. I intercepted it through regular matching. How can I solve the problem?

回答:

11110111001011110111001110111:

线上报什么错?

小宝:我是用正则匹配的   match  
然后线上就报  match /  of undefind
11110111001011110111001110111:你代码可能写得有问题
undefined 是没有match这个方法的
可能你要匹配的字段都没有
PS:
let data = {};
data.path.match(...);  // 这肯定报错
小宝:那为什么开发板不报错呢
小宝:而且开发板正常截取也没事
微盟:

scene >> 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)

你最好把scene编码一下,encodeURIComponent,接受到的时候decodeURIComponent解一下就行。


小宝:这个限制15位    主要的问题是  都没有这个scene这个参数。  这个参数拼接到了路径后边, 上线之后就报截取的错误了   开发版不报
solin:

不用那么麻烦。可以通过 wx.getEnterOptionsSync 和wx.getLaunchOptionsSync 返回的query拿到这个参数

小宝:前端调起扫一扫之后,扫描小程序码, 前端需要获取scene这个参数,但是没有这个参数,拼接到了路径后边  ,截取开发没事  线上就报错了

-EOF-

AI助手支持GPT4.0