104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
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 //@ 消息
|
||
)
|
||
|
||
// 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
|
||
}
|
||
|
||
// 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
|
||
}
|
||
|
||
// GetStoreIMStatus 获取门店的im状态(这个应该不怎么用)
|
||
func (a *API) GetStoreIMStatus(platformShopId string) (int, 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"].(int), 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
|
||
}
|