mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-14 01:32:27 +08:00
fix officialaccount part in Issue 590 (#591)
* fix issue #586 #543 * fix issue #590 in officialaccount Co-authored-by: Wang Rong <wangron@tesla.com>
This commit is contained in:
@@ -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