Wechat mini program to generate two-dimensional code step pit
First, the writing time is September 24, 2019, valid at this time
- Because from the view of wechat open community, now (201909) small program chrysanthemum code is no experience version, so the chrysanthemum code generated by generating small program code is online environment, so when testing the mobile phone to identify this TWO-DIMENSIONAL code into the online small program, it is not convenient to test; Now we know the indirect test method, but ultimately need to go directly to the online environment test:
- Development tools, compilation mode selection through two-dimensional code compilation to test the generated chrysanthemum code
- Development tools, add compile mode, add parameters to debug, note that some interface parameters need
encodeURIComponent
- Development tools, add compilation mode, through the preview or real machine debugging generated with time limit two-dimensional code, scan the two-dimensional code for testing
-
In the background management page of wechat public platform, on the upper right, tools > Generate applets can generate applets in the specified path, but the current version seems to have a hole with parameters, refer to the applets background “generate applets” how to take parameters
-
Generate the TWO-DIMENSIONAL code with specified parameters through the grass two-dimensional code, sesame two-dimensional code, but these third-party applications need authorization or small program secret key;
-
Small program TWO-DIMENSIONAL code back end and front end can generate, I here is the front generation method to generate small program code, the following content is the first method to generate two-dimensional code some introduction;
Second, the use ofGenerate small program codeInterface Preparation
-
According to the document, there are three interfaces to generate two-dimensional code, do not copy the document, each interface can be through HTTPS call and cloud call to obtain small program code, I introduce is through HTTPS call;
-
All of the above methods require the access_token parameter to make a background request. For example:
Request the address
POST
https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN
- generate
access_token
access_token
It’s changing, so it needs to go throughInterface invokes the credential interfaceTo obtain, this interface request is required for two key parametersAppId
andAppSecret
- To obtain
AppId
andAppSecret
AppId
In the small program management background can be seen, andAppSecret
Is hidden and cannot be reset easily, resetting will cause the original background to use thisAppSecret
All need to be changed, andAppSecret
General background code will be written, so you can find the background colleagues to;
- To obtain
AppId
andAppSecret
After the parameter is written through the front-end code in the HTTP request orpostMan
Such tools, request the following address, to obtainWith agingtheAppSecret
Request the address
GET
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
Third, toGets the small program codeInterface call considerations
- Because the generated TWO-DIMENSIONAL code is permanent effective, the main difference is the request interface generated two-dimensional code number is limited, but if only need to generate a small amount of two-dimensional code, used in other scenarios to scan two-dimensional code into the small program, three kinds of interface can;
- Different interfaces call many pits of –.
- The second method suggests referring to JS generate small program a page TWO-DIMENSIONAL code (generate small program two-dimensional code), pro test available (so post the article, later have time to arrange again ==). ;
- The second method is to place the parameters in
scene
So get this parameter, which is recognized when onloadoptions.scene
; - Generated by the above link method, in the network of the small program
preview
You can view the QR code, or transfer the picture information tobase64
Format after inimg
Add a reference to the tag;
success(res) {
console.log(res)
let src = wx.arrayBufferToBase64(res.data); // Convert the data
}
Copy the code
<img src="data:image/png; base64,{{src}}"/>
Copy the code
In the above way, in the web page or small program to generate available download copy of the TWO-DIMENSIONAL code picture;