-
Notifications
You must be signed in to change notification settings - Fork 174
/
client.go
89 lines (66 loc) · 2.71 KB
/
client.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
package account
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
response2 "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response"
"github.com/ArtisanCloud/PowerWeChat/v3/src/openPlatform/authorizer/aggregate/account/response"
)
type Client struct {
BaseClient *kernel.BaseClient
}
func NewClient(app kernel.ApplicationInterface) (*Client, error) {
baseClient, err := kernel.NewBaseClient(&app, nil)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// 创建开放平台帐号并绑定公众号/小程序
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/account/create.html
func (comp *Client) Create(ctx context.Context) (*response.ResponseCreate, error) {
result := &response.ResponseCreate{}
config := (*comp.BaseClient.App).GetConfig()
params := &object.HashMap{
"appid": config.GetString("app_id", ""),
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/open/create", params, nil, nil, result)
return result, err
}
// 将公众号/小程序绑定到开放平台帐号下
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/account/bind.html
func (comp *Client) BindTo(ctx context.Context, openAppID string) (*response2.ResponseOpenPlatform, error) {
result := &response2.ResponseOpenPlatform{}
config := (*comp.BaseClient.App).GetConfig()
params := &object.HashMap{
"appid": config.GetString("app_id", ""),
"open_appid": openAppID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/open/bind", params, nil, nil, result)
return result, err
}
// 将公众号/小程序绑定到开放平台帐号下
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/account/unbind.html
func (comp *Client) UnbindFrom(ctx context.Context, openAppID string) (*response2.ResponseOpenPlatform, error) {
result := &response2.ResponseOpenPlatform{}
config := (*comp.BaseClient.App).GetConfig()
params := &object.HashMap{
"appid": config.GetString("app_id", ""),
"open_appid": openAppID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/open/unbind", params, nil, nil, result)
return result, err
}
// 获取公众号/小程序所绑定的开放平台帐号
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/account/get.html
func (comp *Client) GetBinding(ctx context.Context) (*response.ResponseGetBinding, error) {
result := &response.ResponseGetBinding{}
config := (*comp.BaseClient.App).GetConfig()
params := &object.HashMap{
"appid": config.GetString("app_id", ""),
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/open/get", params, nil, nil, result)
return result, err
}