115 lines
4.5 KiB
Go
115 lines
4.5 KiB
Go
package mtwmapi
|
||
|
||
import (
|
||
"fmt"
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
"net/url"
|
||
)
|
||
|
||
const (
|
||
ImStatusOpen = 1 //单聊状态开启
|
||
ImStatusClose = 0 //关闭
|
||
|
||
OnlineStatusBusy = 1 //忙碌
|
||
OnlineStatusOnline = 0 //在线
|
||
|
||
MsgSourceStore = 1 //商家
|
||
MsgSourceUser = 2 //用户
|
||
MsgTypeText = 1 //文字
|
||
MsgTypePic = 2 //图片
|
||
MsgTypeVoice = 3 //语音
|
||
MsgTypeGoodsCard = 4 //商品卡片
|
||
MsgTypeOrderCard = 5 //订单卡片
|
||
)
|
||
|
||
// ImCallbackMsg im消息回调参数
|
||
type ImCallbackMsg struct {
|
||
Timestamp int `json:"timestamp"` //调用接口时的时间戳,即当前时间戳(当前距离Epoch(1970年1月1日) 以秒计算的时间,即unix - timestamp),注意传输时间戳与当前北京时间前后相差不能超过10分钟
|
||
AppID string `json:"app_id"`
|
||
Sig string `json:"sig"`
|
||
FormData url.Values
|
||
BizType int `json:"biz_type"` //业务类型字段:1:单聊,2:群聊
|
||
PushContent interface{} `json:"push_content"` //消息体详细内容
|
||
}
|
||
|
||
// PushContentReq msgSend商家发送IM消息
|
||
type PushContentReq struct {
|
||
AppID int `json:"app_id"` //美团分配给APP方的id
|
||
AppPoiCode string `json:"app_poi_code"` //APP方门店id,最长不超过128个字符
|
||
MsgID int `json:"msg_id"` //消息id,确保消息唯一性,发送消息时,为三方的消息id,接收消息时,为美团的消息id
|
||
MsgContent string `json:"msg_content"` //消息内容,需要进行加密。加密方式:使用AES加密算法,加密解密的秘钥取自开放平台APP的secret的前16位,请自行截取。 加密工具:http://tool.chacuo.net/cryptaes
|
||
MsgSource int `json:"msg_source"` //消息发送方,1:商家,2:用户
|
||
MsgType int `json:"msg_type"` //消息类型,1:文字,2:图片,3:语音,注意b2c不支持语音,4:商品卡片,发送商品卡片类型则不关注msg_content,5:订单卡片类型商家只能接收消息,不支持给用户发送消息,只支持单聊 11:群文字,12:群图片,13:群语音,注意b2c不支持语音,14:群商品卡片 其中商品卡片单次最多传7个商品
|
||
Cts int `json:"cts"` //消息发送时间,10位时间戳
|
||
//非必填
|
||
OpenUserID int `json:"open_user_id"` //用户id,单聊时必传
|
||
OrderID int `json:"order_id"` //订单id
|
||
GroupID int `json:"group_id"` //群聊id,发送群聊消息时必传
|
||
AppSpuCodes string `json:"app_spu_codes"` //开放平台侧商品标识(无须加密)
|
||
}
|
||
|
||
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
|
||
func (a *API) MsgSend(pushContent string) (interface{}, error) {
|
||
retVal, err := a.AccessAPI("ecommerce/IM/msgSend", false, map[string]interface{}{
|
||
"push_content": pushContent,
|
||
})
|
||
return retVal, err
|
||
}
|
||
|
||
// SetPoiIMStatus 设置门店IM线上状态 0-关闭 1-开启
|
||
func (a *API) SetPoiIMStatus(appPoiCode string, imStatus int) error {
|
||
_, err := a.AccessAPI("wm/IM/setPoiIMStatus", false, map[string]interface{}{
|
||
"app_poi_code": appPoiCode,
|
||
"im_status": imStatus,
|
||
})
|
||
return err
|
||
}
|
||
|
||
// SetPoiIMOnlineStatus 设置门店IM线上状态 0-在线或1-忙碌
|
||
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
|
||
}
|
||
|
||
// QueryHistory 查询历史消息
|
||
func (a *API) QueryHistory(start, end int64) {
|
||
resp, err := a.AccessAPI("ecommerce/IM/historyMsg/list", false, map[string]interface{}{
|
||
"type": 1,
|
||
"start_time": start,
|
||
"end_time": end,
|
||
"page_num": 1,
|
||
"page_size": 20,
|
||
})
|
||
fmt.Println(resp)
|
||
fmt.Println(err)
|
||
return
|
||
}
|
||
|
||
// MsgRead 设置消息已读 https://open-shangou.meituan.com/home/docDetail/465
|
||
//func (a *API) MsgRead(appPoiCode string, msgID, openUserID int) error {
|
||
// _, err := a.AccessAPI("/wm/IM/msgRead", false, map[string]interface{}{
|
||
// "app_poi_code": appPoiCode,
|
||
// "msg_id": msgID,
|
||
// "open_user_id": openUserID,
|
||
// })
|
||
// return err
|
||
//}
|