# wxacode.get

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 Mini Program QR code in scenarios where a small number of codes are required. Mini Program codes generated via this API are permanently effective, but the quantity is limited. For details, see Obtaining the QR Code.

Calling methods:

# HTTPS Call

# Request Address

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

# Request Parameters

Attribute Type Default Required Description
access_token string Yes Credentials to call API
path string Yes The path to the Mini Program page to be entered after QR code is scanned. Its value cannot be empty and contains a maximum of 128 bytes. For a Mini Game, you may pass in only the query part. For example, after ?foo=bar is passed in, you can obtain {foo:"bar"} from the query parameter via the wx.getLaunchOptionsSync API.
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.
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 code.

# 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
45029 The total number of generated codes has reached the upper limit.

# 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 maximum number of codes generated via wxacode.createQRCode and this API is 100,000, so be cautious when using this API.

# Example

Request

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

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.get

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

# Request Parameters

Attribute Type Default Required Description
path string Yes The path to the Mini Program page to be entered after QR code is scanned. Its value cannot be empty and contains a maximum of 128 bytes. For a Mini Game, you may pass in only the query part. For example, after ?foo=bar is passed in, you can obtain {foo:"bar"} from the query parameter via the wx.getLaunchOptionsSync API.
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.
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 code.

# 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.get({
        path: 'page/index/index',
        width: 430
      })
      console.log(result)
      return result
    } catch (err) {
      console.log(err)
      return err
    }
  }

Response

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