This commit is contained in:
richboo111
2023-08-31 15:06:41 +08:00
parent 4054cb523d
commit 0395ee4617
5 changed files with 49 additions and 58 deletions

View File

@@ -1,8 +1,14 @@
package mtwmapi
import "net/url"
import (
"git.rosy.net.cn/baseapi/utils"
"net/url"
)
const (
ImStatusOpen = 1 //开启
ImStatusClose = 0 //关闭
MsgSourceStore = 1 //商家
MsgSourceUser = 2 //用户
MsgTypeText = 1 //文字
@@ -12,27 +18,6 @@ const (
MsgTypeOrderCard = 5 //订单卡片
)
// SingleChat 单聊信息体
type SingleChat struct {
AppID int `json:"app_id"` //应用标识
AppPoiCode string `json:"app_poi_code"` //门店标识
Cts int `json:"cts"` //消息发送时间,10位时间戳
MsgContent string `json:"msg_content"` //消息内容
MsgID int `json:"msg_id"` //消息id确保消息唯一性发送消息时为三方的消息id接收消息时为美团的消息id
MsgSource int `json:"msg_source"` //消息发送方 商家1用户2
MsgType int `json:"msg_type"` //消息类型: 文字-1; 图片-2;语音-3注意b2c不支持语音; 商品卡片-4发送商品卡片类型则不关注msg_content; 订单卡片-5订单卡片类型商家只能接收消息不支持给用户发送消息只支持单聊
OpenUserID int `json:"open_user_id"` //用户id
OrderID int `json:"order_id"` // 订单id
AppSpuCodes string `json:"app_spu_codes"` //开放平台侧商品标识(无须加密)
}
// GetConnTokenResp 获取长链接token返回参数
type GetConnTokenResp struct {
ConnectionToken string `json:"connectionToken"` //建立长连接的token
UserCount int `json:"userCount"` //30分钟内消息发送失败的用户数
AppKey string `json:"appKey"` //建立长连接的appkey
}
// ImCallbackMsg im消息回调参数
type ImCallbackMsg struct {
Timestamp int `json:"timestamp"` //调用接口时的时间戳即当前时间戳当前距离Epoch1970年1月1日) 以秒计算的时间即unix - timestamp注意传输时间戳与当前北京时间前后相差不能超过10分钟
@@ -59,14 +44,10 @@ type PushContentReq struct {
AppSpuCodes string `json:"app_spu_codes"` //开放平台侧商品标识(无须加密)
}
type PushContentResp struct {
ResultCode int `json:"result_code"` //1-全部操作成功查询到的数据在data字段中2-部分成功成功的数据存储在data字段中失败的数据存在error_list字段中3-全部操作失败失败的数据存在error_list字段中4-请求失败一般为签名或限流问题关注error字段中的具体描述即可
ErrorList []ErrorList `json:"error_list"` //返回失败原因,根据失败原因判断是否重发消息
}
type ErrorList struct {
Code int `json:"code"` //错误码
Msg string `json:"msg"` //错误描述
type GetPoiIMStatusResp struct {
AppPoiCode string `json:"app_poi_code"`
AppID int `json:"app_id"`
ImStatus int `json:"im_status"`
}
// MsgSend 商家发送IM消息 https://open-shangou.meituan.com/home/docDetail/10087
@@ -78,11 +59,23 @@ func (a *API) MsgSend(pushContent string) (interface{}, error) {
return retVal, err
}
// GetConnectionToken 获取长连接的token https://developer.waimai.meituan.com/home/docDetail/461
//func (a *API) GetConnectionToken() (retVal interface{}, err error) {
// retVal, err = a.AccessAPI("wm/IM/getConnectionToken", false, nil)
// return retVal, err
//}
//设置门店IM线上状态
func (a *API) SetPoiIMOnlineStatus(appPoiCode string, onlineStatus int) error {
_, err := a.AccessAPI("wm/IM/setPoiIMOnlineStatus", false, map[string]interface{}{
"app_poi_code": appPoiCode,
"online_status": onlineStatus,
})
return err
}
// GetPoiIMStatus 查询门店IM单聊开关状态
func (a *API) GetPoiIMStatus(appPoiCode string) (retVal GetPoiIMStatusResp, err error) {
resp, err := a.AccessAPI("wm/IM/getPoiIMStatus", false, map[string]interface{}{
"app_poi_code": appPoiCode,
})
utils.Map2StructByJson(resp, &retVal, false)
return retVal, err
}
// MsgRead 设置消息已读 https://open-shangou.meituan.com/home/docDetail/465
//func (a *API) MsgRead(appPoiCode string, msgID, openUserID int) error {