From c7d7be7320813e607a1eadde82b6002d9425650b Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Tue, 23 Jan 2024 21:31:39 +0800 Subject: [PATCH] customer state --- qyweixin/app_customer.go | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/qyweixin/app_customer.go b/qyweixin/app_customer.go index a494305..2bf5436 100644 --- a/qyweixin/app_customer.go +++ b/qyweixin/app_customer.go @@ -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{})