customer state

This commit is contained in:
jiangyong27 2024-01-23 21:31:39 +08:00
parent 9dde0e0fa0
commit c7d7be7320
1 changed files with 43 additions and 0 deletions

View File

@ -25,6 +25,10 @@ type CustomerMessage struct {
SyncTime int64
Content string
}
type CustomerState struct {
State int
Servicer string
}
type AppCustomer struct {
App
@ -59,6 +63,45 @@ func (a *AppCustomer) AccountList() ([]*CustomerAccount, error) {
return accounts, nil
}
func (a *AppCustomer) SetCustomerState(openKfid, externalUserid string, state *CustomerState) error {
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/trans?access_token=%s", a.GetToken())
params := make(map[string]interface{})
params["external_userid"] = externalUserid
params["open_kfid"] = openKfid
params["service_state"] = state.State
params["servicer_userid"] = state.Servicer
reqBody, _ := json.Marshal(params)
rspBody, err := util.HttpPostJson(reqUrl, nil, reqBody)
if err != nil {
return err
}
_, err = a.GetResult(rspBody)
if err != nil {
return err
}
return nil
}
func (a *AppCustomer) GetCustomerState(openKfid, externalUserid string) (*CustomerState, error) {
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/get?access_token=%s", a.GetToken())
params := make(map[string]interface{})
params["external_userid"] = externalUserid
params["open_kfid"] = openKfid
reqBody, _ := json.Marshal(params)
rspBody, err := util.HttpPostJson(reqUrl, nil, reqBody)
if err != nil {
return nil, err
}
result, err := a.GetResult(rspBody)
if err != nil {
return nil, err
}
state := new(CustomerState)
state.State = cast.ToInt(result["service_state"])
state.Servicer = cast.ToString(result["servicer_userid"])
return state, nil
}
func (a *AppCustomer) SendCustomerText(toUser, openKfId, content string) error {
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg?access_token=%s", a.GetToken())
params := make(map[string]interface{})