Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
7807033c1a
|
@ -114,6 +114,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
|
||||||
rsp[mapKey] = map[string]interface{}{
|
rsp[mapKey] = map[string]interface{}{
|
||||||
"id": templateInfo.Id,
|
"id": templateInfo.Id,
|
||||||
"material": *templateInfo.MaterialImg,
|
"material": *templateInfo.MaterialImg,
|
||||||
|
//写死的数据
|
||||||
"material_data": map[string]interface{}{
|
"material_data": map[string]interface{}{
|
||||||
"QRcode": map[string]interface{}{
|
"QRcode": map[string]interface{}{
|
||||||
"if_show": true,
|
"if_show": true,
|
||||||
|
|
|
@ -79,7 +79,12 @@ type wsConnectItem struct {
|
||||||
renderProperty renderProperty //扩展云渲染属性
|
renderProperty renderProperty //扩展云渲染属性
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 请求建立连接,升级websocket协议
|
||||||
func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) {
|
func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) {
|
||||||
|
//把子协议携带的token设置到标准token头信息中
|
||||||
|
r.Header.Set("Authorization", "Bearer "+r.Header.Get("Sec-Websocket-Protocol"))
|
||||||
|
//设置Sec-Websocket-Protocol
|
||||||
|
upgrade.Subprotocols = []string{r.Header.Get("Sec-Websocket-Protocol")}
|
||||||
//升级websocket
|
//升级websocket
|
||||||
conn, err := upgrade.Upgrade(w, r, nil)
|
conn, err := upgrade.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -88,13 +93,13 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
//鉴权不成功后断开
|
//鉴权不成功后断开
|
||||||
/*var (
|
var (
|
||||||
userInfo *auth.UserInfo
|
userInfo *auth.UserInfo
|
||||||
isAuth bool
|
isAuth bool
|
||||||
)
|
)
|
||||||
isAuth, userInfo = l.checkAuth(r)
|
isAuth, userInfo = l.checkAuth(r)
|
||||||
if !isAuth {
|
if !isAuth {
|
||||||
time.Sleep(time.Second * 1) //兼容下火狐
|
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
|
||||||
rsp := websocket_data.DataTransferData{
|
rsp := websocket_data.DataTransferData{
|
||||||
T: constants.WEBSOCKET_UNAUTH,
|
T: constants.WEBSOCKET_UNAUTH,
|
||||||
D: nil,
|
D: nil,
|
||||||
|
@ -105,12 +110,9 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
|
||||||
//发送关闭信息
|
//发送关闭信息
|
||||||
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
||||||
return
|
return
|
||||||
}*/
|
}
|
||||||
// todo user信息是没有的
|
|
||||||
var userInfo auth.UserInfo
|
|
||||||
userInfo.UserId = 39
|
|
||||||
//设置连接
|
//设置连接
|
||||||
ws := l.setConnPool(conn, userInfo)
|
ws := l.setConnPool(conn, *userInfo)
|
||||||
defer ws.close()
|
defer ws.close()
|
||||||
//循环读客户端信息
|
//循环读客户端信息
|
||||||
go ws.readLoop()
|
go ws.readLoop()
|
||||||
|
@ -151,7 +153,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
|
||||||
mapConnPool.Store(uniqueId, ws)
|
mapConnPool.Store(uniqueId, ws)
|
||||||
go func() {
|
go func() {
|
||||||
//把连接成功消息发回去
|
//把连接成功消息发回去
|
||||||
time.Sleep(time.Second * 1) //兼容下火狐
|
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
|
||||||
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId))
|
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId))
|
||||||
}()
|
}()
|
||||||
return ws
|
return ws
|
||||||
|
@ -178,6 +180,7 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a
|
||||||
claims, err := l.svcCtx.ParseJwtToken(r)
|
claims, err := l.svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
if claims != nil {
|
if claims != nil {
|
||||||
|
@ -185,6 +188,7 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a
|
||||||
userInfo, err = auth.GetUserInfoFormMapClaims(claims)
|
userInfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
//不是登录用户也不是游客
|
//不是登录用户也不是游客
|
||||||
|
|
Loading…
Reference in New Issue
Block a user