# wxacode.getUnlimited

Call this API at the server side. For more information, see Server API.

This API supports Cloud Calls. The WeChat DevTools version must be 1.02.1904090 or later (download the latest stable version here), and the wx-server-sdk version must be 0.4.0 or later.

Obtains the Mini Program code in scenarios where a large number of codes are required. Mini Program codes generated via this API are permanently effective. There is no upper limit on the number of codes. For more information on how to use it, see Obtaining QR Codes.

Calling methods:

# HTTPS Call

# Request Address

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

# Request Parameters

Attribute Type Default Required Description
access_token string Yes Credentials to call API
scene string Yes A maximum of 32 visible characters including numbers, uppercase and lowercase English letters, and some special characters !#$&'()*+,/:;=?@-._~ are supported. Other characters need to be encoded as valid characters. (Because % is not supported, Chinese characters cannot be processed via urlencode, so you must use other encoding schemes instead.)
page string Homepage No This must be an existing page of a published Mini Program (otherwise, an error is reported), for example, pages/index/index. Do not prefix a root path with /. This field cannot contain parameters (parameters can be contained in the scene field). If this field is left empty, the user is redirected to the homepage by default.
width number 430 No The width of the QR code (in px). The minimum value is 280 px and the maximum value is 1280 px.
auto_color boolean false No The automatically configured line color. If the color is still black, it indicates that the setting of the dominant tone is not recommended. Its value is "false" by default.
line_color Object {"r":0,"g":0,"b":0} No It takes effect when auto_color is "false". The color is specified via RGB, for example, {"r":"xxx","g":"xxx","b":"xxx"}, and indicated by a decimal value.
is_hyaline boolean false No Specifies whether a transparent background is required. "true" indicates a transparent background is generated for the Mini Program.

# Return Value

# Buffer

An image buffer is returned.

# Exception Response

# Object

JSON

Property Type Description
errcode number Error code
errmsg string Error message

Valid values of errcode

Value Description Minimum Version
45009 The number of calls to this API per minute is limited to 5000, which will be adjusted. If a large number of Mini Program codes are required, pre-generation is recommended.
41030 The page does not exist, or the Mini Program is not published.

# Return Values

If the call is successful, binary content of the image is directly returned; if the call failed, data in the JSON format is returned.

# Notes

  • POST parameters need to be converted into JSON strings, and cannot be submitted in forms.
  • This API can only be used to generate the QR codes of published Mini Programs.
  • The number of calls to this API per minute is limited to 5000. If a large number of Mini Program codes are required, pre-generation is recommended.

# Obtaining Scene Values

The value of the scene field is passed to a Mini Program/Mini Game as a query parameter. After a user scans this code to enter the Mini Program/Mini Game, developers can obtain the scene value from the QR code and then process the logic.

During debugging, developers can simulate the scene by customizing the parameter scene=xxxx via conditional compilation in WeChat DevTools. The encodeURIComponent API needs to be called for the scene value during the simulation.

Mini Program

Page({
  onLoad (query) {
    // scene must use decodeURIComponent to obtain the scene value provided during QR code generation.
    const scene = decodeURIComponent(query.scene)
  }
})

Mini Game

// Obtains the scene value via the `wx.getLaunchOptionsSync` API during initial startup.
const {query} = wx.getLaunchOptionsSync()
const scene = decodeURIComponent(query.scene)

// or obtains the scene value from the wx.onShow event.
wx.onShow(function ({query}) {
  // scene must use decodeURIComponent to obtain the scene value provided during QR code generation.
  const scene = decodeURIComponent(query.scene)
})

# Example

Request

{
 "scene": "a=1"
}

Response

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

# Cloud Call

Cloud call is a capability provided by Mini Program·Cloud Base that allows you to call WeChat APIs in a cloud function. It must be used via wx-server-sdk in the cloud function.

# API Calling Method

openapi.wxacode.getUnlimited

You need to configure the permissions for the wxacode.getUnlimited API via config.json. Details

# Request Parameters

Attribute Type Default Required Description
scene string Yes A maximum of 32 visible characters including numbers, uppercase and lowercase English letters, and some special characters !#$&'()*+,/:;=?@-._~ are supported. Other characters need to be encoded as valid characters. (Because % is not supported, Chinese characters cannot be processed via urlencode, so you must use other encoding schemes instead.)
page string Homepage No This must be an existing page of a published Mini Program (otherwise, an error is reported), for example, pages/index/index. Do not prefix a root path with /. This field cannot contain parameters (parameters can be contained in the scene field). If this field is left empty, the user is redirected to the homepage by default.
width number 430 No The width of the QR code (in px). The minimum value is 280 px and the maximum value is 1280 px.
autoColor boolean false No The automatically configured line color. If the color is still black, it indicates that the setting of the dominant tone is not recommended. Its value is "false" by default.
lineColor Object {"r":0,"g":0,"b":0} No It takes effect when auto_color is "false". The color is specified via RGB, for example, {"r":"xxx","g":"xxx","b":"xxx"}, and indicated by a decimal value.
isHyaline boolean false No Specifies whether a transparent background is required. "true" indicates a transparent background is generated for the Mini Program.

# Return Value

# Object

Returns an object containing binary data and its data type.

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

# Exceptions

# Object

JSON

Property Type Description
errCode number Error code
errMsg string Error message

Valid values of errCode

Value Description Minimum Version

# Example

Request

const cloud = require('wx-server-sdk')
  cloud.init()
  exports.main = async (event, context) => {
    try {
      const result = await cloud.openapi.wxacode.getUnlimited({
        scene: 'a=1'
      })
      console.log(result)
      return result
    } catch (err) {
      console.log(err)
      return err
    }
  }

Response

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