This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
external_contact.go
174 lines (160 loc) · 5.9 KB
/
external_contact.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package wecom
// 客户管理
import (
"encoding/json"
"fmt"
"github.com/go-laoji/wecom-app-sdk/internal"
)
type ExternalContactGetFollowUserListResponse struct {
internal.BizResponse
FollowUser []string `json:"follow_user"`
}
// ExternalContactGetFollowUserList 获取配置了客户联系功能的成员列表
// 参考连接 https://open.work.weixin.qq.com/api/doc/90000/90135/92571
func (app weCom) ExternalContactGetFollowUserList() (resp ExternalContactGetFollowUserListResponse) {
queryParams := app.buildBasicTokenQuery(app.getAppAccessToken())
body, err := internal.HttpGet(fmt.Sprintf("/cgi-bin/externalcontact/get_follow_user_list?%s", queryParams.Encode()))
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
} else {
json.Unmarshal(body, &resp)
}
return
}
type ExternalContactListResponse struct {
internal.BizResponse
ExternalUserId []string `json:"external_userid"`
}
// ExternalContactList 获取客户列表
// 参考连接 https://open.work.weixin.qq.com/api/doc/90000/90135/92113
func (app weCom) ExternalContactList(userId string) (resp ExternalContactListResponse) {
queryParams := app.buildBasicTokenQuery(app.getAppAccessToken())
queryParams.Add("userid", userId)
body, err := internal.HttpGet(fmt.Sprintf("/cgi-bin/externalcontact/list?%s", queryParams.Encode()))
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
} else {
json.Unmarshal(body, &resp)
}
return
}
type ExternalContact struct {
ExternalUserId string `json:"external_userid"`
Name string `json:"name"`
Position string `json:"position"`
Avatar string `json:"avatar"`
CorpName string `json:"corp_name"`
CorpFullName string `json:"corp_full_name"`
Type int `json:"type"`
Gender int `json:"gender"`
UnionId string `json:"unionid"`
ExternalProfile struct {
ExternalAttr []struct {
Type int `json:"type"`
Name string `json:"name"`
Text struct {
Value string `json:"value"`
} `json:"text,omitempty"`
Web struct {
Url string `json:"url"`
Title string `json:"title"`
} `json:"web,omitempty"`
MiniProgram struct {
AppId string `json:"appid"`
PagePath string `json:"pagepath"`
Title string `json:"title"`
} `json:"miniprogram,omitempty"`
}
} `json:"external_profile"`
}
type FollowUser struct {
UserId string `json:"userid"`
Remark string `json:"remark,omitempty"`
Description string `json:"description,omitempty"`
CreateTime int64 `json:"createtime"`
Tags []struct {
GroupName string `json:"group_name"`
TagName string `json:"tag_name"`
TagId string `json:"tag_id"`
Type int `json:"type"`
} `json:"tags,omitempty"`
RemarkCorpName string `json:"remark_corp_name,omitempty"`
RemarkMobiles []string `json:"remark_mobiles,omitempty"`
State string `json:"state,omitempty"`
OperUserId string `json:"oper_userid,omitempty"`
AddWay int `json:"add_way,omitempty"`
}
type ExternalContactGetResponse struct {
internal.BizResponse
ExternalContact ExternalContact `json:"external_contact"`
FollowUser []FollowUser `json:"follow_user"`
NextCursor string `json:"next_cursor"`
}
// ExternalContactGet 获取客户详情
// 参考连接 https://open.work.weixin.qq.com/api/doc/90000/90135/92114
// 当客户在企业内的跟进人超过500人时需要使用cursor参数进行分页获取
func (app weCom) ExternalContactGet(externalUserId, cursor string) (resp ExternalContactGetResponse) {
queryParams := app.buildBasicTokenQuery(app.getAppAccessToken())
queryParams.Add("external_userid", externalUserId)
queryParams.Add("cursor", cursor)
body, err := internal.HttpGet(fmt.Sprintf("/cgi-bin/externalcontact/get?%s", queryParams.Encode()))
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
} else {
json.Unmarshal(body, &resp)
}
return
}
type ExternalContactBatchGetByUserResponse struct {
internal.BizResponse
ExternalContactList []struct {
ExternalContact ExternalContact `json:"external_contact"`
FollowInfo FollowUser `json:"follow_info"`
} `json:"external_contact_list"`
NextCursor string `json:"next_cursor"`
}
// ExternalContactBatchGetByUser 批量获取客户详情
// 企业可通过此接口获取指定成员添加的客户信息列表。
// 参考连接 https://open.work.weixin.qq.com/api/doc/90000/90135/92994
func (app weCom) ExternalContactBatchGetByUser(userIds []string, cursor string, limit int) (resp ExternalContactBatchGetByUserResponse) {
p := H{"userid_list": userIds, "cursor": cursor, "limit": limit}
queryParams := app.buildBasicTokenQuery(app.getAppAccessToken())
body, err := internal.HttpPost(fmt.Sprintf("/cgi-bin/externalcontact/batch/get_by_user?%s", queryParams.Encode()), p)
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
} else {
json.Unmarshal(body, &resp)
}
return
}
type ExternalContactRemarkRequest struct {
UserId string `json:"user_id" validate:"required"`
ExternalUserid string `json:"external_userid" validate:"required"`
Remark string `json:"remark"`
Description string `json:"description"`
RemarkCompany string `json:"remark_company"`
RemarkMobiles []string `json:"remark_mobiles"`
RemarkPicMediaId string `json:"remark_pic_mediaid"`
}
// ExternalContactRemark 修改客户备注信息
// 参考连接 https://open.work.weixin.qq.com/api/doc/90000/90135/92115
func (app weCom) ExternalContactRemark(remark ExternalContactRemarkRequest) (resp internal.BizResponse) {
if ok := validate.Struct(remark); ok != nil {
resp.ErrCode = 500
resp.ErrorMsg = ok.Error()
return
}
queryParams := app.buildBasicTokenQuery(app.getAppAccessToken())
body, err := internal.HttpPost(fmt.Sprintf("/cgi-bin/externalcontact/remark?%s", queryParams.Encode()), remark)
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
} else {
json.Unmarshal(body, &resp)
}
return
}