-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofficialaccount.go
120 lines (100 loc) · 3.43 KB
/
officialaccount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package officialaccount
import (
"net/http"
"github.com/fideism/golang-wechat/credential"
"github.com/fideism/golang-wechat/officialaccount/basic"
"github.com/fideism/golang-wechat/officialaccount/broadcast"
"github.com/fideism/golang-wechat/officialaccount/card"
"github.com/fideism/golang-wechat/officialaccount/config"
"github.com/fideism/golang-wechat/officialaccount/context"
"github.com/fideism/golang-wechat/officialaccount/datacube"
"github.com/fideism/golang-wechat/officialaccount/device"
"github.com/fideism/golang-wechat/officialaccount/js"
"github.com/fideism/golang-wechat/officialaccount/material"
"github.com/fideism/golang-wechat/officialaccount/menu"
"github.com/fideism/golang-wechat/officialaccount/message"
"github.com/fideism/golang-wechat/officialaccount/oauth"
"github.com/fideism/golang-wechat/officialaccount/server"
"github.com/fideism/golang-wechat/officialaccount/user"
)
//OfficialAccount 微信公众号相关API
type OfficialAccount struct {
ctx *context.Context
}
//NewOfficialAccount 实例化公众号API
func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
defaultAkHandle := credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, credential.CacheKeyOfficialAccountPrefix, cfg.Cache)
ctx := &context.Context{
Config: cfg,
AccessTokenHandle: defaultAkHandle,
}
return &OfficialAccount{ctx: ctx}
}
//SetAccessTokenHandle 自定义access_token获取方式
func (o *OfficialAccount) SetAccessTokenHandle(accessTokenHandle credential.AccessTokenHandle) {
o.ctx.AccessTokenHandle = accessTokenHandle
}
// GetContext get Context
func (o *OfficialAccount) GetContext() *context.Context {
return o.ctx
}
// GetBasic qr/url 相关配置
func (o *OfficialAccount) GetBasic() *basic.Basic {
return basic.NewBasic(o.ctx)
}
// GetMenu 菜单管理接口
func (o *OfficialAccount) GetMenu() *menu.Menu {
return menu.NewMenu(o.ctx)
}
// GetServer 消息管理:接收事件,被动回复消息管理
func (o *OfficialAccount) GetServer(req *http.Request, writer http.ResponseWriter) *server.Server {
srv := server.NewServer(o.ctx)
srv.Request = req
srv.Writer = writer
return srv
}
//GetAccessToken 获取access_token
func (o *OfficialAccount) GetAccessToken() (string, error) {
return o.ctx.GetAccessToken()
}
// GetOauth oauth2网页授权
func (o *OfficialAccount) GetOauth() *oauth.Oauth {
return oauth.NewOauth(o.ctx)
}
// GetMaterial 素材管理
func (o *OfficialAccount) GetMaterial() *material.Material {
return material.NewMaterial(o.ctx)
}
// GetJs js-sdk配置
func (o *OfficialAccount) GetJs() *js.Js {
return js.NewJs(o.ctx)
}
// GetUser 用户管理接口
func (o *OfficialAccount) GetUser() *user.User {
return user.NewUser(o.ctx)
}
// GetTemplate 模板消息接口
func (o *OfficialAccount) GetTemplate() *message.Template {
return message.NewTemplate(o.ctx)
}
// GetDevice 获取智能设备的实例
func (o *OfficialAccount) GetDevice() *device.Device {
return device.NewDevice(o.ctx)
}
//GetBroadcast 群发消息
//TODO 待完善
func (o *OfficialAccount) GetBroadcast() *broadcast.Broadcast {
return broadcast.NewBroadcast(o.ctx)
}
//GetDataCube 数据统计
func (o *OfficialAccount) GetDataCube() *datacube.DataCube {
return datacube.NewCube(o.ctx)
}
// GetCard 卡券
func (o *OfficialAccount) GetCard() *card.Card {
return card.NewCard(o.ctx)
}
// GetMessage 消息管理
func (o *OfficialAccount) GetMessage() *message.Manager {
return message.NewMessageManager(o.ctx)
}