Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
bee9c6a1
Commit
bee9c6a1
authored
Mar 06, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公共方法
parent
5b9a1ba0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
0 deletions
+98
-0
context.go
mycontext/context.go
+3
-0
user_center_func.go
rpc/user_center_func.go
+84
-0
utils.go
utils/utils.go
+11
-0
No files found.
mycontext/context.go
View file @
bee9c6a1
...
...
@@ -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
)
/**
...
...
rpc/user_center_func.go
View file @
bee9c6a1
...
...
@@ -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
}
utils/utils.go
View file @
bee9c6a1
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment