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

WeChat small program createQRCode


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wxacode.createQRCode

This interface should be called on the server side, as detailed in the Service Side API.
This interface supports cloud calls. Developer tool version required . . . 1.02.1904090 (latest stable download)
wx-server-sdk >= 0.4.0

Get the small program QR code for business scenarios where the number of codes required is small. The small program code generated through this interface is permanently valid and has a limit on the number, see Get QR code.

How to call:

  • HTTPS call
  • Cloud calls

HTTPS call

The request address

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

Request parameters

Property Type The default Required Description
access_token string Is The interface calls the credentials
path string Is The path to the small program page entered by the broom, with a maximum length of 128 bytes, cannot be empty, and for small games, only the query section can be passed in to achieve a parameter effect, such as: incoming "?foo-bar", which can be obtained from the query parameter wx.getLaunchOptionsSync interface to the {foo:"bar"}
width number 430 Whether The width of the QR code in px. Min 280px, max 1280px

Returns a value

Buffer

The returned picture is Buffer

The exception returns

Object

Json

Property Type Description
errcode number Error code
errmsg string The error message

The legal value of errcode

Value Description The lowest version
45029 The sum of the generated yards reaches the maximum number limit

Returns a description of the value

If the call is successful, the picture binary content is returned directly, and if the request fails, the data in JSON format is returned.

Attention

  • The POST parameter needs to be converted to a JSON string and form form submission is not supported.
  • Interfaces can only generate QR codes for published small programs. The development version of the ginseng QR code can be generated when the developer tool is previewed.
  • The total number of codes generated with wxacode.get is limited to 100,000, please call with caution.

Example

Request

{
 "path":"page/index/index",
 "width":430
}

Return

{
 "errcode": 0,
 "errmsg": "ok",
 "contentType": "image/jpeg",
 "buffer": Buffer
}

Cloud calls

Cloud call is the ability provided by the small program Cloud Development to call WeChat open interfaces in cloud functions and need to be used in cloud functions via wx-server-sdk.

The interface method

openapi.wxacode.createQRCode
Permissions for the wxacode.createQRCode API need to be configured in config.json, details

Request parameters

Property Type The default Required Description
path string Is The path to the small program page entered by the broom, with a maximum length of 128 bytes, cannot be empty, and for small games, only the query section can be passed in to achieve a parameter effect, such as: incoming "?foo-bar", which can be obtained from the query parameter wx.getLaunchOptionsSync interface to the {foo:"bar"}
width number 430 Whether The width of the QR code in px. Min 280px, max 1280px

Returns a value

Object

An object that contains binary data and its data type

Property Type Description
contentType String Data Type (MIME Type)
buffer Buffer Data Buffer

Abnormal

Object

Json

Property Type Description
errCode number Error code
errMsg string The error message

The legal value of errCode

Value Description The lowest version

Example

Request

const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.wxacode.createQRCode({
        path: 'page/index/index',
        width: 430
      })
    return result
  } catch (err) {
    return err
  }
}

Return

{
 "errcode": 0,
 "errmsg": "ok",
 "contentType": "image/jpeg",
 "buffer": Buffer
}