forked from shenghui0779/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
131 lines (110 loc) ยท 3.14 KB
/
user.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
123
124
125
126
127
128
129
130
131
package linkedcorp
import (
"encoding/json"
"fmt"
"github.com/chenghonour/wechat-sdk/urls"
"github.com/chenghonour/wechat-sdk/wx"
)
type UserInfo struct {
UserID string `json:"userid"`
Name string `json:"name"`
Department []string `json:"department"`
Mobile string `json:"mobile"`
Telephone string `json:"telephone"`
EMail string `json:"email"`
Position string `json:"position"`
CorpID string `json:"corpid"`
ExtAttr *ExtAttr `json:"extattr"`
}
type ExtAttr struct {
Attrs []*Attr `json:"attrs"`
}
type Attr struct {
Name string `json:"name"`
Type int `json:"type"`
Text *AttrText `json:"text,omitempty"`
Web *AttrWeb `json:"web,omitempty"`
Miniprogram *AttrMinip `json:"miniprogram,omitempty"`
}
type AttrText struct {
Value string `json:"value"`
}
type AttrWeb struct {
Title string `json:"title"`
URL string `json:"url"`
}
type AttrMinip struct {
Title string `json:"title"`
AppID string `json:"appid"`
PagePath string `json:"pagepath"`
}
type ParamsUserGet struct {
UserID string `json:"userid"`
}
type ResultUserGet struct {
UserInfo *UserInfo `json:"user_info"`
}
// GetUser ่ทๅไบ่ไผไธๆๅ่ฏฆ็ปไฟกๆฏ
func GetUser(corpID, userID string, result *ResultUserGet) wx.Action {
params := &ParamsUserGet{
UserID: fmt.Sprintf("%s/%s", corpID, userID),
}
return wx.NewPostAction(urls.CorpLinkedcorpUserGet,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsSimpleUserList struct {
DepartmentID string `json:"department_id"`
FetchChild bool `json:"fetch_child"`
}
type SimpleUser struct {
UserID string `json:"userid"`
Name string `json:"name"`
Department []string `json:"department"`
CorpID string `json:"corpid"`
}
type ResultSimpleUserList struct {
UserList []*SimpleUser `json:"userlist"`
}
// ListSimpleUser ่ทๅไบ่ไผไธ้จ้จๆๅ
func ListSimpleUser(linkedID, departmentID string, fetchChild bool, result *ResultSimpleUserList) wx.Action {
params := &ParamsSimpleUserList{
DepartmentID: fmt.Sprintf("%s/%s", linkedID, departmentID),
FetchChild: fetchChild,
}
return wx.NewPostAction(urls.CorpLinkedcorpUserSimpleList,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsUserList struct {
DepartmentID string `json:"department_id"`
FetchChild bool `json:"fetch_child"`
}
type ResultUserList struct {
UserList []*UserInfo `json:"userlist"`
}
// ListUser ่ทๅไบ่ไผไธ้จ้จๆๅ่ฏฆๆ
func ListUser(linkedID, departmentID string, fetchChild bool, result *ResultUserList) wx.Action {
params := &ParamsUserList{
DepartmentID: fmt.Sprintf("%s/%s", linkedID, departmentID),
FetchChild: fetchChild,
}
return wx.NewPostAction(urls.CorpLinkedcorpUserList,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}