-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathopen.go
69 lines (62 loc) · 2.4 KB
/
open.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
package wechat3rd
import "github.com/l306287405/wechat3rd/core"
type OpenCreateOrGetResp struct {
core.Error
OpenAppId string `json:"open_appid"`
}
// 创建开放平台帐号并绑定公众号/小程序
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/account/create.html
func (s *Server) OpenCreate(authorizerAccessToken string, appId *string) (resp *OpenCreateOrGetResp) {
var (
u = CGIUrl + "/open/create?"
req = &struct {
AppId *string `json:"appid"`
}{}
)
if appId != nil {
req.AppId = appId
}
resp = &OpenCreateOrGetResp{}
resp.Err(core.PostJson(s.AuthToken2url(u, authorizerAccessToken), req, resp))
return
}
type OpenBindOrUnbindReq struct {
AppId *string `json:"appid,omitempty"` //非必填,如果不填则取生成authorizer_access_token的授权公众号或小程序的 appid。如果填,则需要填与生成authorizer_access_token的授权公众号或小程序的 appid一致的appid,否则会出现40013报错
OpenAppid string `json:"open_appid"` //开放平台帐号 appid,由创建开发平台帐号接口返回
}
// 将公众号/小程序绑定到开放平台帐号下
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/account/create.html
func (s *Server) OpenBind(authorizerAccessToken string, req *OpenBindOrUnbindReq) (resp *core.Error) {
var (
u = CGIUrl + "/open/bind?"
)
resp = &core.Error{}
resp.Err(core.PostJson(s.AuthToken2url(u, authorizerAccessToken), req, resp))
return
}
// 将公众号/小程序从开放平台帐号下解绑
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/account/unbind.html
func (s *Server) OpenUnbind(authorizerAccessToken string, req *OpenBindOrUnbindReq) (resp *core.Error) {
var (
u = CGIUrl + "/open/unbind?"
)
resp = &core.Error{}
resp.Err(core.PostJson(s.AuthToken2url(u, authorizerAccessToken), req, resp))
return
}
// 获取公众号/小程序所绑定的开放平台帐号
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/account/get.html
func (s *Server) OpenGet(authorizerAccessToken string, appId *string) (resp *OpenCreateOrGetResp) {
var (
u = CGIUrl + "/open/get?"
req = &struct {
AppId *string `json:"appid,omitempty"`
}{}
)
if appId != nil {
req.AppId = appId
}
resp = &OpenCreateOrGetResp{}
resp.Err(core.PostJson(s.AuthToken2url(u, authorizerAccessToken), req, resp))
return
}