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

WeChat gadgets Subscribe to message getCategory


May 20, 2021 WeChat Mini Program Development Document


Table of contents


subscribeMessage.getCategory

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 class of the small program account number

How to call:

  • HTTPS call
  • Cloud calls

HTTPS call

The request address

GET https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token=ACCESS_TOKEN

Request parameters

Property Type The default Required Description
access_token string Is The interface calls the credentials

The returned JSON packet

Property Type Description
errcode number Error code
errmsg string The error message
data Array.<Object> The list of classes

The structure of the data

Property Type Description
Id number Class id, required when querying public library templates
name string The name of Chinese purpose

An example response

{
   "errcode": 0,
   "errmsg": "ok",
   "data": [
       {
           "id": 616,
           "name": "公交"
       }
   ]
}

Cloud calls

Cloud calling is the ability provided by the small program Cloud Development to invoke WeChat's open interface in cloud functions and needs to be used in cloud functions via wx-server-sdk.

The interface method

openapi.subscribeMessage.getCategory
Permissions for the subscribeMessage.getCategory API need to be configured in config.json, details

An example of a request

const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.subscribeMessage.getCategory({})
    return result
  } catch (err) {
    return err
  }
}

An example response

const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.subscribeMessage.getCategory({
        errcode: 0,
        errmsg: 'ok',
        data: [
          {
            id: 616,
            name: '公交'
          }
        ]
      })
    return result
  } catch (err) {
    return err
  }
}