1
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/gazeboxu/mapstructure"
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/gorilla/websocket"
|
||||
"io"
|
||||
"net/http/httptest"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -17,9 +19,10 @@ const (
|
||||
TestAppID = "589_WMOPEN"
|
||||
TestToken = "wo589i4VsZHFH2fh4uVsr6Dtc3k6vG8Xu0vxpreBQFy6QAvg"
|
||||
|
||||
TestMTIMPushUrl = "wss://wpush.meituan.com/websocket/589_WMOPEN/wo589i4VsZHFH2fh4uVsr6Dtc3k6vG8Xu0vxpreBQFy6QAvg"
|
||||
TestWssUrl = "wss://www.jxc4.com:443/v2/event/TestWebsocket"
|
||||
TestWssUrl1 = "wss://www-jxgy.jxc4.com:443/v2/im/StartWebSocket"
|
||||
TestMTIM589 = "wss://wpush.meituan.com/websocket/589_WMOPEN/wo589i4VsZHFH2fh4uVsr6Dtc3k6vG8Xu0vxpreBQFy6QAvg"
|
||||
TestMTIM4123 = "wss://wpush.meituan.com/websocket/4123_WMOPEN/wo4123aAVXDUkZDYucMoTDAZgsMzjrR_porZcLGv2GmWRNOiw"
|
||||
TestWssUrl = "wss://www.jxc4.com:443/v2/event/TestWebsocket"
|
||||
TestWssUrl1 = "wss://www-jxgy.jxc4.com:443/v2/im/StartWebSocket"
|
||||
)
|
||||
|
||||
type ClientManager struct {
|
||||
@@ -70,29 +73,81 @@ 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)
|
||||
}
|
||||
}
|
||||
fmt.Printf("%s", utils.Format4Output(retVal, false))
|
||||
//if err != nil {
|
||||
// fmt.Print(err)
|
||||
//}
|
||||
}
|
||||
|
||||
//测试心跳
|
||||
func TestHeartCheck(t *testing.T) {
|
||||
//go func() {
|
||||
// ticker := time.NewTicker(5 * time.Second)
|
||||
// defer ticker.Stop()
|
||||
// for {
|
||||
// <-ticker.C
|
||||
//发送心跳
|
||||
var clientID = make(map[string]*websocket.Conn)
|
||||
//conn, resp, err := websocket.DefaultDialer.Dial(TestMTIMPushUrl, nil)
|
||||
//conn, resp, err := websocket.DefaultDialer.Dial(TestWssUrl, nil)
|
||||
conn, resp, err := websocket.DefaultDialer.Dial(TestWssUrl1, nil)
|
||||
fmt.Println(resp, err)
|
||||
err1 := conn.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(time.Second))
|
||||
|
||||
//str := "~#HHhehHBBB#~"
|
||||
//data := []byte(str)
|
||||
conn1, resp1, err1 := websocket.DefaultDialer.Dial(TestMTIM4123, nil)
|
||||
fmt.Println(conn1, resp1, err1)
|
||||
clientID["1"] = conn1
|
||||
|
||||
conn, resp, err := websocket.DefaultDialer.Dial(TestMTIM589, nil)
|
||||
clientID["2"] = conn
|
||||
fmt.Println(conn, resp, err)
|
||||
|
||||
if err != nil || resp.StatusCode != 101 {
|
||||
fmt.Printf("连接失败:%v http响应不成功", err)
|
||||
}
|
||||
//关闭
|
||||
defer func(conn *websocket.Conn) {
|
||||
err := conn.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}(conn)
|
||||
|
||||
if err := conn.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(time.Second)); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
//err = conn.WriteMessage(websocket.TextMessage, data)
|
||||
//if err != nil {
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
|
||||
for {
|
||||
_, msg, err := conn.ReadMessage()
|
||||
if err != nil {
|
||||
temp := string(msg)
|
||||
if err != nil || temp != "HB" {
|
||||
break
|
||||
}
|
||||
fmt.Printf("%s receive: %s\n", conn.RemoteAddr(), string(msg))
|
||||
}
|
||||
fmt.Println(err1)
|
||||
//}
|
||||
//}()
|
||||
}
|
||||
|
||||
func TestGetConnectionToken(t *testing.T) {
|
||||
@@ -120,81 +175,34 @@ func TestAesCBCDecrypt(t *testing.T) {
|
||||
|
||||
var wsList []*websocket.Conn
|
||||
|
||||
func sendmsg() {
|
||||
for _, conn := range wsList {
|
||||
if err := conn.WriteMessage(websocket.TextMessage, []byte("~#HHHBBB#~")); err != nil {
|
||||
fmt.Printf("%s", err) //"use of closed network connection"
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestPut(t *testing.T) {
|
||||
fmt.Println(wsList)
|
||||
type RetData struct {
|
||||
Code int `json:"code"` //响应code
|
||||
Msg string `json:"msg"` //响应msg success/fail
|
||||
Data interface{} `json:"data"` //信息
|
||||
}
|
||||
|
||||
func TestWebSocketClient(t *testing.T) {
|
||||
//发送webSocket请求
|
||||
conn, resp, err := websocket.DefaultDialer.Dial(TestMTIMPushUrl, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("连接失败:%v", err)
|
||||
}
|
||||
fmt.Printf("响应:%s", fmt.Sprint(resp))
|
||||
//wsList = append(wsList, conn)
|
||||
//关闭
|
||||
conn.SetCloseHandler(func(code int, text string) error {
|
||||
fmt.Printf("WebSocket connection closed with code %d and text: %s\n", code, text)
|
||||
return nil
|
||||
})
|
||||
defer func(conn *websocket.Conn) {
|
||||
err := conn.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}(conn)
|
||||
var retData RetData
|
||||
|
||||
//赋入全局变量
|
||||
//Default(conn)
|
||||
//生成clientID
|
||||
clientID := GenClientId()
|
||||
retData.Code = 0
|
||||
retData.Msg = "success"
|
||||
retData.Data = "发送信息成功"
|
||||
|
||||
//创建实例连接
|
||||
client := &Client{
|
||||
ID: clientID,
|
||||
//AccountId:conn. ,
|
||||
Socket: conn,
|
||||
HeartbeatTime: time.Now().Unix(),
|
||||
}
|
||||
//rdb.Set("testPush", client, 0)
|
||||
|
||||
//注册到连接管理
|
||||
RegisterChan <- client
|
||||
//todo 暂时不确定放哪
|
||||
//go Start()
|
||||
|
||||
done := make(chan SingleChat)
|
||||
//err = conn.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(time.Second))
|
||||
err = conn.WriteMessage(websocket.TextMessage, []byte("~#HHHBBB#~"))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
for {
|
||||
_, msg, err := conn.ReadMessage()
|
||||
if err != nil {
|
||||
//log.Fatal(err)
|
||||
break
|
||||
}
|
||||
fmt.Printf("%s receive: %s\n", conn.RemoteAddr(), string(msg))
|
||||
}
|
||||
<-done
|
||||
retJson, _ := json.Marshal(retData)
|
||||
str := string(retJson)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
_, _ = io.WriteString(w, str)
|
||||
return
|
||||
}
|
||||
|
||||
func TestPUSH(t *testing.T) {
|
||||
key := "589:7954977:10"
|
||||
//rdb.RPush(key, "1111111111")
|
||||
rdb.RPush(key, "1111111111")
|
||||
//rdb.RPush(key, "{\"vendorID\":10,\"userID\":11158569333,\"NewMessageNum\":3,\"latestMsg\":\"hhhhhhhhhhh\",\"latestTime\":1681983980}")
|
||||
//rdb.RPush(key, "{\"vendorID\":10,\"userID\":11158569333,\"NewMessageNum\":3,\"latestMsg\":\"oooooooooo\",\"latestTime\":1681983980}")
|
||||
//rdb.RPush(key, "2222222222222")
|
||||
rdb.RPush(key, "{\"vendorID\":10,\"userID\":11158569333,\"NewMessageNum\":3,\"latestMsg\":\"oooooooooo\",\"latestTime\":1681983980}")
|
||||
rdb.RPush(key, "2222222222222")
|
||||
rdb.RPush(key, "{\"vendorID\":10,\"userID\":11158569333,\"NewMessageNum\":4,\"latestMsg\":\"成功插入新数据,看下cnt\",\"latestTime\":1681983980}")
|
||||
rdb.RPush(key, "{\"vendorID\":10,\"userID\":11158569333,\"NewMessageNum\":5,\"latestMsg\":\"成功插入新数据,看下cnt\",\"latestTime\":1681983980}")
|
||||
}
|
||||
@@ -209,43 +217,72 @@ type UserMessageList struct {
|
||||
}
|
||||
|
||||
func TestNewRedis(t *testing.T) {
|
||||
var flag = 11158569333
|
||||
var key = "589:7954977:10"
|
||||
s2 := rdb.LRange(key, 0, -1).Val()
|
||||
fmt.Printf("before len %d\n", len(s2))
|
||||
fmt.Printf("before ans %s\n", s2)
|
||||
cnt := 0
|
||||
n := rdb.Exists(key).Val()
|
||||
if n > 0 {
|
||||
var (
|
||||
err error
|
||||
flag = 11158569333
|
||||
key = "589:7954977:10"
|
||||
temp = UserMessageList{}
|
||||
)
|
||||
if n := rdb.Exists(key).Val(); n > 0 {
|
||||
s2 := rdb.LRange(key, 0, -1).Val()
|
||||
for i := 0; i < len(s2); i++ {
|
||||
v := UserMessageList{}
|
||||
_ = json.Unmarshal([]byte(s2[i]), &v)
|
||||
if v.UserID == flag {
|
||||
rdb.LSet(key, int64(i), "del")
|
||||
rdb.LRem(key, 0, "del")
|
||||
//删除此条数据
|
||||
err = rdb.LSet(key, int64(i), "del").Err()
|
||||
err = rdb.LRem(key, 0, "del").Err()
|
||||
s2 = append(s2[:i], s2[i+1:]...)
|
||||
i--
|
||||
if v.NewMessageNum == 0 { //目前为首条
|
||||
cnt++ //赋值1
|
||||
} else {
|
||||
cnt = v.NewMessageNum
|
||||
//cnt=0 重新赋值
|
||||
temp = UserMessageList{
|
||||
VendorID: v.VendorID,
|
||||
UserID: v.UserID,
|
||||
NewMessageNum: 0,
|
||||
LatestMsg: v.LatestMsg,
|
||||
LatestTime: v.LatestTime,
|
||||
}
|
||||
}
|
||||
}
|
||||
str, _ := json.Marshal(temp)
|
||||
err = rdb.RPush(key, str).Err()
|
||||
}
|
||||
fmt.Printf("after cnt %d\n", cnt)
|
||||
fmt.Printf("after len %d\n", len(s2))
|
||||
fmt.Printf("after ans %s\n", s2)
|
||||
//存入flag数据
|
||||
ans := UserMessageList{
|
||||
VendorID: 10,
|
||||
UserID: 11158569333,
|
||||
NewMessageNum: cnt,
|
||||
LatestMsg: "成功插入新数据,看下cnt",
|
||||
LatestTime: 1681983980,
|
||||
}
|
||||
param, _ := json.Marshal(ans)
|
||||
rdb.RPush(key, param)
|
||||
fmt.Print(err)
|
||||
//s2 := rdb.LRange(key, 0, -1).Val()
|
||||
//fmt.Printf("before len %d\n", len(s2))
|
||||
//fmt.Printf("before ans %s\n", s2)
|
||||
//cnt := 0
|
||||
//n := rdb.Exists(key).Val()
|
||||
//if n > 0 {
|
||||
// for i := 0; i < len(s2); i++ {
|
||||
// v := UserMessageList{}
|
||||
// _ = json.Unmarshal([]byte(s2[i]), &v)
|
||||
// if v.UserID == flag {
|
||||
// rdb.LSet(key, int64(i), "del")
|
||||
// rdb.LRem(key, 0, "del")
|
||||
// s2 = append(s2[:i], s2[i+1:]...)
|
||||
// i--
|
||||
// if v.NewMessageNum == 0 { //目前为首条
|
||||
// cnt++ //赋值1
|
||||
// } else {
|
||||
// cnt = v.NewMessageNum
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//fmt.Printf("after cnt %d\n", cnt)
|
||||
//fmt.Printf("after len %d\n", len(s2))
|
||||
//fmt.Printf("after ans %s\n", s2)
|
||||
////存入flag数据
|
||||
//ans := UserMessageList{
|
||||
// VendorID: 10,
|
||||
// UserID: 11158569333,
|
||||
// NewMessageNum: cnt,
|
||||
// LatestMsg: "成功插入新数据,看下cnt",
|
||||
// LatestTime: 1681983980,
|
||||
//}
|
||||
//param, _ := json.Marshal(ans)
|
||||
//rdb.RPush(key, param)
|
||||
}
|
||||
|
||||
// 根据账号获取连接
|
||||
|
||||
@@ -20,10 +20,10 @@ func init() {
|
||||
baseapi.Init(sugarLogger)
|
||||
|
||||
// 菜市
|
||||
api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")
|
||||
//api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")
|
||||
|
||||
// 果园
|
||||
//api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")
|
||||
api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")
|
||||
|
||||
//商超
|
||||
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_n4TwqCntWWuvQwAawzxC0w") //token_n4TwqCntWWuvQwAawzxC0w
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
// "authority_id": ""
|
||||
//}`
|
||||
|
||||
var token = `{"access_token":"c2c6e258-847d-4e8f-a695-b20488a5a667","expires_in":1682270239,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"ebf0e9f1-b200-47c2-a2bb-bafefbdaed47","authority_id":""}`
|
||||
var token = `{"access_token":"71896365-cec7-4982-a686-0d8f3044cc1e","expires_in":1682872676,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"76d410d2-e869-4ddc-b8ad-0ae652114e13","authority_id":""}`
|
||||
|
||||
//var token = `{"access_token":"e3173e9f-266f-4d87-88e7-e7cd837bc9d9","expires_in":1672882632,"scope":"SCOPE","shop_id":68023619,"shop_name":"京西到家","refresh_token":"5070aae2-493f-46bd-b5d6-6ea0cd64729f","authority_id":""}`
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ func TestUtilsTime2Date(t *testing.T) {
|
||||
|
||||
//设置门店打包费
|
||||
func TestSetStorePackageFee(t *testing.T) {
|
||||
err := a.SetStorePackageFee(62490423, 5) //单位 分
|
||||
err := a.SetStorePackageFee(94979567, 5) //单位 分
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package trenditapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var api = New(TiAppID, TiAppSecret)
|
||||
@@ -40,10 +42,7 @@ func TestAPI_Print(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCal(t *testing.T) {
|
||||
str := "豌豆米-手工剥豆约100g/份"
|
||||
//ans := "--------------------------------"
|
||||
cnt := CalWidth(str)
|
||||
fmt.Println(cnt)
|
||||
fmt.Println(utils.Time2Str(time.Now()))
|
||||
}
|
||||
|
||||
//打印取消/退货模板
|
||||
|
||||
@@ -23,16 +23,41 @@ func TestCBMessageTemplateSend(t *testing.T) {
|
||||
// "oYN_usk0AeGc_C6VEZfmFQP5VHMQ": 1, // 周小扬
|
||||
// "oYN_ust9hXKEvEv0X6Mq6nlAWs_E": 1, // me
|
||||
// "oYN_usvnObzrPweIgHTad9-uMf78": 1, // 老赵
|
||||
err := api.CBMessageTemplateSend("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", "_DtNGwmOeR6TkkTVUblxLIlkV2MAPOX57TkvfdqG6nY", "", map[string]interface{}{
|
||||
"appid": "wx4b5930c13f8b1170",
|
||||
"pagepath": "pages/order-manager/main",
|
||||
err := api.CBMessageTemplateSend("oYN_uskWlggFxGNZtagNh-cqfTQs", "b8-tLyWwAmK-1tEU1eGqp_YAAqQtSzoVDZkHuyUe9lk", "", map[string]interface{}{
|
||||
"appid": "wx4b5930c13f8b1170",
|
||||
//"pagepath": "pages/order-manager/main",
|
||||
}, map[string]interface{}{
|
||||
"first": "first",
|
||||
"Day": "Day",
|
||||
"orderId": "orderId",
|
||||
"orderType": "orderType",
|
||||
"customerName": "customerName",
|
||||
"customerPhone": "customerPhone",
|
||||
"first": map[string]interface{}{
|
||||
"value": "这是一个测试头",
|
||||
"color": "#0191EA",
|
||||
},
|
||||
"keyword1": map[string]interface{}{
|
||||
"value": "美团#1",
|
||||
"color": "#173177",
|
||||
},
|
||||
"keyword2": map[string]interface{}{
|
||||
"value": "好菜鲜生(清水塘生鲜农贸市场2店)",
|
||||
"color": "#173177",
|
||||
},
|
||||
//"orderId": "orderId",
|
||||
"keyword3": map[string]interface{}{
|
||||
//"value": "吴廷琦吴吴廷琦吴吴廷琦吴吴廷琦吴吴廷琦吴吴廷琦吴 18727362534,0987",
|
||||
"value": "1234567891234567891234567891234 18727362534,0987",
|
||||
"color": "#173177",
|
||||
},
|
||||
"keyword4": map[string]interface{}{
|
||||
"value": "2023:05:05 14:30:18",
|
||||
"color": "#173177",
|
||||
},
|
||||
//"keyword5": map[string]interface{}{
|
||||
// "value": "立即配送",
|
||||
// "color": "#173177",
|
||||
//},
|
||||
|
||||
//"customerPhone": map[string]interface{}{
|
||||
// "value": "1234567891234567891234567891234",
|
||||
// "color": "#173177",
|
||||
//},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
|
||||
@@ -27,7 +27,7 @@ func init() {
|
||||
|
||||
//weixinapp
|
||||
//api = New("wx18111a41fd17f24f", "c79ac6e1b2d6d7968e72a9658a8b6715")
|
||||
api.CBSetToken("46_sKrKhgoeh0Om1V2_IcTERUux4-pLL5CplvhOh7civG51UCSUTt6g3WkTutvk107i2SMhdcU5q9MYGbciZ4PHyPzhlzx34yBPblf8dpRHx3VYE_a9JbE2wbtjJY93GmXc4KcRHxlEa8s_QWFVOLCgADAKHY")
|
||||
api.CBSetToken("68_McFYD4DjMiawiqWvGstXuxBq5IKTt9xMHRnwqE4nW8c6YVYhPV7cYEpyf0y0nh0m8qiHKCYbzS6Oc3DN-Wu74_WoNXi7PDzjkZWG2dziBqzsGYE8UVZlpi2ezO0NBKeAEAQEN")
|
||||
}
|
||||
|
||||
func handleError(t *testing.T, err error) {
|
||||
|
||||
Reference in New Issue
Block a user