1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-06 13:42:26 +08:00

feat:add template list method (#298)

This commit is contained in:
Amor
2020-07-07 19:08:02 +08:00
committed by GitHub
parent c956f416a5
commit ff38e6bac0

View File

@@ -10,6 +10,7 @@ import (
const (
templateSendURL = "https://api.weixin.qq.com/cgi-bin/message/template/send"
templateListURL = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template"
)
//Template 模板消息
@@ -74,3 +75,41 @@ func (tpl *Template) Send(msg *TemplateMessage) (msgID int64, err error) {
msgID = result.MsgID
return
}
// TemplateItem 模板消息.
type TemplateItem struct {
TemplateID string `json:"template_id"`
Title string `json:"title"`
PrimaryIndustry string `json:"primary_industry"`
DeputyIndustry string `json:"deputy_industry"`
Content string `json:"content"`
Example string `json:"example"`
}
type resTemplateList struct {
util.CommonError
TemplateList []*TemplateItem `json:"template_list"`
}
//List 获取模板列表
func (tpl *Template) List() (templateList []*TemplateItem, err error) {
var accessToken string
accessToken, err = tpl.GetAccessToken()
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", templateListURL, accessToken)
var response []byte
response, err = util.HTTPGet(uri)
if err != nil {
return
}
var res resTemplateList
err = util.DecodeWithError(response, res, "ListTemplate")
if err != nil {
return
}
templateList = res.TemplateList
return
}