-
Notifications
You must be signed in to change notification settings - Fork 7
/
customer.go
45 lines (39 loc) · 1.75 KB
/
customer.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
package WeChatCustomerServiceSDK
import (
"encoding/json"
"fmt"
"github.com/NICEXAI/WeChatCustomerServiceSDK/util"
)
const (
customerBatchGetAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/customer/batchget?access_token=%s"
)
// CustomerBatchGetOptions 客户基本信息获取请求参数
type CustomerBatchGetOptions struct {
ExternalUserIDList []string `json:"external_userid_list"` // external_userid列表
}
// CustomerSchema 微信客户基本资料
type CustomerSchema struct {
ExternalUserID string `json:"external_userid"` // 微信客户的external_userid
NickName string `json:"nickname"` // 微信昵称
Avatar string `json:"avatar"` // 微信头像。第三方不可获取
Gender int `json:"gender"` // 性别
UnionID string `json:"unionid"` // unionid,需要绑定微信开发者帐号才能获取到,查看绑定方法: https://open.work.weixin.qq.com/kf/doc/92512/93143/94769#%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E5%BE%AE%E4%BF%A1%E5%AE%A2%E6%88%B7%E7%9A%84unionid
}
// CustomerBatchGetSchema 获取客户基本信息响应内容
type CustomerBatchGetSchema struct {
BaseModel
CustomerList []CustomerSchema `json:"customer_list"` // 微信客户信息列表
InvalidExternalUserID []string `json:"invalid_external_userid"` // 无效的微信客户ID
}
// CustomerBatchGet 客户基本信息获取
func (r *Client) CustomerBatchGet(options CustomerBatchGetOptions) (info CustomerBatchGetSchema, err error) {
data, err := util.HttpPost(fmt.Sprintf(customerBatchGetAddr, r.accessToken), options)
if err != nil {
return info, err
}
_ = json.Unmarshal(data, &info)
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}