customer info2

This commit is contained in:
jiangyong27 2024-01-24 21:08:44 +08:00
parent e04e84cb8a
commit 9d69129614
1 changed files with 35 additions and 35 deletions

View File

@ -180,6 +180,41 @@ func (a *AppCustomer) GetCustomerState(openKfid, externalUserid string) (*Custom
return state, nil return state, nil
} }
func (q *AppCustomer) GetCustomerInfo(externalUserid string) (*CustomerInfo, error) {
postdata := map[string]interface{}{
"external_userid_list": []string{
externalUserid,
},
"need_enter_session_context": 1,
}
dataByte, err := json.Marshal(postdata)
if err != nil {
return nil, err
}
rspBody, err := util.HttpPostJson("https://qyapi.weixin.qq.com/cgi-bin/kf/customer/batchget?access_token="+q.GetToken(), nil, dataByte)
if err != nil {
return nil, err
}
result, err := q.GetResult(rspBody)
if err != nil {
return nil, err
}
users := cast.ToSlice(result["customer_list"])
if len(users) == 0 {
return nil, errors.New("no user info")
}
user := cast.ToStringMap(users[0])
u := new(CustomerInfo)
u.Nickname = cast.ToString(user["nickname"])
u.Avatar = cast.ToString(user["avatar"])
u.Unionid = cast.ToString(user["unionid"])
u.Gender = cast.ToInt(user["gender"])
u.Context = user["enter_session_context"]
return u, nil
}
func (a *AppCustomer) SendCustomerText(openKfId, toUser, content string) error { func (a *AppCustomer) SendCustomerText(openKfId, toUser, content string) error {
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg?access_token=%s", a.GetToken()) reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg?access_token=%s", a.GetToken())
params := make(map[string]interface{}) params := make(map[string]interface{})
@ -260,41 +295,6 @@ func (q *AppCustomer) GetServiceLink(openKfId, sence string) (string, error) {
return customerServcieUrl, nil return customerServcieUrl, nil
} }
func (q *AppCustomer) GetCustomerInfo(externalUserid string) (*CustomerInfo, error) {
postdata := map[string]interface{}{
"external_userid_list": []string{
externalUserid,
},
"need_enter_session_context": 1,
}
dataByte, err := json.Marshal(postdata)
if err != nil {
return nil, err
}
rspBody, err := util.HttpPostJson("https://qyapi.weixin.qq.com/cgi-bin/kf/customer/batchget?access_token="+q.GetToken(), nil, dataByte)
if err != nil {
return nil, err
}
result, err := q.GetResult(rspBody)
if err != nil {
return nil, err
}
users := cast.ToSlice(result["customer_list"])
if len(users) == 0 {
return nil, errors.New("no user info")
}
user := cast.ToStringMap(users[0])
u := new(CustomerInfo)
u.Nickname = cast.ToString(user["nickname"])
u.Avatar = cast.ToString(user["avatar"])
u.Unionid = cast.ToString(user["unionid"])
u.Gender = cast.ToInt(user["gender"])
u.Context = user["enter_session_context"]
return u, nil
}
func (m *CustomerMessage) From(data map[string]interface{}) { func (m *CustomerMessage) From(data map[string]interface{}) {
m.SyncTime = time.Now().Unix() m.SyncTime = time.Now().Unix()
m.SendTime = cast.ToInt64(data["send_time"]) m.SendTime = cast.ToInt64(data["send_time"])