Background debug getWXACodeUnlimit how to obtain the value of the front end, directly with how wx.scanCode value, the simulator simulates how traditional values getWXACodeUnlimit

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qq_34672907/article/details/89337717

Because before doing applet parameters are entered with sesame small program to do two-dimensional code, you can direct mass participation, the project is now the boss said to call back to the front getWXACodeUnlimit generate two-dimensional code values. Then do yourself these three questions for a long time (of course, there Baidu), and some are fundamentally less than the A point, some only the first part, so I am here to write a bar, the whole process needs to be scanned codes are written.

The difference: There sence = this parameter. The value is slightly different.

1. Said first background debug getWXACodeUnlimit generate two-dimensional code, the user clicks sweep the micro-channel into

onLoad: function (options) { 
        if (this.getUrlParam("cabinet_id", decodeURIComponent(options.scene))) {//扫码进来带参数
            this.setData({ cabinet_id: this.getUrlParam("cabinet_id", decodeURIComponent(options.scene)) });//将id赋值给data里面的变量
        }  
    },
// 获取扫码后的字符串,因为考虑有多个参数,所以写了一个公共函数
    getUrlParam(name, str) {
        let regs = new RegExp("scene=", "g"); //场景值
        str = str.replace(regs, ""); 
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var array = str.match(reg);
        if (array != null)
            return array[2];
    },

The key point is to get the first parameter decodeURIComponent

Click sweep the 2. After entering small program to generate two-dimensional code sweep getWXACodeUnlimit

wx.scanCode({
                success:(res)=> {
                    let str = decodeURIComponent(res.path ? res.path.substr(res.path.indexOf("?") + 1, res.path.length - 1) : "");
                    if (this.getUrlParam("cabinet_id", str)) {
                        this.setData({ "cabinet_id": this.getUrlParam("cabinet_id", str) });
                    }else{
                        wx.showModal({
                            title: '提示',
                            content: '没有找到相关设备,请找相关人员确认是否为有效二维码',
                            confirmText: "确定",
                            showCancel: false,
                            success: (res) => {if (res.confirm) {}}
                        })
                    }  
                }
            })

The key point is to get the scan code parameter is not a result, the parameters in the path inside the small program documents estimate is not updated it, I hope you do not fall this pit. path can decodeURIComponent turn may not be transferred, because the phone automatically decode the end, but the applet development tool is still needed

3. Small program editor simulate two-dimensional code parameter passing getWXACodeUnlimit generated, according to a small program documentation needs encodeURLComponent say it, then I silly scene = encodeURLComponent (cabinet_id = 10001), we do not commit my fault, is such scene = cabinet_id% 3D10001

I forgot to say, to simulate clicks compilation, select Custom compile condition. As shown below:

Well, the notes will do this, nice!

Guess you like

Origin blog.csdn.net/qq_34672907/article/details/89337717