1
This commit is contained in:
121
platformapi/ebaiapi/im.go
Normal file
121
platformapi/ebaiapi/im.go
Normal file
@@ -0,0 +1,121 @@
|
||||
package ebaiapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
IMStoreStatusOnLine = "ONLINE" // 门店im在线状态
|
||||
IMStoreStatusBusy = "BUSY" // 忙碌状态
|
||||
IMType = "IM" // 业务类型,消息默认IM
|
||||
SubTypeDef = "SEND_MESSAGE" // 子业务类型,发送消息。默认值:SEND_MESSAGE
|
||||
ReadIMType = "READ_MESSAGE"
|
||||
|
||||
//消息类型
|
||||
ContentTypeNormal = 1 //普通文本信息
|
||||
ContentTypeAt = 8 //@ 消息
|
||||
|
||||
//门店im状态
|
||||
ImStatusOpen = 1 //开启
|
||||
ImStatusClose = -1 //关闭
|
||||
|
||||
)
|
||||
|
||||
// BusinessSendMsgReq im发送消息
|
||||
type BusinessSendMsgReq struct {
|
||||
PlatformShopId string `json:"platformShopId"` // 平台门店id
|
||||
BizType string `json:"bizType"` // 业务类型,IM消息。默认值:IM
|
||||
SubBizType string `json:"subBizType"` // 子业务类型,发送消息。默认值:SEND_MESSAGE
|
||||
Payload BusinessMsgPayload `json:"payload"`
|
||||
}
|
||||
|
||||
type BusinessMsgPayload struct {
|
||||
GroupId string `json:"groupId"` // 会话ID
|
||||
MsgId string `json:"msgId"` // 消息ID
|
||||
ReceiverIds []string `json:"receiverIds"` // 接收人列表
|
||||
Content string `json:"content"` // 发送内容,格式:JSON {"text":"msg"}
|
||||
ContentType string `json:"contentType"` // 内容类型,目前只支持文本消息。枚举值: 1-普通文本
|
||||
}
|
||||
|
||||
// BusinessSendMsg 门店老板发送消息
|
||||
func (a *API) BusinessSendMsg(param *BusinessSendMsgReq) error {
|
||||
result, err := a.AccessAPI("im.message.send", utils.Struct2MapByJson(param))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.ErrNo != 0 {
|
||||
return errors.New(result.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetStoreIMStatus 获取门店的im状态 1:开启,-1:关闭
|
||||
func (a *API) GetStoreIMStatus(platformShopId string) (string, error) {
|
||||
result, err := a.AccessAPI("im.getIMStatus", map[string]interface{}{"platformShopId": platformShopId})
|
||||
if err != nil {
|
||||
return "0", err
|
||||
}
|
||||
if result.ErrNo != 0 {
|
||||
return "0", errors.New(result.Error)
|
||||
}
|
||||
|
||||
return result.Data.(map[string]interface{})["imStatus"].(string), nil
|
||||
}
|
||||
|
||||
// UpdateIMStatus 更新店铺IM开关状态 1-开启,-1-关闭
|
||||
func (a *API) UpdateIMStatus(platformShopId string, status int) error {
|
||||
result, err := a.AccessAPI("im.updateIMStatus", map[string]interface{}{"platformShopId": platformShopId, "status": status})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.ErrNo != 0 {
|
||||
return errors.New(result.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SettingStoreMsgRead 设置消息已读
|
||||
//func (a *API) SettingStoreMsgRead(platformShopId string, msgId string) error {
|
||||
// result, err := a.AccessAPI("im.message.read", map[string]interface{}{
|
||||
// "platformShopId": platformShopId,
|
||||
// "bizType": IMType,
|
||||
// "subBizType": ReadIMType,
|
||||
// "payload": map[string]string{"msgId": msgId},
|
||||
// })
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if result.ErrNo != 0 {
|
||||
// return errors.New(result.Error)
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
|
||||
// GetImOnlineStatus 获取门店IM线上状态
|
||||
//func (a *API) GetImOnlineStatus(platformShopId string) (int, error) {
|
||||
// result, err := a.AccessAPI("im.getIMOnlineStatus", map[string]interface{}{"platformShopId": platformShopId})
|
||||
// if err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// if result.ErrNo != 0 {
|
||||
// return 0, errors.New(result.Error)
|
||||
// }
|
||||
//
|
||||
// return result.Data.(map[string]interface{})["status"].(int), nil
|
||||
//}
|
||||
|
||||
// SetImOnlineStatus 设置im线上状态 ONLINE - 在线 BUSY - 忙碌
|
||||
//func (a *API) SetImOnlineStatus(platformShopId string, status string) error {
|
||||
// result, err := a.AccessAPI("im.updateIMOnlineStatus", map[string]interface{}{"platformShopId": platformShopId, "status": status})
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if result.ErrNo != 0 {
|
||||
// return errors.New(result.Error)
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
Reference in New Issue
Block a user