Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API to get small program page QR code


May 19, 2021 WeChat Mini Program Development Document


Table of contents


Get the QR code


Through the background interface, you can get the QR code of any page of the small program, scan the QR code can go directly to the page corresponding to the small program. At present, WeChat supports two types of QR code, small program code (left), small program QR code (right), as follows:

WeChat small program API to get small program page QR code

You can use the development tool 1.02.1803130 and later versions of the two-dimensional code compilation function debugging obtained by the QR code

WeChat small program API to get small program page QR code

Get the small program code

We recommend generating and using a small program code that has better recognition. Currently, there are two interfaces that can generate small program codes, and developers can choose the right interface for their needs.

Interface A: For business scenarios where fewer codes are required

Interface address:

https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN

Get access_token the documentation

POST parameter description

Parameters Type The default Description
path String Cannot be empty, maximum length 128 bytes
width Int 430 The width of the QR code
auto_color Bool false Line color is automatically configured, and if the color is still black, the main tone is not recommended
line_color Object {"r":"0","g":"0","b":"0"} auth_color is false, use rgb to set colors such as "r": "xxx", "g":xxx", "b":xxx"

Note: The small program code generated through this interface is permanently valid, and the quantity limit is indicated at the end of the article, please use it with caution. After the user scans the code and enters the program, they go directly to the page corresponding to path.

Interface B: Applicable to the number of codes, or only temporary service scene

interface address:

https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN

Get access_token See Documentation

POST parameter description

Parameters Type The default Description
scene String Up to 32 visible characters, only numbers, case English and some special characters are supported: Other characters should be encoded as legitimate (because not supported, Chinese cannot be processed using urlencode, please use other encoding methods)
page String Must be a small program page that has already been published, such as "pages/index/index", and if you do not fill in this field, jump the main page by default
width Int 430 The width of the QR code
auto_color Bool false Line color is automatically configured, and if the color is still black, the main tone is not recommended
line_color Object {"r":"0","g":"0","b":"0"} auto_color is false, use rgb to set colors such as "r":xxx,""g":xxx,""b":"xxx"

Note: The small code generated through this interface is permanent and has no limit on the number. A fter the user scans the code into the program, the developer needs to take the value of the scene field in the code obtained by the corresponding page, and then do the processing logic. U se the following code to get the value of the scene field in the QR code. The debugging phase can use the conditions of the development tool to compile the custom parameter scene=xxxx for simulation, and the parameter value of the scene when the development tool simulates requires urlencode

// 这是首页的 js
Page({
  onLoad: function(options) {
    // options 中的 scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
    var scene = decodeURIComponent(options.scene)
  }
})

Get the small program QR code

Interface C: For business scenarios where fewer codes are required

Interface address:

https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN

Get access_token the documentation

POST parameter description

Parameters Type The default Description
path String Cannot be empty, maximum length 128 bytes
width Int 430 The width of the QR code

Note: The small program QR code generated through this interface is permanently valid and the quantity limit is indicated at the end of the article, please use it with caution. After the user scans the code and enters the program, they go directly to the page corresponding to path.

Example:

{"path": "pages/index?query=1", "width": 430}

Note: pages/index needs to app.json pages pages

Bug & Tip

  1. tip This interface allows you to generate only the QR code for published small programs.
  2. tip You can generate a ginseng QR code for the development version when the developer tool is previewed.
  3. tip Interface A plus interface C, the total number of code generated is limited to 100,000, please call carefully.
  4. tip The POST parameter needs to be converted to a json string and form form submission is not supported.
  5. tip Auto_color line_color parameter is only valid for small program codes.

Error code

45009:B interface calls are limited in minute frequency (currently 5000 times per minute, will be adjusted), if a large number of small code, it is recommended to pre-build.

45029: The sum of the number of codes generated by the A and C interfaces reaches the maximum number limit.

41030: B interface pass page does not exist, or the small program is not published, please note that the B interface does not have path parameters, passpath parameters although you can generate small program code, but can only jump the main page.