1
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"io"
|
||||
"net/http/httptest"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -25,46 +24,6 @@ const (
|
||||
TestWssUrl1 = "wss://www-jxgy.jxc4.com:443/v2/im/StartWebSocket"
|
||||
)
|
||||
|
||||
type ClientManager struct {
|
||||
ClientIdMap map[string]*Client // 全部的连接
|
||||
ClientIdMapLock sync.RWMutex // 读写锁
|
||||
|
||||
Connect chan *Client // 连接处理
|
||||
DisConnect chan *Client // 断开连接处理
|
||||
|
||||
GroupLock sync.RWMutex
|
||||
Groups map[string][]string
|
||||
|
||||
//SystemClientsLock sync.RWMutex
|
||||
//SystemClients map[string][]string
|
||||
Clients map[string]*Client // 保存连接
|
||||
Accounts map[string][]string // 账号和连接关系,map的key是账号id即:AccountId,这里主要考虑到一个账号多个连接
|
||||
mu *sync.Mutex
|
||||
}
|
||||
|
||||
var Manager = NewClientManager()
|
||||
|
||||
func NewClientManager() (clientManager *ClientManager) {
|
||||
clientManager = &ClientManager{
|
||||
Accounts: make(map[string][]string),
|
||||
ClientIdMap: make(map[string]*Client, 100),
|
||||
Connect: make(chan *Client, 10000),
|
||||
DisConnect: make(chan *Client, 10000),
|
||||
mu: new(sync.Mutex),
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var RegisterChan = make(chan *Client, 100)
|
||||
|
||||
type Client struct {
|
||||
ID string // 连接ID
|
||||
AccountId string // 账号id, 一个账号可能有多个连接
|
||||
Socket *websocket.Conn // 连接
|
||||
HeartbeatTime int64 // 前一次心跳时间
|
||||
}
|
||||
|
||||
var rdb = redis.NewClient(&redis.Options{
|
||||
//Addr: "www.jxc4.com:6379",
|
||||
//Password: "",
|
||||
@@ -73,36 +32,21 @@ var rdb = redis.NewClient(&redis.Options{
|
||||
DB: 0,
|
||||
})
|
||||
|
||||
type TestStr struct {
|
||||
VendorID int `json:"vendorID"` //平台品牌 10-美团 11-饿了么
|
||||
UserID int `json:"userID"` //用户ID
|
||||
NewMessageNum int `json:"NewMessageNum"` //新消息数量
|
||||
LatestMsg string `json:"latestMsg"` //最新一条消息
|
||||
LatestTime int `json:"latestTime"` //最新一条消息发送时间
|
||||
}
|
||||
|
||||
func TestCacher_RPush(t *testing.T) {
|
||||
//ans := TestStr{
|
||||
// VendorID: 22,
|
||||
// UserID: 2222222222,
|
||||
// NewMessageNum: 222,
|
||||
// LatestMsg: "22222222222",
|
||||
// LatestTime: 22222222222,
|
||||
//}
|
||||
//str, _ := json.Marshal(ans)
|
||||
//err := rdb.RPush("test", string(str))
|
||||
keys := []string{"589:7954977:10", "test"}
|
||||
retVal := make(map[string][]interface{}, 0)
|
||||
for _, key := range keys {
|
||||
temp := rdb.LRange(key, 0, -1).Val()
|
||||
for _, v := range temp {
|
||||
retVal[key] = append(retVal[key], v)
|
||||
}
|
||||
func TestSendMsg(t *testing.T) {
|
||||
data := PushContentReq{
|
||||
AppID: 589,
|
||||
AppPoiCode: "8694203",
|
||||
MsgID: 20230615,
|
||||
MsgContent: "QYEyt4edHFiW0Fg0iKqeSKZ+Dab9zKJWSLwQuE38J+XL/1BUIwkqy3sf3E9lOK77",
|
||||
MsgSource: 1,
|
||||
MsgType: 1,
|
||||
Cts: int(time.Now().Unix()),
|
||||
OpenUserID: 12248014636,
|
||||
}
|
||||
fmt.Printf("%s", utils.Format4Output(retVal, false))
|
||||
//if err != nil {
|
||||
// fmt.Print(err)
|
||||
//}
|
||||
dataMar, err := json.Marshal(data)
|
||||
|
||||
ret, err := api.MsgSend(string(dataMar))
|
||||
fmt.Println(ret, err)
|
||||
}
|
||||
|
||||
//测试心跳
|
||||
@@ -161,18 +105,6 @@ func TestGetConnectionToken(t *testing.T) {
|
||||
fmt.Println(utils.Format4Output(retVal, false))
|
||||
}
|
||||
|
||||
//解密测试
|
||||
func TestAesCBCDecrypt(t *testing.T) {
|
||||
secret := "a81eb3df418d83d6a1a4b7c572156d2f"
|
||||
key := secret[:16]
|
||||
str := "qodhoVd4IGtgPKrvYwq6QrzBecJZkeSUPYR88iGRUsCRFmCFxDHpUhqsbBztNXQx"
|
||||
//str := "Vv+Y/K8vfS42W+P7xq26aIb6uoaG/nL0ZoMMXpitc5QQ3XJm3Roh10NuSoojYrG/3JZwbzgtYA+kBvodoY2eJV00f9MBY+kLkxToP+aSofsYva9tHbipvjVtexebc+eP7aQMtzbwU4BNNnuRG6e7TkXP+BLdtiGsyvHolGfky+p2fZgWes9R6JIxkuRCXW/yBhUo8F+wWCZ2YQl/szp5lHJ3cmneD6cwem36E0FBcvxZNB9an4pRkBrqi1p43V8QBLO719oXkQ+dqTqJMi1/xDSBrCDYN8QORnARP8+j1oDuqE34Kklcse4WL9rwTJ2sOmOu/O2h6Gx3ZaFaMaWRXBDYv8JpzTZjCbRrLSENlEHTof29BmvXTJ0QZ7qi6iAD"
|
||||
data, err := Decrypt(str, []byte(key))
|
||||
//data, err := DecryptAES(key, str)
|
||||
fmt.Println(data)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
var wsList []*websocket.Conn
|
||||
|
||||
type RetData struct {
|
||||
@@ -285,28 +217,6 @@ func TestNewRedis(t *testing.T) {
|
||||
//rdb.RPush(key, param)
|
||||
}
|
||||
|
||||
// 根据账号获取连接
|
||||
func TestGetClient(t *testing.T) {
|
||||
accountId := "QW+r2FtsRKGGLJnlgyDNlChzcKcSZ8Kfgh0qw//ONuQCDKzky4x+nlbnx3k1JX13"
|
||||
clients := make([]*Client, 0)
|
||||
|
||||
Manager.mu.Lock()
|
||||
defer Manager.mu.Unlock()
|
||||
|
||||
if len(Manager.Accounts[accountId]) > 0 {
|
||||
for _, clientId := range Manager.Accounts[accountId] {
|
||||
if c, ok := Manager.Clients[clientId]; ok {
|
||||
clients = append(clients, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf(utils.Format4Output(clients, false))
|
||||
}
|
||||
func TestMal(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestGetWayBillFee(t *testing.T) {
|
||||
//order, _ := api.OrderGetOrderDetail(1100486451772280163, false)
|
||||
//globals.SugarLogger.Debugf("order:==%s", utils.Format4Output(order, false)) 2002
|
||||
|
||||
Reference in New Issue
Block a user