1
This commit is contained in:
@@ -12,6 +12,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/gazeboxu/mapstructure"
|
||||
@@ -38,6 +40,7 @@ type ClientManager struct {
|
||||
type Client struct {
|
||||
ClientId string // 标识ID
|
||||
Socket *websocket.Conn // 用户连接
|
||||
ClientType string //标识是美团/客户端长链接
|
||||
ConnectTime uint64 // 首次连接时间
|
||||
IsDeleted bool // 是否删除或下线
|
||||
UserId string // 业务端标识用户ID
|
||||
@@ -132,27 +135,45 @@ type UserRelInfo struct {
|
||||
UserID string `json:"userID"` //用户id/groupID
|
||||
}
|
||||
|
||||
// UrlInfo 生成美团长链接url信息
|
||||
type UrlInfo struct {
|
||||
UrlMain string `json:"urlMain"` //主连接路由
|
||||
ClientIDMain string `json:"ClientIDMain"` //主连接id
|
||||
UrlSub string `json:"urlSub"` //副连接路由
|
||||
ClientIDSub string `json:"ClientIDSub"` //副连接id
|
||||
}
|
||||
|
||||
var (
|
||||
cfg *ini.File
|
||||
rdb = api.Cacher
|
||||
Manager = NewClientManager() // 管理者
|
||||
CommonSetting = &commonConf{}
|
||||
GlobalSetting = &global{}
|
||||
ToClientChan chan clientInfo
|
||||
heartbeatInterval = 60 * time.Second // 心跳间隔
|
||||
HeartCheckMsg = "~#HHHBBB#~" //心跳检测消息
|
||||
HeartCheckSuccess = "HB" //成功发送返回心跳消息
|
||||
VendorIDMT = 10 //im美团
|
||||
VendorIDELM = 11 //im饿了么
|
||||
SendTypeJx = "jx" //京西客户端发送方标识
|
||||
SendTypeMt = "mt" //美团用户发送方标识符
|
||||
SendTypeElm = "elm" //饿了么用户发送方标识符
|
||||
MTIMPushUrl = "wss://wpush.meituan.com/websocket" //buildPushConnect建立长连接
|
||||
cfg *ini.File
|
||||
rdb = api.Cacher
|
||||
//客户端相关
|
||||
Manager = NewClientManager() // 管理者
|
||||
ToClientChan chan clientInfo
|
||||
ClientTypeJx = "jx" //京西客户端
|
||||
ClientTypeMt = "mt" //美团客户端
|
||||
//配置文件
|
||||
CommonSetting = &commonConf{}
|
||||
GlobalSetting = &global{}
|
||||
//心跳相关
|
||||
heartbeatInterval = 60 * time.Second // 心跳间隔
|
||||
HeartCheckMsg = "~#HHHBBB#~" //心跳检测消息
|
||||
HeartCheckSuccess = "HB" //成功发送返回心跳消息
|
||||
HeartSuccessWord = "成功" //成功发送返回心跳消息
|
||||
//平台标识
|
||||
AppID5873 = float64(5873)
|
||||
AppID589 = "589"
|
||||
VendorIDMT = 1 //im美团
|
||||
VendorIDELM = 3 //im饿了么
|
||||
SendTypeJx = "jx" //京西客户端发送方标识
|
||||
SendTypeMt = "mt" //美团用户发送方标识符
|
||||
SendTypeElm = "elm" //饿了么用户发送方标识符
|
||||
MTIMPushUrl = "wss://wpush.meituan.com/websocket" //buildPushConnect建立长连接
|
||||
|
||||
)
|
||||
|
||||
const (
|
||||
ExpireTimeDay = 24 * time.Hour //redis一天过期时间
|
||||
maxMessageSize = 8192 // 最大的消息大小
|
||||
ExpireTimeDay = 2 * time.Hour //redis一天过期时间
|
||||
maxMessageSize = 8192 // 最大的消息大小
|
||||
)
|
||||
|
||||
type renderData struct {
|
||||
@@ -162,7 +183,7 @@ type renderData struct {
|
||||
const (
|
||||
SuccessCode = 0
|
||||
SuccessMsg = "success"
|
||||
Fail = -1
|
||||
FailCode = -1
|
||||
FailMsg = "fail"
|
||||
|
||||
SYSTEM_ID_ERROR = -1001
|
||||
@@ -189,12 +210,13 @@ func Render(conn *websocket.Conn, messageId string, code int, message string, da
|
||||
}
|
||||
}
|
||||
|
||||
func ClientRender(code int, msg string, data interface{}) (str string) {
|
||||
// ClientRender http响应
|
||||
func ClientRender(code int, msg string) (str string) {
|
||||
var retData RetData
|
||||
|
||||
retData.Code = code
|
||||
retData.Msg = msg
|
||||
retData.Data = data
|
||||
//retData.Data = data
|
||||
|
||||
retJson, _ := json.Marshal(retData)
|
||||
str = string(retJson)
|
||||
@@ -272,7 +294,16 @@ func getIntranetIp() string {
|
||||
}
|
||||
|
||||
// GenFullUrl 组装完整websocket url以及生成clientID
|
||||
func GenFullUrl() (fullUrl string) {
|
||||
func GenFullUrl(appID float64) (fullUrl string) {
|
||||
if appID == AppID5873 {
|
||||
if resp5873, err := api.Mtwm2API.GetConnectionToken(); err == nil {
|
||||
r1 := mtwmapi.GetConnTokenResp{}
|
||||
err = mapstructure.Decode(resp5873, &r1)
|
||||
fullUrl = MTIMPushUrl + "/" + r1.AppKey + "/" + r1.ConnectionToken
|
||||
return fullUrl
|
||||
}
|
||||
}
|
||||
//589/4123
|
||||
resp, err := api.MtwmAPI.GetConnectionToken()
|
||||
if err != nil {
|
||||
return ""
|
||||
@@ -280,13 +311,48 @@ func GenFullUrl() (fullUrl string) {
|
||||
retVal := mtwmapi.GetConnTokenResp{}
|
||||
err = mapstructure.Decode(resp, &retVal)
|
||||
fullUrl = MTIMPushUrl + "/" + retVal.AppKey + "/" + retVal.ConnectionToken
|
||||
//clientID = api.MtwmAPI.GetAppID() + ":" + retVal.ConnectionToken
|
||||
//打印输出
|
||||
//fmt.Printf("Create websocket connect failCount:%d", retVal.UserCount)
|
||||
|
||||
//todo 测试
|
||||
tete := api.MtwmAPI.GetAppID()
|
||||
globals.SugarLogger.Debugf("GenFullUrl appID=%s", tete)
|
||||
//todo
|
||||
|
||||
fmt.Printf("GenFullUrl:%s", fullUrl)
|
||||
return fullUrl
|
||||
}
|
||||
|
||||
//生成随机字符串
|
||||
// GenFullUrl2 组装完整websocket url以及生成clientID
|
||||
func GenFullUrl2() *UrlInfo {
|
||||
urlInfo := &UrlInfo{}
|
||||
//1 589/4123
|
||||
resp, err := api.MtwmAPI.GetConnectionToken()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
retVal := mtwmapi.GetConnTokenResp{}
|
||||
err = mapstructure.Decode(resp, &retVal)
|
||||
urlInfo.UrlMain = MTIMPushUrl + "/" + retVal.AppKey + "/" + retVal.ConnectionToken
|
||||
urlInfo.ClientIDMain = retVal.AppKey + ":" + retVal.ConnectionToken
|
||||
|
||||
if api.MtwmAPI.GetAppID() == AppID589 { //目前果园无4123
|
||||
if resp5873, err := api.Mtwm2API.GetConnectionToken(); err == nil {
|
||||
r1 := mtwmapi.GetConnTokenResp{}
|
||||
err = mapstructure.Decode(resp5873, &r1)
|
||||
urlInfo.UrlSub = MTIMPushUrl + "/" + r1.AppKey + "/" + r1.ConnectionToken
|
||||
urlInfo.ClientIDSub = r1.AppKey + ":" + r1.ConnectionToken
|
||||
}
|
||||
}
|
||||
|
||||
//todo 测试
|
||||
tete := api.MtwmAPI.GetAppID()
|
||||
globals.SugarLogger.Debugf("GenFullUrl appID=%s", tete)
|
||||
//todo
|
||||
|
||||
fmt.Printf("GenFullUrl:urlMain=%s, urlSub=%s", urlInfo.UrlMain, urlInfo.UrlSub)
|
||||
return urlInfo
|
||||
}
|
||||
|
||||
// RandString 生成随机字符串
|
||||
func RandString() string {
|
||||
bytes := make([]byte, 16)
|
||||
for i := 0; i < 16; i++ {
|
||||
|
||||
Reference in New Issue
Block a user