提交 943f9811 编写于 作者: programor_guo's avatar programor_guo

Merge remote-tracking branch 'origin/main'

# The class cannot be named by Pascal or camel case.
# If it is not used, the corresponding structure will not be set,
# and it will not be read naturally.
#---------------Infrastructure configuration---------------------#
etcd:
etcdSchema: openIM
etcdAddr: [ 47.112.160.66:2379 ]
mysql:
dbAddress: [ 47.112.160.66:3306 ]
dbUserName: root
dbPassword: 123456
dbDatabaseName: openIM
dbTableName: eMsg
dbMsgTableNum: 1
dbMaxOpenConns: 20
dbMaxIdleConns: 10
dbMaxLifeTime: 120
mongo:
dbAddress: [ 47.112.160.66:27017 ]
dbDirect: false
dbTimeout: 10
dbDatabase: [ openIM ]
dbSource: admin
dbUserName:
dbPassword:
dbMaxPoolSize: 20
dbRetainChatRecords: 7
redis:
dbAddress: [47.112.160.66:6379]
dbMaxIdle: 128
dbMaxActive: 0
dbIdleTimeout: 120
dbPassWord: open_im4545453
kafka:
ws2mschat:
addr: [ 47.112.160.66:9092 ]
topic: "ws2ms_chat"
ms2pschat:
addr: [ 47.112.160.66:9092 ]
topic: "ms2ps_chat"
consumergroupid:
msgToMongo: mongo
msgToMySql: mysql
msgToPush: push
#---------------Internal service configuration---------------------#
# The service ip default is empty,
# automatically obtain the machine's valid network card ip as the service ip,
# otherwise the configuration ip is preferred
serverip:
api:
openImApiPort: [ 10000 ]
credential:
tencent:
appID: 1302656840
region: ap-chengdu
bucket: echat-1302656840
secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC
secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe
rpcport:
openImUserPort: [ 10100,10101 ]
openImFriendPort: [ 10200,10201 ]
openImOfflineMessagePort: [ 10300 ]
openImOnlineRelayPort: [ 10400 ]
openImGroupPort: [ 10500 ,10501 ]
openImAuthPort: [ 10600, 10601 ]
openImPushPort: [ 10700 ]
rpcregistername:
openImUserName: User
openImFriendName: Friend
openImOfflineMessageName: OfflineMessage
openImPushName: Push
openImOnlineMessageRelayName: OnlineMessageRelay
openImGroupName: Group
rpcGetTokenName: Auth
log:
storageLocation: ../logs/
elasticSearchSwitch: false
elasticSearchAddr: [ 47.112.160.66:9201 ]
elasticSearchUser: ""
elasticSearchPassword: ""
modulename:
longConnSvrName: msg_gateway
msgTransferName: msg_transfer
pushName: push
longconnsvr:
websocketPort: [ 7778 ]
websocketMaxConnNum: 10000
websocketMaxMsgLen: 4096
websocketTimeOut: 10
push:
tpns:
ios:
accessID: 1600018281
secretKey: 3cd68a77a95b89e5089a1aca523f318f
android:
accessID: 111
secretKey: 111
secret: tuoyun
multiloginpolicy:
onlyOneTerminalAccess: false
mobileAndPCTerminalAccessButOtherTerminalKickEachOther: true
allTerminalAccess: false
#token config
tokenpolicy:
accessSecret: "open_im_server"
# Token effective time seconds as a unit
#Seven days 7*24*60*60
accessExpire: 604800
\ No newline at end of file
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsAddBlackList struct {
OperationID string `json:"operationID" binding:"required"`
UID string `json:"uid" binding:"required"`
}
func AddBlacklist(c *gin.Context) {
log.Info("", "", "api add blacklist init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsSearchFriend{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.AddBlacklistReq{
Uid: params.UID,
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api add blacklist is server:userID=%s", req.Uid)
RpcResp, err := client.AddBlacklist(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call add blacklist rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add blacklist rpc server failed"})
return
}
log.InfoByArgs("call add blacklist rpc server success,args=%s", RpcResp.String())
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
log.InfoByArgs("api add blacklist success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsAddFriend struct {
OperationID string `json:"operationID" binding:"required"`
UID string `json:"uid" binding:"required"`
ReqMessage string `json:"reqMessage"`
}
func AddFriend(c *gin.Context) {
log.Info("", "", "api add friend init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsAddFriend{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.AddFriendReq{
Uid: params.UID,
OperationID: params.OperationID,
ReqMessage: params.ReqMessage,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api add friend is server")
RpcResp, err := client.AddFriend(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call add friend rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add friend rpc server failed"})
return
}
log.InfoByArgs("call add friend rpc server success,args=%s", RpcResp.String())
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
log.InfoByArgs("api add friend success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsAddFriendResponse struct {
OperationID string `json:"operationID" binding:"required"`
UID string `json:"uid" binding:"required"`
Flag int32 `json:"flag" binding:"required"`
}
func AddFriendResponse(c *gin.Context) {
log.Info("", "", fmt.Sprintf("api add friend response init ...."))
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsAddFriendResponse{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.AddedFriendReq{
Uid: params.UID,
Flag: params.Flag,
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api add friend response is server:userID=%s", req.Uid)
RpcResp, err := client.AddedFriend(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call add_friend_response rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add_friend_response rpc server failed"})
return
}
log.InfoByArgs("call add friend response rpc server success,args=%s", RpcResp.String())
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
log.InfoByArgs("api add friend response success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsDeleteFriend struct {
OperationID string `json:"operationID" binding:"required"`
UID string `json:"uid" binding:"required"`
}
func DeleteFriend(c *gin.Context) {
log.Info("", "", fmt.Sprintf("api delete_friend init ...."))
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsDeleteFriend{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.DeleteFriendReq{
Uid: params.UID,
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api delete_friend is server:%s", req.Uid)
RpcResp, err := client.DeleteFriend(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call delete_friend rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete_friend rpc server failed"})
return
}
log.InfoByArgs("call delete_friend rpc server,args=%s", RpcResp.String())
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
log.InfoByArgs("api delete_friend success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsGetBlackList struct {
OperationID string `json:"operationID" binding:"required"`
}
type blackListUserInfo struct {
UID string `json:"uid"`
Name string `json:"name"`
Icon string `json:"icon"`
Gender int32 `json:"gender"`
Mobile string `json:"mobile"`
Birth string `json:"birth"`
Email string `json:"email"`
Ex string `json:"ex"`
}
func GetBlacklist(c *gin.Context) {
log.Info("", "", "api get blacklist init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsGetBlackList{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.GetBlacklistReq{
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, fmt.Sprintf("api get blacklist is server"))
RpcResp, err := client.GetBlacklist(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call get_friend_list rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get blacklist rpc server failed"})
return
}
log.InfoByArgs("call get blacklist rpc server success,args=%s", RpcResp.String())
if RpcResp.ErrorCode == 0 {
userBlackList := make([]blackListUserInfo, 0)
for _, friend := range RpcResp.Data {
var fi blackListUserInfo
fi.UID = friend.Uid
fi.Name = friend.Name
fi.Icon = friend.Icon
fi.Gender = friend.Gender
fi.Mobile = friend.Mobile
fi.Birth = friend.Birth
fi.Email = friend.Email
fi.Ex = friend.Ex
userBlackList = append(userBlackList, fi)
}
resp := gin.H{
"errCode": RpcResp.ErrorCode,
"errMsg": RpcResp.ErrorMsg,
"data": userBlackList,
}
c.JSON(http.StatusOK, resp)
} else {
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
}
log.InfoByArgs("api get black list success return,get args=%s,return=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsGetFriendApplyList struct {
OperationID string `json:"operationID" binding:"required"`
}
type UserInfo struct {
UID string `json:"uid"`
Name string `json:"name"`
Icon string `json:"icon"`
Gender int32 `json:"gender"`
Mobile string `json:"mobile"`
Birth string `json:"birth"`
Email string `json:"email"`
Ex string `json:"ex"`
ReqMessage string `json:"reqMessage"`
ApplyTime string `json:"applyTime"`
Flag int32 `json:"flag"`
}
func GetFriendApplyList(c *gin.Context) {
log.Info("", "", "api get_friend_apply_list init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsGetFriendApplyList{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.GetFriendApplyReq{
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api get friend apply list is server")
RpcResp, err := client.GetFriendApplyList(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call get friend apply list rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend apply list rpc server failed"})
return
}
log.InfoByArgs("call get friend apply list rpc server success,args=%s", RpcResp.String())
if RpcResp.ErrorCode == 0 {
userInfoList := make([]UserInfo, 0)
for _, applyUserinfo := range RpcResp.Data {
var un UserInfo
un.UID = applyUserinfo.Uid
un.Name = applyUserinfo.Name
un.Icon = applyUserinfo.Icon
un.Gender = applyUserinfo.Gender
un.Mobile = applyUserinfo.Mobile
un.Birth = applyUserinfo.Birth
un.Email = applyUserinfo.Email
un.Ex = applyUserinfo.Ex
un.Flag = applyUserinfo.Flag
un.ApplyTime = applyUserinfo.ApplyTime
un.ReqMessage = applyUserinfo.ReqMessage
userInfoList = append(userInfoList, un)
}
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": userInfoList}
c.JSON(http.StatusOK, resp)
} else {
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
}
log.InfoByArgs("api get friend apply list success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsGetFriendLIst struct {
OperationID string `json:"operationID" binding:"required"`
}
type friendInfo struct {
UID string `json:"uid"`
Name string `json:"name"`
Icon string `json:"icon"`
Gender int32 `json:"gender"`
Mobile string `json:"mobile"`
Birth string `json:"birth"`
Email string `json:"email"`
Ex string `json:"ex"`
Comment string `json:"comment"`
IsInBlackList int32 `json:"isInBlackList"`
}
func GetFriendList(c *gin.Context) {
log.Info("", "", fmt.Sprintf("api get_friendlist init ...."))
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsGetFriendLIst{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.GetFriendListReq{
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api get friend list is server")
RpcResp, err := client.GetFriendList(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call get friend list rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend list rpc server failed"})
return
}
log.InfoByArgs("call get friend list rpc server success,args=%s", RpcResp.String())
if RpcResp.ErrorCode == 0 {
friendsInfo := make([]friendInfo, 0)
for _, friend := range RpcResp.Data {
var fi friendInfo
fi.UID = friend.Uid
fi.Name = friend.Name
fi.Icon = friend.Icon
fi.Gender = friend.Gender
fi.Mobile = friend.Mobile
fi.Birth = friend.Birth
fi.Email = friend.Email
fi.Ex = friend.Ex
fi.Comment = friend.Comment
fi.IsInBlackList = friend.IsInBlackList
friendsInfo = append(friendsInfo, fi)
}
resp := gin.H{
"errCode": RpcResp.ErrorCode,
"errMsg": RpcResp.ErrorMsg,
"data": friendsInfo,
}
c.JSON(http.StatusOK, resp)
} else {
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
}
log.InfoByArgs("api get friend list success return,get args=%s,return=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsRemoveBlackList struct {
OperationID string `json:"operationID" binding:"required"`
UID string `json:"uid" binding:"required"`
}
func RemoveBlacklist(c *gin.Context) {
log.Info("", "", "api remove_blacklist init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsRemoveBlackList{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.RemoveBlacklistReq{
Uid: params.UID,
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api remove blacklist is server:userID=%s", req.Uid)
RpcResp, err := client.RemoveBlacklist(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call remove blacklist rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call remove blacklist rpc server failed"})
return
}
log.InfoByArgs("call remove blacklist rpc server success,args=%s", RpcResp.String())
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
log.InfoByArgs("api remove blacklist success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsSearchFriend struct {
OperationID string `json:"operationID" binding:"required"`
UID string `json:"uid" binding:"required"`
}
func SearchFriend(c *gin.Context) {
log.Info("", "", fmt.Sprintf("api search friend init ...."))
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsSearchFriend{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.SearchFriendReq{
Uid: params.UID,
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api search_friend is server")
RpcResp, err := client.SearchFriend(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call search friend rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call search friend rpc server failed"})
return
}
log.InfoByArgs("call search friend rpc server success,args=%s", RpcResp.String())
if RpcResp.ErrorCode == 0 {
resp := gin.H{
"errCode": RpcResp.ErrorCode,
"errMsg": RpcResp.ErrorMsg,
"data": gin.H{
"uid": RpcResp.Data.Uid,
"icon": RpcResp.Data.Icon,
"name": RpcResp.Data.Name,
"gender": RpcResp.Data.Gender,
"mobile": RpcResp.Data.Mobile,
"birth": RpcResp.Data.Birth,
"email": RpcResp.Data.Email,
"ex": RpcResp.Data.Ex,
"comment": RpcResp.Data.Comment,
"isFriend": RpcResp.Data.IsFriend,
"isInBlackList": RpcResp.Data.IsInBlackList,
},
}
c.JSON(http.StatusOK, resp)
} else {
resp := gin.H{
"errCode": RpcResp.ErrorCode,
"errMsg": RpcResp.ErrorMsg,
}
c.JSON(http.StatusOK, resp)
}
log.InfoByArgs("api search_friend success return,get args=%s,return=%s", req.String(), RpcResp.String())
}
package friend
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbFriend "Open_IM/src/proto/friend"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsSetFriendComment struct {
OperationID string `json:"operationID" binding:"required"`
UID string `json:"uid" binding:"required"`
Comment string `json:"comment"`
}
func SetFriendComment(c *gin.Context) {
log.Info("", "", "api set friend comment init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
params := paramsSetFriendComment{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.SetFriendCommentReq{
Uid: params.UID,
OperationID: params.OperationID,
Comment: params.Comment,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api set friend comment is server")
RpcResp, err := client.SetFriendComment(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call set friend comment rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call set friend comment rpc server failed"})
return
}
log.Info("", "", "call set friend comment rpc server success,args=%s", RpcResp.String())
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
log.Info("", "", "api set friend comment success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}
package user
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbUser "Open_IM/src/proto/user"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type userInfo struct {
UID string `json:"uid"`
Name string `json:"name"`
Icon string `json:"icon"`
Gender int32 `json:"gender"`
Mobile string `json:"mobile"`
Birth string `json:"birth"`
Email string `json:"email"`
Ex string `json:"ex"`
}
func GetUserInfo(c *gin.Context) {
log.InfoByKv("api get userinfo init...", "")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
client := pbUser.NewUserClient(etcdConn)
params := paramsStruct{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbUser.GetUserInfoReq{
UserIDList: params.UIDList,
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.InfoByKv("api get user info is server", c.PostForm("OperationID"), c.Request.Header.Get("token"))
RpcResp, err := client.GetUserInfo(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call get user info rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{
"errorCode": 500,
"errorMsg": "call rpc server failed",
})
return
}
log.InfoByKv("call get user info rpc server success", params.OperationID)
if RpcResp.ErrorCode == 0 {
userInfoList := make([]userInfo, 0)
for _, user := range RpcResp.Data {
var ui userInfo
ui.UID = user.Uid
ui.Name = user.Name
ui.Icon = user.Icon
ui.Gender = user.Gender
ui.Mobile = user.Mobile
ui.Birth = user.Birth
ui.Email = user.Email
ui.Ex = user.Ex
userInfoList = append(userInfoList, ui)
}
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": userInfoList}
c.JSON(http.StatusOK, resp)
} else {
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
}
log.InfoByKv("api get user info return success", params.OperationID, "args=%s", RpcResp.String())
}
package user
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbUser "Open_IM/src/proto/user"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type paramsStruct struct {
OperationID string `json:"operationID" binding:"required"`
UIDList []string `json:"uidList"`
Platform int32 `json:"platform"`
Name string `json:"name"`
Icon string `json:"icon"`
Gender int32 `json:"gender"`
Mobile string `json:"mobile"`
Birth string `json:"birth"`
Email string `json:"email"`
Ex string `json:"ex"`
}
func UpdateUserInfo(c *gin.Context) {
log.InfoByKv("api update userinfo init...", "")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
client := pbUser.NewUserClient(etcdConn)
params := paramsStruct{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbUser.UpdateUserInfoReq{
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
Name: params.Name,
Icon: params.Icon,
Gender: params.Gender,
Mobile: params.Mobile,
Birth: params.Birth,
Email: params.Email,
Ex: params.Ex,
}
log.InfoByKv("api update user info is server", req.OperationID, req.Token)
RpcResp, err := client.UpdateUserInfo(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call get user info rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
log.InfoByKv("call update user info rpc server success", params.OperationID)
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
log.InfoByKv("api update user info return success", params.OperationID, "args=%s", RpcResp.String())
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册