mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-06-23 01:18:39 +08:00
查询共同群
This commit is contained in:
parent
9bb769a2eb
commit
f9d3221df0
2
go.mod
2
go.mod
@ -2,6 +2,8 @@ module github.com/openimsdk/open-im-server/v3
|
||||
|
||||
go 1.25.0
|
||||
|
||||
replace github.com/openimsdk/protocol => ../protocol
|
||||
|
||||
require (
|
||||
firebase.google.com/go/v4 v4.14.1
|
||||
github.com/dtm-labs/rockscache v0.1.1
|
||||
|
||||
2
go.sum
2
go.sum
@ -354,8 +354,6 @@ github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y=
|
||||
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
|
||||
github.com/openimsdk/gomake v0.0.17 h1:q8haP48VOH45WhJRiLj1YSBJyUFJqD8CTedH65i1YH8=
|
||||
github.com/openimsdk/gomake v0.0.17/go.mod h1:nnjS8yCtrPJAt1knMbyPiUwCH2gpyBzj/EZAONfUOXg=
|
||||
github.com/openimsdk/protocol v0.0.73-alpha.12 h1:2NYawXeHChYUeSme6QJ9pOLh+Empce2WmwEtbP4JvKk=
|
||||
github.com/openimsdk/protocol v0.0.73-alpha.12/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
|
||||
github.com/openimsdk/tools v0.0.50-alpha.113 h1:rhLWaSJuhjgJFNVzmpChLCG7dPXS0+bte+CPI0008Us=
|
||||
github.com/openimsdk/tools v0.0.50-alpha.113/go.mod h1:x9i/e+WJFW4tocy6RNJQ9NofQiP3KJ1Y576/06TqOG4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
|
||||
@ -169,3 +169,7 @@ func (o *GroupApi) GetFullJoinGroupIDs(c *gin.Context) {
|
||||
func (o *GroupApi) GetGroupApplicationUnhandledCount(c *gin.Context) {
|
||||
a2r.Call(c, group.GroupClient.GetGroupApplicationUnhandledCount, o.Client)
|
||||
}
|
||||
|
||||
func (o *GroupApi) GetCommonGroupsWithFriend(c *gin.Context) {
|
||||
a2r.Call(c, group.GroupClient.GetCommonGroupsWithFriend, o.Client)
|
||||
}
|
||||
|
||||
@ -187,6 +187,7 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, co
|
||||
groupRouterGroup.POST("/get_full_group_member_user_ids", g.GetFullGroupMemberUserIDs)
|
||||
groupRouterGroup.POST("/get_full_join_group_ids", g.GetFullJoinGroupIDs)
|
||||
groupRouterGroup.POST("/get_group_application_unhandled_count", g.GetGroupApplicationUnhandledCount)
|
||||
groupRouterGroup.POST("/get_common_groups_with_friend", g.GetCommonGroupsWithFriend)
|
||||
}
|
||||
// certificate
|
||||
{
|
||||
|
||||
@ -358,6 +358,50 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbgroup.GetJo
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (g *groupServer) GetCommonGroupsWithFriend(ctx context.Context, req *pbgroup.GetCommonGroupsWithFriendReq) (*pbgroup.GetCommonGroupsWithFriendResp, error) {
|
||||
if req.FriendUserID == "" {
|
||||
return nil, errs.ErrArgs.WrapMsg("friendUserID empty")
|
||||
}
|
||||
opUserID := mcontext.GetOpUserID(ctx)
|
||||
if opUserID == "" {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("op user id empty")
|
||||
}
|
||||
|
||||
selfGroupIDs, err := g.db.FindJoinGroupID(ctx, opUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(selfGroupIDs) == 0 {
|
||||
return &pbgroup.GetCommonGroupsWithFriendResp{
|
||||
Total: 0,
|
||||
Groups: []*sdkws.GroupInfo{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
friendMembers, err := g.db.FindGroupMemberUser(ctx, selfGroupIDs, req.FriendUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(friendMembers) == 0 {
|
||||
return &pbgroup.GetCommonGroupsWithFriendResp{
|
||||
Total: 0,
|
||||
Groups: []*sdkws.GroupInfo{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
commonGroupIDs := datautil.Distinct(datautil.Slice(friendMembers, func(e *model.GroupMember) string {
|
||||
return e.GroupID
|
||||
}))
|
||||
groups, err := g.getGroupsInfo(ctx, commonGroupIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pbgroup.GetCommonGroupsWithFriendResp{
|
||||
Total: uint32(len(groups)),
|
||||
Groups: groups,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.InviteUserToGroupReq) (*pbgroup.InviteUserToGroupResp, error) {
|
||||
if len(req.InvitedUserIDs) == 0 {
|
||||
return nil, errs.ErrArgs.WrapMsg("user empty")
|
||||
|
||||
112
scripts/get_common_group.sh
Executable file
112
scripts/get_common_group.sh
Executable file
@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ====== 按需修改 ======
|
||||
API_BASE="${API_BASE:-http://127.0.0.1:10002}" # 你的 open-im-api 地址
|
||||
SELF_USER_ID="${SELF_USER_ID:-3932647710}" # 当前登录用户(拿 token 的用户)
|
||||
#FRIEND_USER_ID="${FRIEND_USER_ID:-4391832441}" # 要查询共同群的好友
|
||||
FRIEND_USER_ID="${FRIEND_USER_ID:-9607566286}" # 要查询共同群的好友
|
||||
PLATFORM_ID="${PLATFORM_ID:-2}" # 1=iOS, 2=Android, 3=Windows...
|
||||
ADMIN_USER_ID="${ADMIN_USER_ID:-imAdmin}" # 管理员账号(用于签发用户 token)
|
||||
ADMIN_SECRET="${ADMIN_SECRET:-openIM123}" # 配置中的 share.secret
|
||||
DEBUG="${DEBUG:-0}" # DEBUG=1 打印请求/响应明细
|
||||
# =====================
|
||||
|
||||
debug_log() {
|
||||
if [[ "${DEBUG}" == "1" ]]; then
|
||||
echo "[DEBUG] $*"
|
||||
fi
|
||||
}
|
||||
|
||||
print_json_safe() {
|
||||
local raw="${1:-}"
|
||||
if echo "${raw}" | jq -e . >/dev/null 2>&1; then
|
||||
echo "${raw}" | jq .
|
||||
else
|
||||
echo "${raw}"
|
||||
fi
|
||||
}
|
||||
|
||||
# 1) 先拿 user token(如果你已有 token,可跳过这一步,直接 export TOKEN=xxx)
|
||||
if [[ -z "${TOKEN:-}" ]]; then
|
||||
if [[ -z "${ADMIN_SECRET}" ]]; then
|
||||
echo "缺少 ADMIN_SECRET,请先导出:export ADMIN_SECRET='你的share.secret'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "获取管理员 token: ${ADMIN_USER_ID}"
|
||||
OP_ID_ADMIN="op_admin_$(date +%s)"
|
||||
debug_log "POST ${API_BASE}/auth/get_admin_token"
|
||||
debug_log "operationID: ${OP_ID_ADMIN}"
|
||||
debug_log "admin req body: {\"userID\":\"${ADMIN_USER_ID}\",\"secret\":\"***\"}"
|
||||
ADMIN_RESP=$(
|
||||
curl -sS -X POST "${API_BASE}/auth/get_admin_token" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H "operationID: ${OP_ID_ADMIN}" \
|
||||
-d "$(cat <<JSON
|
||||
{
|
||||
"userID": "${ADMIN_USER_ID}",
|
||||
"secret": "${ADMIN_SECRET}"
|
||||
}
|
||||
JSON
|
||||
)"
|
||||
)
|
||||
debug_log "admin raw resp: ${ADMIN_RESP}"
|
||||
ADMIN_TOKEN="$(echo "${ADMIN_RESP}" | jq -r '.data.token // empty')"
|
||||
debug_log "admin token parsed: ${ADMIN_TOKEN:-<empty>}"
|
||||
if [[ -z "${ADMIN_TOKEN}" ]]; then
|
||||
echo "获取管理员 token 失败,响应如下:"
|
||||
print_json_safe "${ADMIN_RESP}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "获取用户 token: ${SELF_USER_ID}"
|
||||
OP_ID_USER="op_user_$(date +%s)"
|
||||
debug_log "POST ${API_BASE}/auth/get_user_token"
|
||||
debug_log "operationID: ${OP_ID_USER}"
|
||||
debug_log "user req body: {\"userID\":\"${SELF_USER_ID}\",\"platformID\":${PLATFORM_ID}}"
|
||||
USER_RESP=$(
|
||||
curl -sS -X POST "${API_BASE}/auth/get_user_token" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H "operationID: ${OP_ID_USER}" \
|
||||
-H "token: ${ADMIN_TOKEN}" \
|
||||
-d "$(cat <<JSON
|
||||
{
|
||||
"userID": "${SELF_USER_ID}",
|
||||
"platformID": ${PLATFORM_ID}
|
||||
}
|
||||
JSON
|
||||
)"
|
||||
)
|
||||
debug_log "user raw resp: ${USER_RESP}"
|
||||
TOKEN="$(echo "${USER_RESP}" | jq -r '.data.token // empty')"
|
||||
debug_log "user token parsed: ${TOKEN:-<empty>}"
|
||||
fi
|
||||
|
||||
if [[ -z "${TOKEN}" ]]; then
|
||||
echo "获取用户 token 失败,响应如下:"
|
||||
print_json_safe "${USER_RESP:-}"
|
||||
echo "提示:请确认 SELF_USER_ID 用户已注册存在,或手动传入 TOKEN 后重试。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OP_ID="op_$(date +%s)"
|
||||
|
||||
# 2) 调共同群接口
|
||||
echo "查询共同群: self=${SELF_USER_ID}, friend=${FRIEND_USER_ID}"
|
||||
REQ_BODY="$(cat <<JSON
|
||||
{
|
||||
"friendUserID": "${FRIEND_USER_ID}"
|
||||
}
|
||||
JSON
|
||||
)"
|
||||
debug_log "POST ${API_BASE}/group/get_common_groups_with_friend"
|
||||
debug_log "operationID: ${OP_ID}"
|
||||
debug_log "group req body: ${REQ_BODY}"
|
||||
GROUP_RESP="$(curl -sS -X POST "${API_BASE}/group/get_common_groups_with_friend" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H "token: ${TOKEN}" \
|
||||
-H "operationID: ${OP_ID}" \
|
||||
-d "${REQ_BODY}")"
|
||||
debug_log "group raw resp: ${GROUP_RESP}"
|
||||
print_json_safe "${GROUP_RESP}"
|
||||
Loading…
x
Reference in New Issue
Block a user