-
Notifications
You must be signed in to change notification settings - Fork 171
/
client.go
81 lines (56 loc) · 2.33 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
package license
import (
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
response2 "github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/response"
"github.com/ArtisanCloud/PowerWeChat/v2/src/openPlatform/codeTemplate/response"
"github.com/ArtisanCloud/PowerWeChat/v2/src/openWork/auth"
)
type Client struct {
*kernel.BaseClient
}
func NewClient(app *kernel.ApplicationInterface) (*Client, error) {
token := (*app).GetComponent("ProviderAccessToken").(*auth.AccessToken)
baseClient, err := kernel.NewBaseClient(app, token.AccessToken)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// 获取代码草稿列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatedraftlist.html
func (comp *Client) GetDrafts() (*response.ResponseGetDrafts, error) {
result := &response.ResponseGetDrafts{}
_, err := comp.HttpGet("wxa/gettemplatedraftlist", nil, nil, result)
return result, err
}
// 将草稿添加到代码模板库
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/addtotemplate.html#请求地址
func (comp *Client) CreateFromDraft(draftID int, templateType int) (*response2.ResponseOpenPlatform, error) {
result := &response2.ResponseOpenPlatform{}
params := &object.HashMap{
"draft_id": draftID,
"template_type": templateType,
}
_, err := comp.HttpPostJson("wxa/addtotemplate", params, nil, nil, result)
return result, err
}
// 获取代码模板列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatelist.html#请求地址
func (comp *Client) List() (*response.ResponseList, error) {
result := &response.ResponseList{}
_, err := comp.HttpGet("wxa/gettemplatelist", nil, nil, result)
return result, err
}
// 删除指定代码模板
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/deletetemplate.html#请求地址
func (comp *Client) Delete(templateID string) (*response2.ResponseOpenPlatform, error) {
result := &response2.ResponseOpenPlatform{}
params := &object.HashMap{
"template_id": templateID,
}
_, err := comp.HttpPostJson("wxa/deletetemplate", params, nil, nil, result)
return result, err
}