Commit bee9c6a1 authored by hujiebin's avatar hujiebin

公共方法

parent 5b9a1ba0
......@@ -28,6 +28,9 @@ const (
METHOD = "method"
IMEI = "imei"
LANGUAGE = "language"
TOKEN = "token"
CARRIER = "carrier" // 运营商,460 开头是中国,如:46001,46007
TIMEZONE = "timeZone" // 时区 GMT+8 / GMT+8:00
)
/**
......
......@@ -131,3 +131,87 @@ func SendGlobalGameBanner(winUserId uint64, diamond uint64, avatar string, gameT
}
return nil
}
func SendJoinGroup(userId uint64, externalId string, groupId string) error {
msg := &userProxy.JoinGroup{GroupId: groupId, ExternalId: externalId}
if buffer, err := proto.Marshal(msg); err == nil {
userIds := []uint64{userId}
rspUids, err := multicast(userIds, MsgTypeJoinGroup, buffer)
//记录socket,注意闭包问题
go func(userIds []uint64, msg *userProxy.JoinGroup, rspUids []uint64, err error) {
buf, _ := json.Marshal(msg)
AddRpcLogs(MsgTypeJoinGroup, userIds, string(buf[:]), rspUids, err)
}(userIds, msg, rspUids, err)
if err != nil {
mylogrus.MyLog.Errorf("grpc SendJoinGroup send fail")
return err
} else {
mylogrus.MyLog.Info("grpc SendJoinGroup send success")
}
} else {
return err
}
return nil
}
func SendConfigChange(operUserId uint64, configType uint32) error {
msg := &userProxy.ConfigChange{
Type: configType,
}
if buffer, err := proto.Marshal(msg); err == nil {
rspUids, err := broadcast(MsgTypeConfigChange, buffer)
//记录socket,注意闭包问题
go func(configType uint32, msg *userProxy.ConfigChange, rspUids []uint64, err error) {
buf, _ := json.Marshal(msg)
AddRpcLog(MsgTypeConfigChange, operUserId, string(buf[:]), rspUids, err)
}(configType, msg, rspUids, err)
if err != nil {
mylogrus.MyLog.Errorf("grpc SendConfigChange send fail")
return err
} else {
mylogrus.MyLog.Info("grpc SendConfigChange send success")
}
} else {
return err
}
return nil
}
func SendGroupChatNotice(fromUserId uint64, userIds []uint64, senderExtId string, senderCode string, senderSex uint32, senderAvatar string,
text string, groupId, groupName, groupCode, groupAvatar string, userInNum uint32) error {
msg := &userProxy.GroupSendNotice{
SenderExtId: senderExtId,
SenderCode: senderCode,
SenderSex: senderSex,
SenderAvatar: senderAvatar,
Text: text,
GroupName: groupName,
GroupCode: groupCode,
GroupAvatar: groupAvatar,
UserInNum: userInNum,
GroupId: groupId,
}
if buffer, err := proto.Marshal(msg); err == nil {
rspUids, err := multicast(userIds, MsgTypeGroupChatNotice, buffer)
//记录socket,注意闭包问题
go func(userId uint64, msg *userProxy.GroupSendNotice, rspUids []uint64, err error) {
buf, _ := json.Marshal(msg)
AddRpcLog(MsgTypeGroupChatNotice, userId, string(buf[:]), rspUids, err)
}(fromUserId, msg, rspUids, err)
if err != nil {
mylogrus.MyLog.Errorf("grpc SendGroupChatNotice send fail,userId:", fromUserId)
return err
} else {
mylogrus.MyLog.Info("grpc SendGroupChatNotice send success,userId:", fromUserId)
}
} else {
return err
}
return nil
}
......@@ -2,7 +2,9 @@ package utils
import (
"encoding/json"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/mysql"
"strings"
"time"
)
......@@ -92,3 +94,12 @@ func IsInStringList(str string, list []string) bool {
}
return false
}
// 缩短url: 去掉AWS前缀,以便aws接口使用
func StripAwsPrefix(url string) string {
if !strings.HasPrefix(url, config.GetConfigAws().AWS_CDN) {
return url
}
newUrl := url[len(config.GetConfigAws().AWS_CDN):]
return newUrl
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment