-
Notifications
You must be signed in to change notification settings - Fork 165
/
client.go
99 lines (77 loc) · 3.48 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
90
91
92
93
94
95
96
97
98
99
package idConvert
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/idConvert/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
}
// unionid转换为第三方external_userid
// https://developer.work.weixin.qq.com/document/path/95900#unionid%E8%BD%AC%E6%8D%A2%E4%B8%BA%E7%AC%AC%E4%B8%89%E6%96%B9external-userid
func (comp *Client) UnionIDToExternalUserID(ctx context.Context, unionID string, openID string, subjectType int) (*response.ResponseUnionIDToExternalUserID, error) {
result := new(response.ResponseUnionIDToExternalUserID)
req := object.HashMap{
"unionid": unionID,
"openid": openID,
}
if subjectType == 1 {
req["subject_type"] = subjectType
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/idconvert/unionid_to_external_userid", &req, nil, nil, result)
return result, err
}
// external_userid查询pending_id
// 该接口可用于当一个微信用户成为企业客户前已经使用过服务商服务(服务商曾通过unionid查询external_userid接口获取到pending_id)的场景。本接口获取到的pending_id可以维持unionid和external_userid的关联关系。pending_id有效期为90天,超过有效期之后,将无法通过该接口将external_userid换取对应的pending_id。
func (comp *Client) ExternalUserIDToPendingID(ctx context.Context, externalUserID []string, chatID string) ([]response.ExternalUserIDToPendingIDResult, error) {
result := new(response.ResponseExternalUserIDToPendingID)
req := object.HashMap{
"external_userid": externalUserID,
}
if chatID != "" {
req["chat_id"] = chatID
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/idconvert/batch/external_userid_to_pending_id", &req, nil, nil, result)
return result.Result, err
}
// userid的转换
// https://developer.work.weixin.qq.com/document/path/97062
func (comp *Client) UserIDToOpenUserID(ctx context.Context, userIDList []string) ([]response.UserIDToOpenUserIDResult, error) {
result := new(response.ResponseUserIDToOpenUserID)
req := object.HashMap{
"userid_list": userIDList,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/batch/userid_to_openuserid", &req, nil, nil, result)
return result.OpenUserIDList, err
}
// userid的转换
// https://developer.work.weixin.qq.com/document/path/97062
func (comp *Client) OpenUserIDToUserID(ctx context.Context, sourceAgentID int, openUserIDList []string) (*response.ResponseOpenUserIDToUserID, error) {
result := new(response.ResponseOpenUserIDToUserID)
req := object.HashMap{
"source_agentid": sourceAgentID,
"open_userid_list": openUserIDList,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/batch/openuserid_to_userid", &req, nil, nil, result)
return result, err
}
// 客户标签ID的转换
// https://developer.work.weixin.qq.com/document/path/96169
func (comp *Client) ExternalTagIDToOpenExternalTagID(ctx context.Context, externalTagIDList []string) (*response.ResponseExternalTagIDToOpenExternalTagID, error) {
result := new(response.ResponseExternalTagIDToOpenExternalTagID)
req := object.HashMap{
"external_tagid_list": externalTagIDList,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/idconvert/external_tagid", &req, nil, nil, result)
return result, err
}