Wechat official document scan common link TWO-DIMENSIONAL code to open small program

At first, after reading the official document, I thought it was set the rule is XXX.xxx.xxx /yyy? Code = 12…

Then I had an Epiphany. I set the qr code rules to XXX.XXX.xxx/YYy? Action =…

You can use any name you like, just remember that the first part of your custom link must be the same as the rule, for example, action=gogogo, and you are free to pass any parameters after the ampersand.

Get parameters in the applet code:

util.js

console.log("url = "+url) console.log("name = " + name) var reg = new RegExp('(^|&|/?) ' + name + '=([^&|/?] (*) & | /? |$)', 'i') var r = url.substr(1).match(reg) if (r ! = null) { console.log("r = " + r) console.log("r[2] = " + r[2]) return r[2] } return null; } module.exports = { getQueryString: getQueryString, }Copy the code

app.js

App({ onLaunch: Function (options) {console.log(" global onLaunch options==" + json.stringify (options)) let q = DecodeURIComponent (options.query.q) if (q){console.log(" global onLaunch onload URL =" + q) console.log(" global onLaunch onload parameters flag=" + utils.getQueryString(q, 'flag')) } } })Copy the code

Obtain qr code parameters on the page

/ * * * * / data page of the initial data: {}, function / * * * life cycle - listening page load * / onLoad: Function (options) {console.log("index life cycle onload"+ json.stringify (options) DecodeURIComponent (options.q) if(q){console.log("index life cycle onload URL =" + q) console.log("index life cycle onload parameter flag=" + utils.getQueryString(q, 'flag')) } } })Copy the code