forked from shenghui0779/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
122 lines (104 loc) ยท 3.06 KB
/
sync.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
121
122
package addrbook
import (
"encoding/json"
"github.com/chenghonour/wechat-sdk/urls"
"github.com/chenghonour/wechat-sdk/wx"
)
type BatchType string
const (
SyncUser BatchType = "sync_user"
ReplaceUser BatchType = "replace_user"
ReplaceParty BatchType = "replace_party"
)
type ResultBatch struct {
JobID string `json:"jobid"`
}
type BatchCallback struct {
URL string `json:"url,omitempty"`
Token string `json:"token,omitempty"`
EncodingAESKey string `json:"encodingaeskey,omitempty"`
}
type ParamsUserBatchSync struct {
MediaID string `json:"media_id"`
ToInvite bool `json:"to_invite"`
Callback *BatchCallback `json:"callback,omitempty"`
}
// BatchSyncUser ๅข้ๆดๆฐๆๅ
func BatchSyncUser(mediaID string, toInvite bool, callback *BatchCallback, result *ResultBatch) wx.Action {
params := &ParamsUserBatchSync{
MediaID: mediaID,
ToInvite: toInvite,
Callback: callback,
}
return wx.NewPostAction(urls.CorpUserBatchSyncUser,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsUserBatchReplace struct {
MediaID string `json:"media_id"`
ToInvite bool `json:"to_invite"`
Callback *BatchCallback `json:"callback,omitempty"`
}
// BatchReplaceUser ๅ
จ้่ฆ็ๆๅ
func BatchReplaceUser(mediaID string, toInvite bool, callback *BatchCallback, result *ResultBatch) wx.Action {
params := &ParamsUserBatchReplace{
MediaID: mediaID,
ToInvite: toInvite,
Callback: callback,
}
return wx.NewPostAction(urls.CorpUserBatchReplaceUser,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsPartyBatchReplace struct {
MediaID string `json:"media_id"`
Callback *BatchCallback `json:"callback,omitempty"`
}
// BatchReplaceParty ๅ
จ้่ฆ็้จ้จ
func BatchReplaceParty(mediaID string, callback *BatchCallback, result *ResultBatch) wx.Action {
params := &ParamsPartyBatchReplace{
MediaID: mediaID,
Callback: callback,
}
return wx.NewPostAction(urls.CorpUserBatchReplaceParty,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ResultBatchRet struct {
Status int `json:"status"`
Type BatchType `json:"type"`
Total int `json:"total"`
Percentage int `json:"percentage"`
Result []*BatchRet `json:"result"`
}
type BatchRet struct {
UserID string `json:"userid"`
Action int `json:"action"`
PartyID int `json:"partyid"`
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
}
// GetBatchResult ่ทๅๅผๆญฅไปปๅก็ปๆ
func GetBatchResult(jobID string, result *ResultBatchRet) wx.Action {
return wx.NewGetAction(urls.CorpUserGetBatchResult,
wx.WithQuery("jobid", jobID),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}