mirror of
https://github.com/silenceper/wechat.git
synced 2026-03-01 00:35:26 +08:00
Compare commits
2 Commits
252fc4838b
...
eb3dbf1646
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb3dbf1646 | ||
|
|
27e18b6958 |
@@ -19,9 +19,9 @@
|
|||||||
| -------------------- | -------- | -------------------------------------- | ---------- | ----------------------- |
|
| -------------------- | -------- | -------------------------------------- | ---------- | ----------------------- |
|
||||||
| 选用模板 | POST | /wxaapi/newtmpl/addtemplate | YES | (tpl *Subscribe) Add |
|
| 选用模板 | POST | /wxaapi/newtmpl/addtemplate | YES | (tpl *Subscribe) Add |
|
||||||
| 删除模板 | POST | /wxaapi/newtmpl/deltemplate | YES | (tpl *Subscribe) Delete |
|
| 删除模板 | POST | /wxaapi/newtmpl/deltemplate | YES | (tpl *Subscribe) Delete |
|
||||||
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | NO | |
|
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | YES | (tpl *Subscribe) GetCategory |
|
||||||
| 获取模板中的关键词 | GET | /wxaapi/newtmpl/getpubtemplatekeywords | NO | |
|
| 获取模板中的关键词 | GET | /wxaapi/newtmpl/getpubtemplatekeywords | YES | (tpl *Subscribe) GetPubTplKeyWordsByID |
|
||||||
| 获取类目下的公共模板 | GET | /wxaapi/newtmpl/getpubtemplatetitles | NO | |
|
| 获取类目下的公共模板 | GET | /wxaapi/newtmpl/getpubtemplatetitles | YES | (tpl *Subscribe) GetPublicTemplateTitleList |
|
||||||
| 获取私有模板列表 | GET | /wxaapi/newtmpl/gettemplate | YES | (tpl *Subscribe) List() |
|
| 获取私有模板列表 | GET | /wxaapi/newtmpl/gettemplate | YES | (tpl *Subscribe) List() |
|
||||||
| 发送订阅通知 | POST | /cgi-bin/message/subscribe/bizsend | YES | (tpl *Subscribe) Send |
|
| 发送订阅通知 | POST | /cgi-bin/message/subscribe/bizsend | YES | (tpl *Subscribe) Send |
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
||||||
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||||
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
||||||
subscribeTemplateDelURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
subscribeTemplateDelURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
||||||
|
subscribeTemplateGetCategoryURL = "https://api.weixin.qq.com/wxaapi/newtmpl/getcategory"
|
||||||
|
subscribeTemplateGetPubTplKeyWorksURL = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords"
|
||||||
|
subscribeTemplateGetPubTplTitles = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Subscribe 订阅消息
|
// Subscribe 订阅消息
|
||||||
@@ -145,3 +148,108 @@ func (tpl *Subscribe) Delete(templateID string) (err error) {
|
|||||||
}
|
}
|
||||||
return util.DecodeWithCommonError(response, "DeleteSubscribe")
|
return util.DecodeWithCommonError(response, "DeleteSubscribe")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PublicTemplateCategory 公众号类目
|
||||||
|
type PublicTemplateCategory struct {
|
||||||
|
ID int `json:"id"` //类目ID
|
||||||
|
Name string `json:"name"` //类目的中文名
|
||||||
|
}
|
||||||
|
|
||||||
|
type resSubscribeCategoryList struct {
|
||||||
|
util.CommonError
|
||||||
|
CategoryList []*PublicTemplateCategory `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCategory 获取公众号类目
|
||||||
|
func (tpl *Subscribe) GetCategory() (categoryList []*PublicTemplateCategory, err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = tpl.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uri := fmt.Sprintf("%s?access_token=%s", subscribeTemplateGetCategoryURL, accessToken)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.HTTPGet(uri)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var result resSubscribeCategoryList
|
||||||
|
err = util.DecodeWithError(response, &result, "GetCategory")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
categoryList = result.CategoryList
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicTemplateKeyWords 模板中的关键词
|
||||||
|
type PublicTemplateKeyWords struct {
|
||||||
|
KeyWordsID int `json:"kid"` // 关键词 id
|
||||||
|
Name string `json:"name"` // 关键词内容
|
||||||
|
Example string `json:"example"` //关键词内容对应的示例
|
||||||
|
Rule string `json:"rule"` // 参数类型
|
||||||
|
}
|
||||||
|
|
||||||
|
type resPublicTemplateKeyWordsList struct {
|
||||||
|
util.CommonError
|
||||||
|
KeyWordsList []*PublicTemplateKeyWords `json:"data"` //关键词列表
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPubTplKeyWordsByID 获取模板中的关键词
|
||||||
|
func (tpl *Subscribe) GetPubTplKeyWordsByID(titleID string) (keyWordsList []*PublicTemplateKeyWords, err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = tpl.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uri := fmt.Sprintf("%s?access_token=%s&tid=%s", subscribeTemplateGetPubTplKeyWorksURL, accessToken, titleID)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.HTTPGet(uri)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var result resPublicTemplateKeyWordsList
|
||||||
|
err = util.DecodeWithError(response, &result, "GetPublicTemplateKeyWords")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
keyWordsList = result.KeyWordsList
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicTemplateTitle 类目下的公共模板
|
||||||
|
type PublicTemplateTitle struct {
|
||||||
|
TitleID int `json:"tid"` // 模版标题 id
|
||||||
|
Title string `json:"title"` // 模版标题
|
||||||
|
Type int `json:"type"` // 模版类型,2 为一次性订阅,3 为长期订阅
|
||||||
|
CategoryID string `json:"categoryId"` // 模版所属类目 id
|
||||||
|
}
|
||||||
|
|
||||||
|
type resPublicTemplateTitleList struct {
|
||||||
|
util.CommonError
|
||||||
|
Count int `json:"count"` //公共模板列表总数
|
||||||
|
TemplateTitleList []*PublicTemplateTitle `json:"data"` //模板标题列表
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPublicTemplateTitleList 获取类目下的公共模板
|
||||||
|
func (tpl *Subscribe) GetPublicTemplateTitleList(ids string, start int, limit int) (count int, templateTitleList []*PublicTemplateTitle, err error) {
|
||||||
|
var accessToken string
|
||||||
|
accessToken, err = tpl.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uri := fmt.Sprintf("%s?access_token=%s&ids=%s&start=%d&limit=%d", subscribeTemplateGetPubTplTitles, accessToken, ids, start, limit)
|
||||||
|
var response []byte
|
||||||
|
response, err = util.HTTPGet(uri)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var result resPublicTemplateTitleList
|
||||||
|
err = util.DecodeWithError(response, &result, "GetPublicTemplateTitle")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
count = result.Count
|
||||||
|
templateTitleList = result.TemplateTitleList
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,7 +26,22 @@ import (
|
|||||||
|
|
||||||
// OfficialAccount 微信公众号相关API
|
// OfficialAccount 微信公众号相关API
|
||||||
type OfficialAccount struct {
|
type OfficialAccount struct {
|
||||||
ctx *context.Context
|
ctx *context.Context
|
||||||
|
basic *basic.Basic
|
||||||
|
menu *menu.Menu
|
||||||
|
oauth *oauth.Oauth
|
||||||
|
material *material.Material
|
||||||
|
draft *draft.Draft
|
||||||
|
freepublish *freepublish.FreePublish
|
||||||
|
js *js.Js
|
||||||
|
user *user.User
|
||||||
|
templateMsg *message.Template
|
||||||
|
managerMsg *message.Manager
|
||||||
|
device *device.Device
|
||||||
|
broadcast *broadcast.Broadcast
|
||||||
|
datacube *datacube.DataCube
|
||||||
|
ocr *ocr.OCR
|
||||||
|
subscribeMsg *message.Subscribe
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOfficialAccount 实例化公众号API
|
// NewOfficialAccount 实例化公众号API
|
||||||
@@ -51,12 +66,18 @@ func (officialAccount *OfficialAccount) GetContext() *context.Context {
|
|||||||
|
|
||||||
// GetBasic qr/url 相关配置
|
// GetBasic qr/url 相关配置
|
||||||
func (officialAccount *OfficialAccount) GetBasic() *basic.Basic {
|
func (officialAccount *OfficialAccount) GetBasic() *basic.Basic {
|
||||||
return basic.NewBasic(officialAccount.ctx)
|
if officialAccount.basic == nil {
|
||||||
|
officialAccount.basic = basic.NewBasic(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.basic
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMenu 菜单管理接口
|
// GetMenu 菜单管理接口
|
||||||
func (officialAccount *OfficialAccount) GetMenu() *menu.Menu {
|
func (officialAccount *OfficialAccount) GetMenu() *menu.Menu {
|
||||||
return menu.NewMenu(officialAccount.ctx)
|
if officialAccount.menu == nil {
|
||||||
|
officialAccount.menu = menu.NewMenu(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.menu
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetServer 消息管理:接收事件,被动回复消息管理
|
// GetServer 消息管理:接收事件,被动回复消息管理
|
||||||
@@ -74,66 +95,105 @@ func (officialAccount *OfficialAccount) GetAccessToken() (string, error) {
|
|||||||
|
|
||||||
// GetOauth oauth2网页授权
|
// GetOauth oauth2网页授权
|
||||||
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
|
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
|
||||||
return oauth.NewOauth(officialAccount.ctx)
|
if officialAccount.oauth == nil {
|
||||||
|
officialAccount.oauth = oauth.NewOauth(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.oauth
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMaterial 素材管理
|
// GetMaterial 素材管理
|
||||||
func (officialAccount *OfficialAccount) GetMaterial() *material.Material {
|
func (officialAccount *OfficialAccount) GetMaterial() *material.Material {
|
||||||
return material.NewMaterial(officialAccount.ctx)
|
if officialAccount.material == nil {
|
||||||
|
officialAccount.material = material.NewMaterial(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.material
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDraft 草稿箱
|
// GetDraft 草稿箱
|
||||||
func (officialAccount *OfficialAccount) GetDraft() *draft.Draft {
|
func (officialAccount *OfficialAccount) GetDraft() *draft.Draft {
|
||||||
return draft.NewDraft(officialAccount.ctx)
|
if officialAccount.draft == nil {
|
||||||
|
officialAccount.draft = draft.NewDraft(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.draft
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFreePublish 发布能力
|
// GetFreePublish 发布能力
|
||||||
func (officialAccount *OfficialAccount) GetFreePublish() *freepublish.FreePublish {
|
func (officialAccount *OfficialAccount) GetFreePublish() *freepublish.FreePublish {
|
||||||
return freepublish.NewFreePublish(officialAccount.ctx)
|
if officialAccount.freepublish == nil {
|
||||||
|
officialAccount.freepublish = freepublish.NewFreePublish(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.freepublish
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetJs js-sdk配置
|
// GetJs js-sdk配置
|
||||||
func (officialAccount *OfficialAccount) GetJs() *js.Js {
|
func (officialAccount *OfficialAccount) GetJs() *js.Js {
|
||||||
return js.NewJs(officialAccount.ctx)
|
if officialAccount.js == nil {
|
||||||
|
officialAccount.js = js.NewJs(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.js
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUser 用户管理接口
|
// GetUser 用户管理接口
|
||||||
func (officialAccount *OfficialAccount) GetUser() *user.User {
|
func (officialAccount *OfficialAccount) GetUser() *user.User {
|
||||||
return user.NewUser(officialAccount.ctx)
|
if officialAccount.user == nil {
|
||||||
|
officialAccount.user = user.NewUser(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.user
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTemplate 模板消息接口
|
// GetTemplate 模板消息接口
|
||||||
func (officialAccount *OfficialAccount) GetTemplate() *message.Template {
|
func (officialAccount *OfficialAccount) GetTemplate() *message.Template {
|
||||||
return message.NewTemplate(officialAccount.ctx)
|
if officialAccount.templateMsg == nil {
|
||||||
|
officialAccount.templateMsg = message.NewTemplate(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.templateMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCustomerMessageManager 客服消息接口
|
// GetCustomerMessageManager 客服消息接口
|
||||||
func (officialAccount *OfficialAccount) GetCustomerMessageManager() *message.Manager {
|
func (officialAccount *OfficialAccount) GetCustomerMessageManager() *message.Manager {
|
||||||
return message.NewMessageManager(officialAccount.ctx)
|
if officialAccount.managerMsg == nil {
|
||||||
|
officialAccount.managerMsg = message.NewMessageManager(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.managerMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDevice 获取智能设备的实例
|
// GetDevice 获取智能设备的实例
|
||||||
func (officialAccount *OfficialAccount) GetDevice() *device.Device {
|
func (officialAccount *OfficialAccount) GetDevice() *device.Device {
|
||||||
return device.NewDevice(officialAccount.ctx)
|
if officialAccount.device == nil {
|
||||||
|
officialAccount.device = device.NewDevice(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.device
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBroadcast 群发消息
|
// GetBroadcast 群发消息
|
||||||
// TODO 待完善
|
// TODO 待完善
|
||||||
func (officialAccount *OfficialAccount) GetBroadcast() *broadcast.Broadcast {
|
func (officialAccount *OfficialAccount) GetBroadcast() *broadcast.Broadcast {
|
||||||
return broadcast.NewBroadcast(officialAccount.ctx)
|
if officialAccount.broadcast == nil {
|
||||||
|
officialAccount.broadcast = broadcast.NewBroadcast(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.broadcast
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDataCube 数据统计
|
// GetDataCube 数据统计
|
||||||
func (officialAccount *OfficialAccount) GetDataCube() *datacube.DataCube {
|
func (officialAccount *OfficialAccount) GetDataCube() *datacube.DataCube {
|
||||||
return datacube.NewCube(officialAccount.ctx)
|
if officialAccount.datacube == nil {
|
||||||
|
officialAccount.datacube = datacube.NewCube(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.datacube
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOCR OCR接口
|
// GetOCR OCR接口
|
||||||
func (officialAccount *OfficialAccount) GetOCR() *ocr.OCR {
|
func (officialAccount *OfficialAccount) GetOCR() *ocr.OCR {
|
||||||
return ocr.NewOCR(officialAccount.ctx)
|
if officialAccount.ocr == nil {
|
||||||
|
officialAccount.ocr = ocr.NewOCR(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.ocr
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSubscribe 公众号订阅消息
|
// GetSubscribe 公众号订阅消息
|
||||||
func (officialAccount *OfficialAccount) GetSubscribe() *message.Subscribe {
|
func (officialAccount *OfficialAccount) GetSubscribe() *message.Subscribe {
|
||||||
return message.NewSubscribe(officialAccount.ctx)
|
if officialAccount.subscribeMsg == nil {
|
||||||
|
officialAccount.subscribeMsg = message.NewSubscribe(officialAccount.ctx)
|
||||||
|
}
|
||||||
|
return officialAccount.subscribeMsg
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user