# 获取模板中的关键词

调试工具

接口应在服务器端调用,不可在前端(小程序、网页、APP等)直接调用,具体可参考接口调用指南

接口英文名:getpubnewtemplatekeywords

该接口用于获取模板标题下的关键词列表。

# 1. 调用方式

# HTTPS 调用

GET https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=ACCESS_TOKEN&tid=TID

# 云调用

  • 调用方法:subscribeMessage.getPubTemplateKeyWordsById

  • 出入参和 HTTPS 调用相同,调用方式可查看 云调用 说明文档

# 第三方调用

  • 本接口支持第三方平台代商家调用。

  • 该接口所属的权限集 id 为:18、89

  • 服务商获得其中之一权限集授权后,可通过使用 authorizer_access_token 代商家进行调用,具体可查看 第三方调用 说明文档。

# 2. 请求参数

# 查询参数 Query String parameters

参数名类型必填说明
access_tokenstring接口调用凭证,可使用 access_tokenauthorizer_access_token
tidstring模板标题 id,可通过接口获取

# 请求体 Request Payload

# 3. 返回参数

# 返回体 Response Payload

参数名类型说明
errcodenumber错误码
errmsgstring错误信息
countnumber模版标题列表总数
dataobjarray关键词列表

# Res.data(Array) Object Payload

关键词列表

参数名类型说明
kidnumber关键词 id,选用模板时需要
namestring关键词内容
examplestring关键词内容对应的示例
rulestring参数类型

# 4. 注意事项

本接口无特殊注意事项

# 5. 代码示例

# 5.1 HTTPS请求示例

请求示例

https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=ACCESS_TOKEN&tid=99

返回示例

{
  "errcode": 0,
  "errmsg": "ok",
  "data": [
    {
      "kid": 1,
      "name": "物品名称",
      "example": "名称",
      "rule": "thing"
    }
  ]
}

# 5.2 云函数调用示例

请求示例

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

返回示例

{
  "errCode": 0,
  "errMsg": "openapi.subscribeMessage.getPubTemplateKeyWordsById:ok",
  "data": [
    {
      "kid": 1,
      "name": "物品名称",
      "example": "名称",
      "rule": "thing"
    }
  ]
}

# 6. 错误码

以下是本接口的错误码列表,其他错误码可参考 通用错误码

错误码错误描述解决方案
20001系统错误
40001invalid credential  access_token isinvalid or not latest获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口
200002入参错误
200014模板 tid 参数错误

# 7. 适用范围

本接口在不同账号类型下的可调用情况:
小程序公众号服务号小游戏
仅认证 仅认证
  • ✔:该账号可调用此接口
  • 仅认证:表示仅允许企业主体已认证账号调用,未认证或不支持认证的账号无法调用
  • 其他未明确声明的账号类型,如无特殊说明,均不可调用此接口;