customer message

This commit is contained in:
jiangyong27 2024-07-26 22:53:27 +08:00
parent c714db19b0
commit 616f26f45b
1 changed files with 33 additions and 4 deletions

View File

@ -234,14 +234,42 @@ func (q *AppCustomer) GetCustomerInfo(externalUserid string) (*CustomerInfo, err
} }
func (a *AppCustomer) SendCustomerText(openKfId, toUser, content string) error { func (a *AppCustomer) SendCustomerText(openKfId, toUser, content string) error {
return a.sendCustomerMessage(openKfId, toUser, "text", map[string]interface{}{
"content": content,
})
}
func (a *AppCustomer) SendCustomerVideo(openKfId, toUser, mediaId string) error {
return a.sendCustomerMessage(openKfId, toUser, "video", map[string]interface{}{
"media_id": mediaId,
})
}
func (a *AppCustomer) SendCustomerImage(openKfId, toUser, mediaId string) error {
return a.sendCustomerMessage(openKfId, toUser, "image", map[string]interface{}{
"media_id": mediaId,
})
}
func (a *AppCustomer) SendCustomerVoice(openKfId, toUser, mediaId string) error {
return a.sendCustomerMessage(openKfId, toUser, "voice", map[string]interface{}{
"media_id": mediaId,
})
}
func (a *AppCustomer) SendCustomerFile(openKfId, toUser, mediaId string) error {
return a.sendCustomerMessage(openKfId, toUser, "file", map[string]interface{}{
"media_id": mediaId,
})
}
func (a *AppCustomer) sendCustomerMessage(openKfId, toUser, msgtype string, data interface{}) 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{})
params["touser"] = toUser params["touser"] = toUser
params["open_kfid"] = openKfId params["open_kfid"] = openKfId
params["msgtype"] = "text" params["msgtype"] = msgtype
params["text"] = map[string]interface{}{ params[msgtype] = data
"content": content,
}
reqBody, _ := json.Marshal(params) reqBody, _ := json.Marshal(params)
rspBody, err := util.HttpPostJson(reqUrl, nil, reqBody) rspBody, err := util.HttpPostJson(reqUrl, nil, reqBody)
if err != nil { if err != nil {
@ -253,6 +281,7 @@ func (a *AppCustomer) SendCustomerText(openKfId, toUser, content string) error {
} }
return nil return nil
} }
func (a *AppCustomer) SyncMessage(openKfId, cursor, token string) ([]*CustomerMessage, string, error) { func (a *AppCustomer) SyncMessage(openKfId, cursor, token string) ([]*CustomerMessage, string, error) {
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/kf/sync_msg?access_token=%s", a.GetToken()) reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/kf/sync_msg?access_token=%s", a.GetToken())
params := make(map[string]interface{}) params := make(map[string]interface{})