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

WeChat program get


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wxacode.get

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 small program codes for business scenarios where fewer codes are required. 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/wxa/getwxacode?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
auto_color boolean false Whether 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} Whether auto_color is false, use rgb to set colors such as {"r":"xxx","g":"xxx","b":"xxx"} for a hex
is_hyaline boolean false Whether Whether a transparent base color is required, a small program code for a transparent base color is generated when true

return value

Buffer

Returns Picture Buffer

Abnormal return

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 total number of codes generated with wxacode.createQRCode 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.get
Permissions for the wxacode.get 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
autoColor boolean false Whether Line color is automatically configured, and if the color is still black, the main tone is not recommended
lineColor Object {"r":0,"g":0,"b":0} Whether auto_color is false, use rgb to set colors such as {"r":"xxx","g":"xxx","b":"xxx"} for a hex
isHyaline boolean false Whether Whether a transparent base color is required, a small program code for a transparent base color is generated when true

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

Return

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