108 lines
3.8 KiB
Go
108 lines
3.8 KiB
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
|
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/im"
|
|
"github.com/astaxie/beego/server/web"
|
|
)
|
|
|
|
type IMController struct {
|
|
web.Controller
|
|
}
|
|
|
|
// @Title IM初始化长链接
|
|
// @Description IM初始化长链接
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /StartWebSocket [get]
|
|
func (c *IMController) StartWebSocket() {
|
|
ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
|
|
//ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, &http.Request{
|
|
// Method: "GET",
|
|
// Header: http.Header{
|
|
// "Upgrade": []string{"websocket"},
|
|
// "Connection": []string{"upgrade"},
|
|
// "Sec-Websocket-Key": []string{"dGhlIHNhbXBsZSBub25jZQ=="},
|
|
// "Sec-Websocket-Version": []string{"13"},
|
|
// }}, nil)
|
|
if err != nil {
|
|
globals.SugarLogger.Errorf("upgrade error: %v", err)
|
|
return
|
|
}
|
|
defer ws.Close()
|
|
|
|
clientID := c.GetString("clientID")
|
|
globals.SugarLogger.Debugf("clientID=%s", clientID)
|
|
im.StartWebSocket(ws, clientID, err)
|
|
}
|
|
|
|
// @Title IM获取门店用户聊天列表
|
|
// @Description IM获取门店用户聊天列表
|
|
// @Param token header string true "认证token"
|
|
// @Param payLoad formData string true "平台应用映射关系"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /GetIMUserList [get]
|
|
func (c *IMController) GetIMUserList() {
|
|
c.callGetIMUserList(func(params *tImGetIMUserListParams) (retVal interface{}, errCode string, err error) {
|
|
var relInfo []im.RelInfo
|
|
if err = json.Unmarshal([]byte(params.PayLoad), &relInfo); err != nil {
|
|
retVal, err = im.GetImUserList(relInfo)
|
|
}
|
|
return retVal, "", err
|
|
})
|
|
}
|
|
|
|
// @Title IM获取单个用户聊天详情
|
|
// @Description IM获取单个用户聊天详情
|
|
// @Param token header string true "认证token"
|
|
// @Param payLoad formData string true "平台用户应用映射关系"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /GetImChatDetail [get]
|
|
func (c *IMController) GetImChatDetail() {
|
|
c.callGetImChatDetail(func(params *tImGetImChatDetailParams) (retVal interface{}, errCode string, err error) {
|
|
var temp []im.UserRelInfo
|
|
if err = json.Unmarshal([]byte(params.PayLoad), &temp); err == nil {
|
|
retVal, err = im.GetImChatDetail(temp)
|
|
}
|
|
return retVal, "", err
|
|
})
|
|
}
|
|
|
|
// @Title IM设置门店与单个用户已读
|
|
// @Description IM设置门店与单个用户已读
|
|
// @Param token header string true "认证token"
|
|
// @Param appID formData string true "应用id"
|
|
// @Param vendorStoreID formData string true "平台门店id"
|
|
// @Param vendorID formData string true "平台id"
|
|
// @Param userID formData string true "用户id/会话id"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /SetImMsgRead [post]
|
|
func (c *IMController) SetImMsgRead() {
|
|
c.callSetImMsgRead(func(params *tImSetImMsgReadParams) (retVal interface{}, errCode string, err error) {
|
|
err = im.SetJxMsgRead(params.AppID, params.VendorStoreID, params.VendorID, params.UserID)
|
|
return nil, "", err
|
|
})
|
|
}
|
|
|
|
// @Title 向平台商发送信息
|
|
// @Description 向平台商发送信息
|
|
// @Param token header string true "认证token"
|
|
// @Param sendData formData string true "平台商消息结构体"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /SendToVendor [post]
|
|
//func (c *IMController) SendToVendor() {
|
|
// c.callSendToVendor(func(params *tImSendToVendorParams) (retVal interface{}, errCode string, err error) {
|
|
// var sendData im.SendData
|
|
// if err = json.Unmarshal([]byte(params.SendData), &sendData); err == nil {
|
|
// im.SendToVendor(sendData)
|
|
// }
|
|
// return nil, "", err
|
|
// })
|
|
//}
|