96 lines
5.2 KiB
Go
96 lines
5.2 KiB
Go
package mtwmapi
|
||
|
||
import "net/url"
|
||
|
||
const (
|
||
MsgSourceStore = 1 //商家
|
||
MsgSourceUser = 2 //用户
|
||
MsgTypeText = 1 //文字
|
||
MsgTypePic = 2 //图片
|
||
MsgTypeVoice = 3 //语音
|
||
MsgTypeGoodsCard = 4 //商品卡片
|
||
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"` //调用接口时的时间戳,即当前时间戳(当前距离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 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"` //错误描述
|
||
}
|
||
|
||
// 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,
|
||
})
|
||
//fmt.Println(retVal)
|
||
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
|
||
}
|
||
|
||
// 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
|
||
}
|