mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 01:55:58 +08:00
ws and push update
This commit is contained in:
@@ -27,7 +27,7 @@ const (
|
||||
TerminalMobile = "Mobile"
|
||||
)
|
||||
|
||||
var PlatformID2Name = map[int32]string{
|
||||
var PlatformID2Name = map[int]string{
|
||||
IOSPlatformID: IOSPlatformStr,
|
||||
AndroidPlatformID: AndroidPlatformStr,
|
||||
WindowsPlatformID: WindowsPlatformStr,
|
||||
@@ -36,7 +36,7 @@ var PlatformID2Name = map[int32]string{
|
||||
MiniWebPlatformID: MiniWebPlatformStr,
|
||||
LinuxPlatformID: LinuxPlatformStr,
|
||||
}
|
||||
var PlatformName2ID = map[string]int32{
|
||||
var PlatformName2ID = map[string]int{
|
||||
IOSPlatformStr: IOSPlatformID,
|
||||
AndroidPlatformStr: AndroidPlatformID,
|
||||
WindowsPlatformStr: WindowsPlatformID,
|
||||
@@ -55,10 +55,10 @@ var Platform2class = map[string]string{
|
||||
LinuxPlatformStr: TerminalPC,
|
||||
}
|
||||
|
||||
func PlatformIDToName(num int32) string {
|
||||
func PlatformIDToName(num int) string {
|
||||
return PlatformID2Name[num]
|
||||
}
|
||||
func PlatformNameToID(name string) int32 {
|
||||
func PlatformNameToID(name string) int {
|
||||
return PlatformName2ID[name]
|
||||
}
|
||||
func PlatformNameToClass(name string) string {
|
||||
|
||||
@@ -111,7 +111,7 @@ func (d *DataBases) DelAppleDeviceToken(accountAddress string) (err error) {
|
||||
}
|
||||
|
||||
//Store userid and platform class to redis
|
||||
func (d *DataBases) AddTokenFlag(userID string, platformID int32, token string, flag int) error {
|
||||
func (d *DataBases) AddTokenFlag(userID string, platformID int, token string, flag int) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
log2.NewDebug("", "add token key is ", key)
|
||||
_, err1 := d.Exec("HSet", key, token, flag)
|
||||
@@ -123,12 +123,12 @@ func (d *DataBases) GetTokenMapByUidPid(userID, platformID string) (map[string]i
|
||||
log2.NewDebug("", "get token key is ", key)
|
||||
return redis.IntMap(d.Exec("HGETALL", key))
|
||||
}
|
||||
func (d *DataBases) SetTokenMapByUidPid(userID string, platformID int32, m map[string]int) error {
|
||||
func (d *DataBases) SetTokenMapByUidPid(userID string, platformID int, m map[string]int) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
_, err := d.Exec("hmset", key, redis.Args{}.Add().AddFlat(m)...)
|
||||
return err
|
||||
}
|
||||
func (d *DataBases) DeleteTokenByUidPid(userID string, platformID int32, fields []string) error {
|
||||
func (d *DataBases) DeleteTokenByUidPid(userID string, platformID int, fields []string) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
_, err := d.Exec("HDEL", key, redis.Args{}.Add().AddFlat(fields)...)
|
||||
return err
|
||||
|
||||
@@ -37,7 +37,7 @@ func BuildClaims(uid, platform string, ttl int64) Claims {
|
||||
}}
|
||||
}
|
||||
|
||||
func CreateToken(userID string, platformID int32) (string, int64, error) {
|
||||
func CreateToken(userID string, platformID int) (string, int64, error) {
|
||||
claims := BuildClaims(userID, constant.PlatformIDToName(platformID), config.Config.TokenPolicy.AccessExpire)
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
tokenString, err := token.SignedString([]byte(config.Config.TokenPolicy.AccessSecret))
|
||||
@@ -233,7 +233,7 @@ func WsVerifyToken(token, uid string, platformID string, operationID string) (bo
|
||||
if claims.UID != uid {
|
||||
return false, utils.Wrap(&constant.ErrTokenUnknown, "uid is not same to token uid"), "uid is not same to token uid"
|
||||
}
|
||||
if claims.Platform != constant.PlatformIDToName(utils.StringToInt32(platformID)) {
|
||||
if claims.Platform != constant.PlatformIDToName(utils.StringToInt(platformID)) {
|
||||
return false, utils.Wrap(&constant.ErrTokenUnknown, "platform is not same to token platform"), "platform is not same to token platform"
|
||||
}
|
||||
log.NewDebug(operationID, utils.GetSelfFuncName(), " check ok ", claims.UID, uid, claims.Platform)
|
||||
|
||||
@@ -9,8 +9,22 @@ message OnlinePushMsgReq {
|
||||
string pushToUserID = 3;
|
||||
}
|
||||
message OnlinePushMsgResp{
|
||||
repeated SingleMsgToUser resp = 1;
|
||||
}//message SendMsgByWSReq{
|
||||
repeated SingleMsgToUserPlatform resp = 1;
|
||||
}
|
||||
message SingelMsgToUserResultList{
|
||||
string userID =1;
|
||||
repeated SingleMsgToUserPlatform resp = 2;
|
||||
|
||||
}
|
||||
message OnlineBatchPushOneMsgReq{
|
||||
string OperationID = 1;
|
||||
server_api_params.MsgData msgData = 2;
|
||||
repeated string pushToUserIDList = 3;
|
||||
}
|
||||
message OnlineBatchPushOneMsgResp{
|
||||
repeated SingelMsgToUserResultList singlePushResult= 1;
|
||||
}
|
||||
//message SendMsgByWSReq{
|
||||
// string SendID = 1;
|
||||
// string RecvID = 2;
|
||||
// string Content = 3;
|
||||
@@ -22,7 +36,7 @@ repeated SingleMsgToUser resp = 1;
|
||||
// int64 PlatformID = 9;
|
||||
//}
|
||||
|
||||
message SingleMsgToUser{
|
||||
message SingleMsgToUserPlatform{
|
||||
int64 ResultCode = 1;
|
||||
string RecvID = 2;
|
||||
int32 RecvPlatFormID = 3;
|
||||
@@ -56,6 +70,7 @@ message GetUsersOnlineStatusResp{
|
||||
service OnlineMessageRelayService {
|
||||
rpc OnlinePushMsg(OnlinePushMsgReq) returns(OnlinePushMsgResp);
|
||||
rpc GetUsersOnlineStatus(GetUsersOnlineStatusReq)returns(GetUsersOnlineStatusResp);
|
||||
rpc OnlineBatchPushOneMsg(OnlineBatchPushOneMsgReq) returns(OnlineBatchPushOneMsgResp);
|
||||
// rpc SendMsgByWS(SendMsgByWSReq) returns(MsgToUserResp);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,14 @@ func IsContainInt32(target int32, List []int32) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsContainInt(target int, List []int) bool {
|
||||
for _, element := range List {
|
||||
if target == element {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
func InterfaceArrayToStringArray(data []interface{}) (i []string) {
|
||||
for _, param := range data {
|
||||
i = append(i, param.(string))
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ func String2Pb(s string, pb proto.Message) error {
|
||||
return proto.Unmarshal([]byte(s), pb)
|
||||
}
|
||||
|
||||
func Map2Pb(m map[string]interface{}) (pb proto.Message, err error) {
|
||||
func Map2Pb(m map[string]string) (pb proto.Message, err error) {
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user