ylbtech-微信-小程序-開發文檔-服務端-模板消息:templateMessage.addTemplate |
1.返回頂部 |
1、
templateMessage.addTemplate
本接口應在服務器端調用,詳細說明參見服務端API。
本接口支持雲調用。需開發者工具版本 >=
1.02.1904090
(最新穩定版下載),wx-server-sdk
>=0.4.0
組合模板並添加至帳號下的個人模板庫
調用方式:
HTTPS 調用
請求地址
POST https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=ACCESS_TOKEN
請求參數
屬性 | 類型 | 默認值 | 必填 | 說明 |
---|---|---|---|---|
access_token | string | 是 | 接口調用憑證 | |
id | string | 是 | 模板標題id,可通過接口獲取,也可登錄小程序后台查看獲取 | |
keyword_id_list | Array.<number> | 是 | 開發者自行組合好的模板關鍵詞列表,關鍵詞順序可以自由搭配(例如[3,5,4]或[4,5,3]),最多支持10個關鍵詞組合 |
返回值
Object
返回的 JSON 數據包
屬性 | 類型 | 說明 |
---|---|---|
errcode | number | 錯誤碼 |
errmsg | string | 錯誤信息 |
template_id | string | 添加至帳號下的模板id,發送小程序模板消息時所需 |
請求數據示例
{ "id":"AT0002", "keyword_id_list":[3,4,5] }
返回數據示例
{ "errcode": 0, "errmsg": "ok", "template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc" }
雲調用
雲調用是小程序·雲開發提供的在雲函數中調用微信開放接口的能力,需要在雲函數中通過
wx-server-sdk
使用。
接口方法
openapi.templateMessage.addTemplate
需在
config.json
中配置templateMessage.addTemplate
API 的權限,詳情
請求參數
屬性 | 類型 | 默認值 | 必填 | 說明 |
---|---|---|---|---|
id | string | 是 | 模板標題id,可通過接口獲取,也可登錄小程序后台查看獲取 | |
keywordIdList | Array.<number> | 是 | 開發者自行組合好的模板關鍵詞列表,關鍵詞順序可以自由搭配(例如[3,5,4]或[4,5,3]),最多支持10個關鍵詞組合 |
返回值
Object
返回的 JSON 數據包
屬性 | 類型 | 說明 |
---|---|---|
errCode | number | 錯誤碼 |
errMsg | string | 錯誤信息 |
templateId | string | 添加至帳號下的模板id,發送小程序模板消息時所需 |
異常
Object
拋出的異常
屬性 | 類型 | 說明 |
---|---|---|
errCode | number | 錯誤碼 |
errMsg | string | 錯誤信息 |
errCode 的合法值
值 | 說明 | 最低版本 |
---|
請求數據示例
const cloud = require('wx-server-sdk') cloud.init() exports.main = async (event, context) => { try { const result = await cloud.openapi.templateMessage.addTemplate({ id: 'AT0002', keywordIdList: [ 3, 4, 5 ] }) console.log(result) return result } catch (err) { console.log(err) return err } }
返回數據示例
{ "errCode": 0, "errMsg": "openapi.templateMessage.addTemplate:ok", "templateId": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc" }
2、
2.返回頂部 |
3.返回頂部 |
4.返回頂部 |
5.返回頂部 |
1、
2、
6.返回頂部 |
![]() |
作者:ylbtech 出處:http://ylbtech.cnblogs.com/ 本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。 |