merge code

This commit is contained in:
wangchuxiao
2022-02-14 10:46:32 +08:00
46 changed files with 2201 additions and 1780 deletions
+39 -7
View File
@@ -245,6 +245,7 @@ func CreateGroup(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
//
req := &rpc.CreateGroupReq{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(req.GroupInfo, &params)
@@ -290,13 +291,13 @@ func GetRecvGroupApplicationList(c *gin.Context) {
}
req := &rpc.GetGroupApplicationListReq{}
utils.CopyStructFields(req, params)
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
//var ok bool
//ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
//if !ok {
// log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
// return
//}
log.NewInfo(req.OperationID, "GetGroupApplicationList args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
@@ -314,6 +315,37 @@ func GetRecvGroupApplicationList(c *gin.Context) {
c.JSON(http.StatusOK, resp)
}
func GetUserReqGroupApplicationList(c *gin.Context) {
var params api.GetUserReqGroupApplicationListReq
if err := c.BindJSON(&params); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &rpc.GetUserReqApplicationListReq{}
utils.CopyStructFields(req, params)
//ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
//if !ok {
// log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
// return
//}
log.NewInfo(req.OperationID, "GetGroupsInfo args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := rpc.NewGroupClient(etcdConn)
RpcResp, err := client.GetUserReqApplicationList(context.Background(), req)
if err != nil {
log.NewError(req.OperationID, "GetGroupsInfo failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
log.NewInfo(req.OperationID, RpcResp)
resp := api.GetGroupApplicationListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, GroupRequestList: RpcResp.GroupRequestList}
log.NewInfo(req.OperationID, "GetGroupApplicationList api return ", resp)
resp.Data = jsonData.JsonDataList(resp.GroupRequestList)
c.JSON(http.StatusOK, resp)
}
func GetGroupsInfo(c *gin.Context) {
params := api.GetGroupInfoReq{}
if err := c.BindJSON(&params); err != nil {
+1 -1
View File
@@ -45,7 +45,7 @@ func GetUsersInfo(c *gin.Context) {
var publicUserInfoList []*open_im_sdk.PublicUserInfo
for _, v := range RpcResp.UserInfoList {
publicUserInfoList = append(publicUserInfoList,
&open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, AppMangerLevel: v.AppMangerLevel})
&open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender})
}
resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
+25 -67
View File
@@ -1,16 +1,16 @@
package register
import (
api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
http2 "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"bytes"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
)
@@ -19,16 +19,15 @@ type ParamsLogin struct {
PhoneNumber string `json:"phoneNumber"`
Password string `json:"password"`
Platform int32 `json:"platform"`
OperationID string `json:"operationID" binding:"required"`
}
func Login(c *gin.Context) {
log.NewDebug("Login api is statrting...")
params := ParamsLogin{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
var account string
if params.Email != "" {
account = params.Email
@@ -36,77 +35,36 @@ func Login(c *gin.Context) {
account = params.PhoneNumber
}
log.InfoByKv("api Login get params", account)
queryParams := im_mysql_model.Register{
Account: account,
Password: params.Password,
}
canLogin := im_mysql_model.Login(&queryParams)
if canLogin == 1 {
log.ErrorByKv("Incorrect phone number password", account, "err", "Mobile phone number is not registered")
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Mobile phone number is not registered"})
return
}
if canLogin == 2 {
log.ErrorByKv("Incorrect phone number password", account, "err", "Incorrect password")
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Incorrect password"})
return
}
resp, err := OpenIMToken(account, params.Platform)
r, err := im_mysql_model.GetRegister(account)
if err != nil {
log.ErrorByKv("get token by phone number err", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.HttpError, "errMsg": err.Error()})
log.NewError(params.OperationID, "user have not register", params.Password, account)
c.JSON(http.StatusOK, gin.H{"errCode": constant.NotRegistered, "errMsg": "Mobile phone number is not registered"})
return
}
response, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
log.ErrorByKv("Failed to read file", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IoError, "errMsg": err.Error()})
if r.Password != params.Password {
log.NewError(params.OperationID, "password err", params.Password, account, r.Password, r.Account)
c.JSON(http.StatusOK, gin.H{"errCode": constant.PasswordErr, "errMsg": "Mobile phone number is not registered"})
return
}
imRep := IMRegisterResp{}
err = json.Unmarshal(response, &imRep)
if err != nil {
log.ErrorByKv("json parsing failed", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
if imRep.ErrCode != 0 {
log.ErrorByKv("openIM Login request failed", account, "err")
c.JSON(http.StatusOK, gin.H{"errCode": constant.HttpError, "errMsg": imRep.ErrMsg})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": imRep.Data})
return
}
func OpenIMToken(Account string, platform int32) (*http.Response, error) {
url := fmt.Sprintf("http://%s:10000/auth/user_token", utils.ServerIP)
client := &http.Client{}
params := make(map[string]interface{})
params["secret"] = config.Config.Secret
params["platform"] = platform
params["uid"] = Account
con, err := json.Marshal(params)
openIMGetUserToken := api.UserTokenReq{}
openIMGetUserToken.OperationID = params.OperationID
openIMGetUserToken.Platform = params.Platform
openIMGetUserToken.Secret = config.Config.Secret
openIMGetUserToken.UserID = account
openIMGetUserTokenResp := api.UserTokenResp{}
bMsg, err := http2.Post(url, openIMGetUserToken, config.Config.MessageCallBack.CallBackTimeOut)
if err != nil {
log.ErrorByKv("json parsing failed", Account, "err", err.Error())
return nil, err
log.NewError(params.OperationID, "request openIM get user token error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.GetIMTokenErr, "errMsg": err.Error()})
return
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(con)))
if err != nil {
log.ErrorByKv("request error", "/auth/user_token", "err", err.Error())
return nil, err
err = json.Unmarshal(bMsg, &openIMGetUserTokenResp)
if err != nil || openIMGetUserTokenResp.ErrCode != 0 {
log.NewError(params.OperationID, "request get user token", account, "err", "")
c.JSON(http.StatusOK, gin.H{"errCode": constant.GetIMTokenErr, "errMsg": ""})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMGetUserTokenResp.UserToken})
resp, err := client.Do(req)
return resp, err
}
+29 -61
View File
@@ -10,7 +10,6 @@ import (
openapi "github.com/alibabacloud-go/darabonba-openapi/client"
dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v2/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/garyburd/redigo/redis"
"github.com/gin-gonic/gin"
"gopkg.in/gomail.v2"
"math/rand"
@@ -21,39 +20,44 @@ import (
type paramsVerificationCode struct {
Email string `json:"email"`
PhoneNumber string `json:"phoneNumber"`
OperationID string `json:"operationID" binding:"required"`
}
func SendVerificationCode(c *gin.Context) {
log.InfoByKv("sendCode api is statrting...", "")
params := paramsVerificationCode{}
if err := c.BindJSON(&params); err != nil {
log.ErrorByKv("request params json parsing failed", params.PhoneNumber, params.Email, "err", err.Error())
log.NewError("", "BindJSON failed", "err:", err.Error(), "phoneNumber", params.PhoneNumber, "email", params.Email)
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
var account string
if params.Email != "" {
account = params.Email
} else {
account = params.PhoneNumber
}
queryParams := im_mysql_model.GetRegisterParams{
Account: account,
}
_, err, rowsAffected := im_mysql_model.GetRegister(&queryParams)
if err == nil && rowsAffected != 0 {
log.ErrorByKv("The phone number has been registered", queryParams.Account, "err")
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "The phone number has been registered"})
_, err := im_mysql_model.GetRegister(account)
if err == nil {
log.NewError(params.OperationID, "The phone number has been registered", params)
c.JSON(http.StatusOK, gin.H{"errCode": constant.HasRegistered, "errMsg": ""})
return
}
ok, err := db.DB.JudgeAccountEXISTS(account)
if ok || err != nil {
log.NewError(params.OperationID, "The phone number has been registered", params)
c.JSON(http.StatusOK, gin.H{"errCode": constant.RepeatSendCode, "errMsg": ""})
return
}
log.InfoByKv("begin sendSms", account)
rand.Seed(time.Now().UnixNano())
code := 100000 + rand.Intn(900000)
log.NewInfo(params.OperationID, "begin store redis", account)
err = db.DB.SetAccountCode(account, code, config.Config.Demo.CodeTTL)
if err != nil {
log.NewError(params.OperationID, "set redis error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.SmsSendCodeErr, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
log.NewDebug("", config.Config.Demo)
if params.Email != "" {
m := gomail.NewMessage()
@@ -63,14 +67,14 @@ func SendVerificationCode(c *gin.Context) {
m.SetBody(`text/html`, fmt.Sprintf("%d", code))
if err := gomail.NewDialer(config.Config.Demo.Mail.SmtpAddr, config.Config.Demo.Mail.SmtpPort, config.Config.Demo.Mail.SenderMail, config.Config.Demo.Mail.SenderAuthorizationCode).DialAndSend(m); err != nil {
log.ErrorByKv("send mail error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": err.Error()})
c.JSON(http.StatusOK, gin.H{"errCode": constant.MailSendCodeErr, "errMsg": ""})
return
}
} else {
client, err := CreateClient(tea.String(config.Config.Demo.AliSMSVerify.AccessKeyID), tea.String(config.Config.Demo.AliSMSVerify.AccessKeySecret))
if err != nil {
log.ErrorByKv("create sendSms client err", "", "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
log.NewError(params.OperationID, "create sendSms client err", "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.SmsSendCodeErr, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
@@ -83,56 +87,20 @@ func SendVerificationCode(c *gin.Context) {
response, err := client.SendSms(sendSmsRequest)
if err != nil {
log.ErrorByKv("sendSms error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
log.NewError(params.OperationID, "sendSms error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.SmsSendCodeErr, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
if *response.Body.Code != "OK" {
log.ErrorByKv("alibabacloud sendSms error", account, "err", response.Body.Code, response.Body.Message)
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
log.NewError(params.OperationID, "alibabacloud sendSms error", account, "err", response.Body.Code, response.Body.Message)
c.JSON(http.StatusOK, gin.H{"errCode": constant.SmsSendCodeErr, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
}
log.InfoByKv("begin store redis", account)
v, err := redis.Int(db.DB.Exec("TTL", account))
if err != nil {
log.ErrorByKv("get account from redis error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
switch {
case v == -2:
_, err = db.DB.Exec("SET", account, code, "EX", 600)
if err != nil {
log.ErrorByKv("set redis error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "Verification code sent successfully!", "data": data})
log.InfoByKv("send new verification code", account)
return
case v > 540:
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Frequent operation!", "data": data})
log.InfoByKv("frequent operation", account)
return
case v < 540:
_, err = db.DB.Exec("SET", account, code, "EX", 600)
if err != nil {
c.JSON(http.StatusOK, gin.H{"errCode": constant.IntentionalError, "errMsg": "Enterthe superCode directly in the verification code box, SuperCode can be configured in config.xml"})
return
}
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "Verification code has been reset!", "data": data})
log.InfoByKv("Reset verification code", account)
return
}
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "Verification code has been set!", "data": data})
}
func CreateClient(accessKeyId *string, accessKeySecret *string) (result *dysmsapi20170525.Client, err error) {
+35 -109
View File
@@ -1,18 +1,18 @@
package register
import (
api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
http2 "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"bytes"
"encoding/json"
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
)
@@ -21,135 +21,61 @@ type ParamsSetPassword struct {
PhoneNumber string `json:"phoneNumber"`
Password string `json:"password"`
VerificationCode string `json:"verificationCode"`
}
type Data struct {
ExpiredTime int64 `json:"expiredTime"`
Token string `json:"token"`
Uid string `json:"uid"`
}
type IMRegisterResp struct {
Data Data `json:"data"`
ErrCode int32 `json:"errCode"`
ErrMsg string `json:"errMsg"`
Platform int32 `json:"platform" binding:"required,min=1,max=7"`
Ex string `json:"ex"`
OperationID string `json:"operationID" binding:"required"`
}
func SetPassword(c *gin.Context) {
log.InfoByKv("setPassword api is statrting...", "")
params := ParamsSetPassword{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
var account string
if params.Email != "" {
account = params.Email
} else {
account = params.PhoneNumber
}
log.InfoByKv("begin store redis", account)
v, err := redis.String(db.DB.Exec("GET", account))
if params.VerificationCode == config.Config.Demo.SuperCode {
goto openIMRegisterTab
if params.VerificationCode != config.Config.Demo.SuperCode {
v, err := redis.String(db.DB.Exec("GET", account))
if err != nil || v != params.VerificationCode {
log.NewError(params.OperationID, "password Verification code error", account, params.VerificationCode)
data := make(map[string]interface{})
data["PhoneNumber"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.CodeInvalidOrExpired, "errMsg": "Verification code error!", "data": data})
return
}
}
fmt.Println("Get Redis:", v, err)
url := fmt.Sprintf("http://%s:10000/auth/user_register", utils.ServerIP)
openIMRegisterReq := api.UserRegisterReq{}
openIMRegisterReq.OperationID = params.OperationID
openIMRegisterReq.Platform = params.Platform
openIMRegisterReq.UserID = account
openIMRegisterReq.Nickname = account
openIMRegisterReq.Secret = config.Config.Secret
openIMRegisterResp := api.UserRegisterResp{}
bMsg, err := http2.Post(url, openIMRegisterReq, config.Config.MessageCallBack.CallBackTimeOut)
if err != nil {
log.ErrorByKv("password Verification code expired", account, "err", err.Error())
data := make(map[string]interface{})
data["phoneNumber"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Verification expired!", "data": data})
log.NewError(params.OperationID, "request openIM register error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": err.Error()})
return
}
if v != params.VerificationCode {
log.InfoByKv("password Verification code error", account, params.VerificationCode)
data := make(map[string]interface{})
data["PhoneNumber"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Verification code error!", "data": data})
err = json.Unmarshal(bMsg, &openIMRegisterResp)
if err != nil || openIMRegisterResp.ErrCode != 0 {
log.NewError(params.OperationID, "request openIM register error", account, "err", "")
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": ""})
return
}
openIMRegisterTab:
log.InfoByKv("openIM register begin", account)
resp, err := OpenIMRegister(account)
log.InfoByKv("openIM register resp", account, resp, err)
log.Info(params.OperationID, "begin store mysql", account, params.Password)
err = im_mysql_model.SetPassword(account, params.Password, params.Ex)
if err != nil {
log.ErrorByKv("request openIM register error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.HttpError, "errMsg": err.Error()})
log.NewError(params.OperationID, "set phone number password error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": err.Error()})
return
}
response, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
c.JSON(http.StatusOK, gin.H{"errCode": constant.IoError, "errMsg": err.Error()})
return
}
imrep := IMRegisterResp{}
err = json.Unmarshal(response, &imrep)
if err != nil {
c.JSON(http.StatusOK, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
if imrep.ErrCode != 0 {
c.JSON(http.StatusOK, gin.H{"errCode": constant.HttpError, "errMsg": imrep.ErrMsg})
return
}
queryParams := im_mysql_model.SetPasswordParams{
Account: account,
Password: params.Password,
}
log.InfoByKv("begin store mysql", account, params.Password)
_, err = im_mysql_model.SetPassword(&queryParams)
if err != nil {
log.ErrorByKv("set phone number password error", account, "err", err.Error())
c.JSON(http.StatusOK, gin.H{"errCode": constant.DatabaseError, "errMsg": err.Error()})
return
}
log.InfoByKv("end setPassword", account)
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": imrep.Data})
log.Info(params.OperationID, "end setPassword", account, params.Password)
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMRegisterResp.UserToken})
return
}
func OpenIMRegister(account string) (*http.Response, error) {
url := fmt.Sprintf("http://%s:10000/auth/user_register", utils.ServerIP)
fmt.Println("1:", config.Config.Secret)
client := &http.Client{}
params := make(map[string]interface{})
params["secret"] = config.Config.Secret
params["platform"] = 2
params["uid"] = account
params["name"] = account
params["icon"] = ""
params["gender"] = 0
params["mobile"] = ""
params["email"] = ""
params["birth"] = ""
params["ex"] = ""
con, err := json.Marshal(params)
if err != nil {
return nil, err
}
log.InfoByKv("openIM register params", account, params)
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(con)))
if err != nil {
return nil, err
}
resp, err := client.Do(req)
return resp, err
}
+12 -13
View File
@@ -6,7 +6,6 @@ import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"github.com/garyburd/redigo/redis"
"github.com/gin-gonic/gin"
"net/http"
)
@@ -15,14 +14,13 @@ type paramsCertification struct {
Email string `json:"email"`
PhoneNumber string `json:"phoneNumber"`
VerificationCode string `json:"verificationCode"`
OperationID string `json:"operationID" binding:"required"`
}
func Verify(c *gin.Context) {
log.InfoByKv("Verify api is statrting...", "")
params := paramsCertification{}
if err := c.BindJSON(&params); err != nil {
log.ErrorByKv("request params json parsing failed", "", "err", err.Error())
log.NewError("", "request params json parsing failed", "", "err", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
return
}
@@ -44,27 +42,28 @@ func Verify(c *gin.Context) {
return
}
log.NewInfo("0", " params.VerificationCode != config.Config.Demo.SuperCode", params.VerificationCode, config.Config.Demo)
log.InfoByKv("begin get form redis", account)
v, err := redis.String(db.DB.Exec("GET", account))
log.InfoByKv("redis phone number and verificating Code", account, v)
log.NewInfo(params.OperationID, "begin get form redis", account)
code, err := db.DB.GetAccountCode(account)
log.NewInfo(params.OperationID, "redis phone number and verificating Code", account, code)
if err != nil {
log.ErrorByKv("Verification code expired", account, "err", err.Error())
log.NewError(params.OperationID, "Verification code expired", account, "err", err.Error())
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Verification code expired!", "data": data})
c.JSON(http.StatusOK, gin.H{"errCode": constant.CodeInvalidOrExpired, "errMsg": "Verification code expired!", "data": data})
return
}
if params.VerificationCode == v {
log.InfoByKv("Verified successfully", account)
if params.VerificationCode == code {
log.Info(params.OperationID, "Verified successfully", account)
data := make(map[string]interface{})
data["account"] = account
data["verificationCode"] = params.VerificationCode
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "Verified successfully!", "data": data})
return
} else {
log.InfoByKv("Verification code error", account, params.VerificationCode)
log.Info(params.OperationID, "Verification code error", account, params.VerificationCode)
data := make(map[string]interface{})
data["account"] = account
c.JSON(http.StatusOK, gin.H{"errCode": constant.LogicalError, "errMsg": "Verification code error!", "data": data})
c.JSON(http.StatusOK, gin.H{"errCode": constant.CodeInvalidOrExpired, "errMsg": "Verification code error!", "data": data})
}
}
+1 -7
View File
@@ -71,7 +71,7 @@ func (r *RPCServer) OnlinePushMsg(_ context.Context, in *pbRelay.OnlinePushMsgRe
log.NewError(in.OperationID, "data encode err", err.Error())
}
var tag bool
recvID := in.MsgData.RecvID
recvID := in.PushToUserID
platformList := genPlatformArray()
for _, v := range platformList {
if conn := ws.getUserConn(recvID, v); conn != nil {
@@ -92,12 +92,6 @@ func (r *RPCServer) OnlinePushMsg(_ context.Context, in *pbRelay.OnlinePushMsgRe
resp = append(resp, temp)
}
}
//Single chat sender synchronization message
if in.MsgData.GetSessionType() == constant.SingleChatType {
for k, v := range ws.getSingleUserAllConn(in.MsgData.SendID) {
_ = sendMsgToUser(v, replyBytes.Bytes(), in, k, in.MsgData.SendID)
}
}
if !tag {
log.NewError(in.OperationID, "push err ,no matched ws conn not in map", in.String())
}
@@ -45,6 +45,7 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
isHistory := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsHistory)
//Control whether to store history messages (mysql)
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
isSenderSync := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsSenderSync)
switch msgFromMQ.MsgData.SessionType {
case constant.SingleChatType:
log.NewDebug(msgFromMQ.OperationID, "msg_transfer msg type = SingleChatType", isHistory, isPersist)
@@ -55,6 +56,8 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String())
return
}
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time)
} else if msgKey == msgFromMQ.MsgData.SendID {
err := saveUserChat(msgFromMQ.MsgData.SendID, &msgFromMQ)
@@ -62,15 +65,12 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String())
return
}
if isSenderSync {
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.SendID)
}
}
log.NewDebug(operationID, "saveUserChat cost time ", utils.GetCurrentTimestampByNano()-time)
}
if msgKey == msgFromMQ.MsgData.RecvID {
go sendMessageToPush(&msgFromMQ)
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time)
}
case constant.GroupChatType:
log.NewDebug(msgFromMQ.OperationID, "msg_transfer msg type = GroupChatType", isHistory, isPersist)
if isHistory {
@@ -80,7 +80,7 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
return
}
}
go sendMessageToPush(&msgFromMQ)
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
default:
log.NewError(msgFromMQ.OperationID, "SessionType error", msgFromMQ.String())
return
@@ -99,10 +99,10 @@ func (mc *HistoryConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSession,
}
return nil
}
func sendMessageToPush(message *pbMsg.MsgDataToMQ) {
func sendMessageToPush(message *pbMsg.MsgDataToMQ, pushToUserID string) {
log.InfoByKv("msg_transfer send message to push", message.OperationID, "message", message.String())
rpcPushMsg := pbPush.PushMsgReq{OperationID: message.OperationID, MsgData: message.MsgData}
mqPushMsg := pbMsg.PushMsgDataToMQ{OperationID: message.OperationID, MsgData: message.MsgData}
rpcPushMsg := pbPush.PushMsgReq{OperationID: message.OperationID, MsgData: message.MsgData, PushToUserID: pushToUserID}
mqPushMsg := pbMsg.PushMsgDataToMQ{OperationID: message.OperationID, MsgData: message.MsgData, PushToUserID: pushToUserID}
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImPushName)
if grpcConn == nil {
log.ErrorByKv("rpc dial failed", rpcPushMsg.OperationID, "push data", rpcPushMsg.String())
+2 -2
View File
@@ -41,7 +41,7 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
log.InfoByKv("test", pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String())
for _, v := range grpcCons {
msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v)
reply, err := msgClient.OnlinePushMsg(context.Background(), &pbRelay.OnlinePushMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData})
reply, err := msgClient.OnlinePushMsg(context.Background(), &pbRelay.OnlinePushMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData, PushToUserID: pushMsg.PushToUserID})
if err != nil {
log.InfoByKv("push data to client rpc err", pushMsg.OperationID, "err", err)
continue
@@ -51,7 +51,7 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
}
}
log.InfoByKv("push_result", pushMsg.OperationID, "result", wsResult, "sendData", pushMsg.MsgData)
if isOfflinePush {
if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID {
for _, v := range wsResult {
if v.ResultCode == 0 {
continue
+39 -37
View File
@@ -101,11 +101,12 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
}
//Establish a latest relationship in the friend request table
friendRequest := db.FriendRequest{ReqMsg: req.ReqMsg}
friendRequest := db.FriendRequest{ReqMsg: req.ReqMsg, HandleResult: 0, CreateTime: time.Now()}
utils.CopyStructFields(&friendRequest, req.CommID)
// {openIM001 openIM002 0 test add friend 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC }]
log.NewDebug(req.CommID.OperationID, "UpdateFriendApplication args ", friendRequest)
err := imdb.InsertFriendApplication(&friendRequest)
//err := imdb.InsertFriendApplication(&friendRequest)
err := imdb.InsertFriendApplication(&friendRequest, map[string]interface{}{"handle_result": 0})
if err != nil {
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
@@ -404,24 +405,25 @@ func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.Get
var appleUserList []*sdkws.FriendRequest
for _, applyUserInfo := range ApplyUsersInfo {
var userInfo sdkws.FriendRequest
utils.CopyStructFields(&userInfo, applyUserInfo)
u, err := imdb.GetUserByUserID(userInfo.FromUserID)
if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
continue
}
userInfo.FromNickname = u.Nickname
userInfo.FromFaceURL = u.FaceURL
userInfo.FromGender = u.Gender
u, err = imdb.GetUserByUserID(userInfo.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
continue
}
userInfo.ToNickname = u.Nickname
userInfo.ToFaceURL = u.FaceURL
userInfo.ToGender = u.Gender
cp.FriendRequestDBCopyOpenIM(&userInfo, &applyUserInfo)
// utils.CopyStructFields(&userInfo, applyUserInfo)
// u, err := imdb.GetUserByUserID(userInfo.FromUserID)
// if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
// continue
// }
// userInfo.FromNickname = u.Nickname
// userInfo.FromFaceURL = u.FaceURL
// userInfo.FromGender = u.Gender
//
// u, err = imdb.GetUserByUserID(userInfo.ToUserID)
// if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
// continue
// }
// userInfo.ToNickname = u.Nickname
// userInfo.ToFaceURL = u.FaceURL
// userInfo.ToGender = u.Gender
appleUserList = append(appleUserList, &userInfo)
}
@@ -447,23 +449,23 @@ func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetSe
for _, selfApplyOtherUserInfo := range usersInfo {
var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo
cp.FriendRequestDBCopyOpenIM(&userInfo, &selfApplyOtherUserInfo)
u, err := imdb.GetUserByUserID(userInfo.FromUserID)
if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
continue
}
userInfo.FromNickname = u.Nickname
userInfo.FromFaceURL = u.FaceURL
userInfo.FromGender = u.Gender
u, err = imdb.GetUserByUserID(userInfo.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
continue
}
userInfo.ToNickname = u.Nickname
userInfo.ToFaceURL = u.FaceURL
userInfo.ToGender = u.Gender
//u, err := imdb.GetUserByUserID(userInfo.FromUserID)
//if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
// continue
//}
//userInfo.FromNickname = u.Nickname
//userInfo.FromFaceURL = u.FaceURL
//userInfo.FromGender = u.Gender
//
//u, err = imdb.GetUserByUserID(userInfo.ToUserID)
//if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
// continue
//}
//userInfo.ToNickname = u.Nickname
//userInfo.ToFaceURL = u.FaceURL
//userInfo.ToGender = u.Gender
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
}
+41 -2
View File
@@ -480,7 +480,7 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
member.UserID = req.FromUserID
member.RoleLevel = constant.GroupOrdinaryUsers
member.OperatorUserID = req.OpUserID
member.FaceUrl = user.FaceURL
member.FaceURL = user.FaceURL
member.Nickname = user.Nickname
err = imdb.InsertIntoGroupMember(member)
@@ -597,7 +597,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
if group.Introduction != req.GroupInfo.Introduction && req.GroupInfo.Introduction != "" {
changedType = changedType | (1 << 2)
}
if group.FaceUrl != req.GroupInfo.FaceURL && req.GroupInfo.FaceURL != "" {
if group.FaceURL != req.GroupInfo.FaceURL && req.GroupInfo.FaceURL != "" {
changedType = changedType | (1 << 3)
}
//only administrators can set group information
@@ -877,3 +877,42 @@ func (s *groupServer) SetGroupMaster(_ context.Context, req *pbGroup.SetGroupMas
}
return resp, nil
}
func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbGroup.GetUserReqApplicationListResp{}
groupRequests, err := imdb.GetUserReqGroupByUserID(req.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserReqGroupByUserID failed ", err.Error())
resp.CommonResp = &pbGroup.CommonResp{
ErrCode: constant.ErrDB.ErrCode,
ErrMsg: constant.ErrDB.ErrMsg,
}
return resp, nil
}
for _, groupReq := range groupRequests {
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
group, err := imdb.GetGroupInfoByGroupID(groupReq.GroupID)
if err != nil {
log.Error(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupReq.GroupID)
continue
}
user, err := imdb.GetUserByUserID(groupReq.UserID)
if err != nil {
log.Error(req.OperationID, "GetUserByUserID failed ", err.Error(), groupReq.UserID)
continue
}
cp.GroupRequestDBCopyOpenIM(&node, &groupReq)
cp.UserDBCopyOpenIMPublicUser(node.UserInfo, user)
cp.GroupDBCopyOpenIM(node.GroupInfo, group)
resp.GroupRequestList = append(resp.GroupRequestList, &node)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), groupRequests)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "output:", resp)
resp.CommonResp = &pbGroup.CommonResp{
ErrCode: 0,
ErrMsg: "",
}
return resp, nil
}
+13 -3
View File
@@ -9,6 +9,7 @@ import (
pbFriend "Open_IM/pkg/proto/friend"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
@@ -34,6 +35,14 @@ func friendNotification(commID *pbFriend.CommID, contentType int32, m proto.Mess
return
}
marshaler := jsonpb.Marshaler{
OrigName: true,
EnumsAsInts: false,
EmitDefaults: false,
}
tips.JsonDetail, _ = marshaler.MarshalToString(m)
fromUserNickname, toUserNickname, err := getFromToUserNickname(commID.FromUserID, commID.ToUserID)
if err != nil {
log.Error(commID.OperationID, "getFromToUserNickname failed ", err.Error(), commID.FromUserID, commID.ToUserID)
@@ -54,9 +63,11 @@ func friendNotification(commID *pbFriend.CommID, contentType int32, m proto.Mess
case constant.FriendRemarkSetNotification:
tips.DefaultTips = fromUserNickname + cn.FriendRemarkSet.DefaultTips.Tips
case constant.BlackAddedNotification:
tips.DefaultTips = cn.BlackAdded.DefaultTips.Tips + toUserNickname
tips.DefaultTips = cn.BlackAdded.DefaultTips.Tips
case constant.BlackDeletedNotification:
tips.DefaultTips = cn.BlackDeleted.DefaultTips.Tips + toUserNickname
case constant.UserInfoUpdatedNotification:
tips.DefaultTips = cn.UserInfoUpdated.DefaultTips.Tips
default:
log.Error(commID.OperationID, "contentType failed ", contentType)
return
@@ -101,7 +112,6 @@ func FriendApplicationRejectedNotification(req *pbFriend.AddFriendResponseReq) {
}
func FriendAddedNotification(operationID, opUserID, fromUserID, toUserID string) {
return
friendAddedTips := open_im_sdk.FriendAddedTips{Friend: &open_im_sdk.FriendInfo{}, OpUser: &open_im_sdk.PublicUserInfo{}}
user, err := imdb.GetUserByUserID(opUserID)
if err != nil {
@@ -150,6 +160,6 @@ func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
func UserInfoUpdatedNotification(operationID, userID string, needNotifiedUserID string) {
selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: userID}
commID := pbFriend.CommID{FromUserID: userID, ToUserID: userID, OpUserID: needNotifiedUserID, OperationID: operationID}
commID := pbFriend.CommID{FromUserID: userID, ToUserID: needNotifiedUserID, OpUserID: userID, OperationID: operationID}
friendNotification(&commID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
}
+71 -19
View File
@@ -10,6 +10,7 @@ import (
pbGroup "Open_IM/pkg/proto/group"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
@@ -30,12 +31,21 @@ func setOpUserInfo(opUserID, groupID string, groupMemberInfo *open_im_sdk.GroupM
groupMemberInfo.GroupID = groupID
} else {
u, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, opUserID)
if err != nil {
return utils.Wrap(err, "GetGroupMemberInfoByGroupIDAndUserID failed")
if err == nil {
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, u); err != nil {
return utils.Wrap(err, "")
}
}
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, u); err != nil {
user, err := imdb.GetUserByUserID(opUserID)
if err != nil {
return utils.Wrap(err, "")
}
groupMemberInfo.GroupID = groupID
groupMemberInfo.UserID = user.UserID
groupMemberInfo.Nickname = user.Nickname
groupMemberInfo.AppMangerLevel = user.AppMangerLevel
groupMemberInfo.FaceURL = user.FaceURL
}
return nil
}
@@ -54,12 +64,19 @@ func setGroupInfo(groupID string, groupInfo *open_im_sdk.GroupInfo) error {
func setGroupMemberInfo(groupID, userID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
groupMember, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
if err == nil {
return utils.Wrap(utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, groupMember), "")
}
user, err := imdb.GetUserByUserID(userID)
if err != nil {
return utils.Wrap(err, "")
}
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, groupMember); err != nil {
return utils.Wrap(err, "")
}
groupMemberInfo.GroupID = groupID
groupMemberInfo.UserID = user.UserID
groupMemberInfo.Nickname = user.Nickname
groupMemberInfo.AppMangerLevel = user.AppMangerLevel
groupMemberInfo.FaceURL = user.FaceURL
return nil
}
@@ -93,19 +110,54 @@ func groupNotification(contentType int32, m proto.Message, sendID, groupID, recv
log.Error(operationID, "Marshal failed ", err.Error(), m.String())
return
}
marshaler := jsonpb.Marshaler{
OrigName: true,
EnumsAsInts: false,
EmitDefaults: false,
}
tips.JsonDetail, _ = marshaler.MarshalToString(m)
from, err := imdb.GetUserByUserID(sendID)
if err != nil {
log.Error(operationID, "GetUserByUserID failed ", err.Error(), sendID)
}
nickname := ""
if from != nil {
nickname = from.Nickname
}
to, err := imdb.GetUserByUserID(recvUserID)
if err != nil {
log.Error(operationID, "GetUserByUserID failed ", err.Error(), recvUserID)
}
toNickname := ""
if to != nil {
toNickname = to.Nickname
}
cn := config.Config.Notification
switch contentType {
case constant.GroupCreatedNotification:
tips.DefaultTips = cn.GroupCreated.DefaultTips.Tips
tips.DefaultTips = nickname + " " + cn.GroupCreated.DefaultTips.Tips
case constant.GroupInfoSetNotification:
tips.DefaultTips = nickname + " " + cn.GroupInfoSet.DefaultTips.Tips
case constant.JoinGroupApplicationNotification:
tips.DefaultTips = nickname + " " + cn.JoinGroupApplication.DefaultTips.Tips
case constant.MemberQuitNotification:
case constant.GroupApplicationAcceptedNotification:
case constant.GroupApplicationRejectedNotification:
case constant.GroupOwnerTransferredNotification:
case constant.MemberKickedNotification:
case constant.MemberInvitedNotification:
tips.DefaultTips = nickname + " " + cn.MemberQuit.DefaultTips.Tips
case constant.GroupApplicationAcceptedNotification: //
tips.DefaultTips = toNickname + " " + cn.GroupApplicationAccepted.DefaultTips.Tips
case constant.GroupApplicationRejectedNotification: //
tips.DefaultTips = toNickname + " " + cn.GroupApplicationRejected.DefaultTips.Tips
case constant.GroupOwnerTransferredNotification: //
tips.DefaultTips = toNickname + " " + cn.GroupOwnerTransferred.DefaultTips.Tips
case constant.MemberKickedNotification: //
tips.DefaultTips = toNickname + " " + cn.MemberKicked.DefaultTips.Tips
case constant.MemberInvitedNotification: //
tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips
case constant.MemberEnterNotification:
tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips
default:
log.Error(operationID, "contentType failed ", contentType)
return
@@ -218,7 +270,7 @@ func MemberQuitNotification(req *pbGroup.QuitGroupReq) {
}
groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, req.GroupID, "", req.OperationID)
groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, "", req.OpUserID, req.OperationID)
// groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, "", req.OpUserID, req.OperationID)
}
@@ -269,7 +321,7 @@ func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) {
log.Error(req.OperationID, "setGroupMemberInfo failed", req.GroupID, req.NewOwnerUserID)
return
}
groupNotification(constant.GroupOwnerTransferredNotification, &GroupOwnerTransferredTips, req.OpUserID, "", req.NewOwnerUserID, req.OperationID)
groupNotification(constant.GroupOwnerTransferredNotification, &GroupOwnerTransferredTips, req.OpUserID, req.GroupID, "", req.OperationID)
}
//message MemberKickedTips{
@@ -298,10 +350,10 @@ func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList
MemberKickedTips.KickedUserList = append(MemberKickedTips.KickedUserList, &groupMemberInfo)
}
groupNotification(constant.MemberKickedNotification, &MemberKickedTips, req.OpUserID, req.GroupID, "", req.OperationID)
for _, v := range kickedUserIDList {
groupNotification(constant.MemberKickedNotification, &MemberKickedTips, req.OpUserID, "", v, req.OperationID)
}
//
//for _, v := range kickedUserIDList {
// groupNotification(constant.MemberKickedNotification, &MemberKickedTips, req.OpUserID, "", v, req.OperationID)
//}
}
//message MemberInvitedTips{
@@ -359,7 +411,7 @@ func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, MemberEnterTips.Group)
return
}
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberEnterTips.EntrantUser); err != nil {
if err := setGroupMemberInfo(req.GroupID, req.FromUserID, MemberEnterTips.EntrantUser); err != nil {
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID, req.GroupID, MemberEnterTips.EntrantUser)
return
}
+187 -25
View File
@@ -14,6 +14,7 @@ import (
"context"
"encoding/json"
"github.com/garyburd/redigo/redis"
"github.com/golang/protobuf/proto"
"math/rand"
"net/http"
"strconv"
@@ -165,6 +166,27 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
log.Error(pb.Token, pb.OperationID, "rpc send_msg getGroupInfo failed, err = %s", reply.ErrMsg)
return returnMsg(&replay, pb, reply.ErrCode, reply.ErrMsg, "", 0)
}
var addUidList []string
switch pb.MsgData.ContentType {
case constant.MemberKickedNotification:
var tips sdk_ws.TipsComm
var memberKickedTips sdk_ws.MemberKickedTips
err := proto.Unmarshal(pb.MsgData.Content, &tips)
if err != nil {
log.Error(pb.OperationID, "Unmarshal err", err.Error())
}
err = proto.Unmarshal(tips.Detail, &memberKickedTips)
if err != nil {
log.Error(pb.OperationID, "Unmarshal err", err.Error())
}
log.Info(pb.OperationID, "data is ", memberKickedTips)
for _, v := range memberKickedTips.KickedUserList {
addUidList = append(addUidList, v.UserID)
}
case constant.MemberQuitNotification:
addUidList = append(addUidList, pb.MsgData.SendID)
default:
}
groupID := pb.MsgData.GroupID
for _, v := range reply.MemberList {
pb.MsgData.RecvID = v.UserID
@@ -178,6 +200,21 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
}
}
}
log.Info(msgToMQ.OperationID, "addUidList", addUidList)
for _, v := range addUidList {
pb.MsgData.RecvID = v
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, pb)
log.Info(msgToMQ.OperationID, "isSend", isSend)
if isSend {
msgToMQ.MsgData = pb.MsgData
err := rpc.sendMsgToKafka(&msgToMQ, v)
if err != nil {
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v, msgToMQ.String())
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
}
}
}
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
default:
@@ -240,12 +277,12 @@ type NotificationMsg struct {
}
func Notification(n *NotificationMsg) {
return
var req pbChat.SendMsgReq
var msg sdk_ws.MsgData
var offlineInfo sdk_ws.OfflinePushInfo
var title, desc, ex string
var pushSwitch bool
var pushSwitch, unReadCount bool
var reliabilityLevel int
req.OperationID = n.OperationID
msg.SendID = n.SendID
msg.RecvID = n.RecvID
@@ -255,36 +292,161 @@ func Notification(n *NotificationMsg) {
msg.SessionType = n.SessionType
msg.CreateTime = utils.GetCurrentTimestampByMill()
msg.ClientMsgID = utils.GetMsgID(n.SendID)
msg.Options = make(map[string]bool, 7)
switch n.SessionType {
case constant.GroupChatType:
msg.RecvID = ""
msg.GroupID = n.RecvID
}
if true {
msg.Options = make(map[string]bool, 10)
//utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
}
offlineInfo.IOSBadgeCount = config.Config.IOSPush.BadgeCount
offlineInfo.IOSPushSound = config.Config.IOSPush.PushSound
//switch msg.ContentType {
//case constant.GroupCreatedNotification:
// pushSwitch = config.Config.Notification.GroupCreated.OfflinePush.PushSwitch
// title = config.Config.Notification.GroupCreated.OfflinePush.Title
// desc = config.Config.Notification.GroupCreated.OfflinePush.Desc
// ex = config.Config.Notification.GroupCreated.OfflinePush.Ext
//case constant.GroupInfoChangedNotification:
// pushSwitch = config.Config.Notification.GroupInfoChanged.OfflinePush.PushSwitch
// title = config.Config.Notification.GroupInfoChanged.OfflinePush.Title
// desc = config.Config.Notification.GroupInfoChanged.OfflinePush.Desc
// ex = config.Config.Notification.GroupInfoChanged.OfflinePush.Ext
//case constant.JoinApplicationNotification:
// pushSwitch = config.Config.Notification.ApplyJoinGroup.OfflinePush.PushSwitch
// title = config.Config.Notification.ApplyJoinGroup.OfflinePush.Title
// desc = config.Config.Notification.ApplyJoinGroup.OfflinePush.Desc
// ex = config.Config.Notification.ApplyJoinGroup.OfflinePush.Ext
//}
switch msg.ContentType {
case constant.GroupCreatedNotification:
pushSwitch = config.Config.Notification.GroupCreated.OfflinePush.PushSwitch
title = config.Config.Notification.GroupCreated.OfflinePush.Title
desc = config.Config.Notification.GroupCreated.OfflinePush.Desc
ex = config.Config.Notification.GroupCreated.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.GroupCreated.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.GroupCreated.Conversation.UnreadCount
case constant.GroupInfoSetNotification:
pushSwitch = config.Config.Notification.GroupInfoSet.OfflinePush.PushSwitch
title = config.Config.Notification.GroupInfoSet.OfflinePush.Title
desc = config.Config.Notification.GroupInfoSet.OfflinePush.Desc
ex = config.Config.Notification.GroupInfoSet.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.GroupInfoSet.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.GroupInfoSet.Conversation.UnreadCount
case constant.JoinGroupApplicationNotification:
pushSwitch = config.Config.Notification.JoinGroupApplication.OfflinePush.PushSwitch
title = config.Config.Notification.JoinGroupApplication.OfflinePush.Title
desc = config.Config.Notification.JoinGroupApplication.OfflinePush.Desc
ex = config.Config.Notification.JoinGroupApplication.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.JoinGroupApplication.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.JoinGroupApplication.Conversation.UnreadCount
case constant.MemberQuitNotification:
pushSwitch = config.Config.Notification.MemberQuit.OfflinePush.PushSwitch
title = config.Config.Notification.MemberQuit.OfflinePush.Title
desc = config.Config.Notification.MemberQuit.OfflinePush.Desc
ex = config.Config.Notification.MemberQuit.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.MemberQuit.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.MemberQuit.Conversation.UnreadCount
case constant.GroupApplicationAcceptedNotification:
pushSwitch = config.Config.Notification.GroupApplicationAccepted.OfflinePush.PushSwitch
title = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Title
desc = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Desc
ex = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.GroupApplicationAccepted.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.GroupApplicationAccepted.Conversation.UnreadCount
case constant.GroupApplicationRejectedNotification:
pushSwitch = config.Config.Notification.GroupApplicationRejected.OfflinePush.PushSwitch
title = config.Config.Notification.GroupApplicationRejected.OfflinePush.Title
desc = config.Config.Notification.GroupApplicationRejected.OfflinePush.Desc
ex = config.Config.Notification.GroupApplicationRejected.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.GroupApplicationRejected.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.GroupApplicationRejected.Conversation.UnreadCount
case constant.GroupOwnerTransferredNotification:
pushSwitch = config.Config.Notification.GroupOwnerTransferred.OfflinePush.PushSwitch
title = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Title
desc = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Desc
ex = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.GroupOwnerTransferred.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.GroupOwnerTransferred.Conversation.UnreadCount
case constant.MemberKickedNotification:
pushSwitch = config.Config.Notification.MemberKicked.OfflinePush.PushSwitch
title = config.Config.Notification.MemberKicked.OfflinePush.Title
desc = config.Config.Notification.MemberKicked.OfflinePush.Desc
ex = config.Config.Notification.MemberKicked.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.MemberKicked.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.MemberKicked.Conversation.UnreadCount
case constant.MemberInvitedNotification:
pushSwitch = config.Config.Notification.MemberInvited.OfflinePush.PushSwitch
title = config.Config.Notification.MemberInvited.OfflinePush.Title
desc = config.Config.Notification.MemberInvited.OfflinePush.Desc
ex = config.Config.Notification.MemberInvited.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.MemberInvited.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.MemberInvited.Conversation.UnreadCount
case constant.MemberEnterNotification:
pushSwitch = config.Config.Notification.MemberEnter.OfflinePush.PushSwitch
title = config.Config.Notification.MemberEnter.OfflinePush.Title
desc = config.Config.Notification.MemberEnter.OfflinePush.Desc
ex = config.Config.Notification.MemberEnter.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.MemberEnter.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.MemberEnter.Conversation.UnreadCount
case constant.UserInfoUpdatedNotification:
pushSwitch = config.Config.Notification.UserInfoUpdated.OfflinePush.PushSwitch
title = config.Config.Notification.UserInfoUpdated.OfflinePush.Title
desc = config.Config.Notification.UserInfoUpdated.OfflinePush.Desc
ex = config.Config.Notification.UserInfoUpdated.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.UserInfoUpdated.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.UserInfoUpdated.Conversation.UnreadCount
case constant.FriendApplicationNotification:
pushSwitch = config.Config.Notification.FriendApplication.OfflinePush.PushSwitch
title = config.Config.Notification.FriendApplication.OfflinePush.Title
desc = config.Config.Notification.FriendApplication.OfflinePush.Desc
ex = config.Config.Notification.FriendApplication.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.FriendApplication.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.FriendApplication.Conversation.UnreadCount
case constant.FriendApplicationApprovedNotification:
pushSwitch = config.Config.Notification.FriendApplicationApproved.OfflinePush.PushSwitch
title = config.Config.Notification.FriendApplicationApproved.OfflinePush.Title
desc = config.Config.Notification.FriendApplicationApproved.OfflinePush.Desc
ex = config.Config.Notification.FriendApplicationApproved.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.FriendApplicationApproved.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.FriendApplicationApproved.Conversation.UnreadCount
case constant.FriendApplicationRejectedNotification:
pushSwitch = config.Config.Notification.FriendApplicationRejected.OfflinePush.PushSwitch
title = config.Config.Notification.FriendApplicationRejected.OfflinePush.Title
desc = config.Config.Notification.FriendApplicationRejected.OfflinePush.Desc
ex = config.Config.Notification.FriendApplicationRejected.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.FriendApplicationRejected.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.FriendApplicationRejected.Conversation.UnreadCount
case constant.FriendAddedNotification:
pushSwitch = config.Config.Notification.FriendAdded.OfflinePush.PushSwitch
title = config.Config.Notification.FriendAdded.OfflinePush.Title
desc = config.Config.Notification.FriendAdded.OfflinePush.Desc
ex = config.Config.Notification.FriendAdded.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.FriendAdded.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.FriendAdded.Conversation.UnreadCount
case constant.FriendDeletedNotification:
pushSwitch = config.Config.Notification.FriendDeleted.OfflinePush.PushSwitch
title = config.Config.Notification.FriendDeleted.OfflinePush.Title
desc = config.Config.Notification.FriendDeleted.OfflinePush.Desc
ex = config.Config.Notification.FriendDeleted.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.FriendDeleted.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.FriendDeleted.Conversation.UnreadCount
case constant.FriendRemarkSetNotification:
pushSwitch = config.Config.Notification.FriendRemarkSet.OfflinePush.PushSwitch
title = config.Config.Notification.FriendRemarkSet.OfflinePush.Title
desc = config.Config.Notification.FriendRemarkSet.OfflinePush.Desc
ex = config.Config.Notification.FriendRemarkSet.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.FriendRemarkSet.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.FriendRemarkSet.Conversation.UnreadCount
case constant.BlackAddedNotification:
pushSwitch = config.Config.Notification.BlackAdded.OfflinePush.PushSwitch
title = config.Config.Notification.BlackAdded.OfflinePush.Title
desc = config.Config.Notification.BlackAdded.OfflinePush.Desc
ex = config.Config.Notification.BlackAdded.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.BlackAdded.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.BlackAdded.Conversation.UnreadCount
case constant.BlackDeletedNotification:
pushSwitch = config.Config.Notification.BlackDeleted.OfflinePush.PushSwitch
title = config.Config.Notification.BlackDeleted.OfflinePush.Title
desc = config.Config.Notification.BlackDeleted.OfflinePush.Desc
ex = config.Config.Notification.BlackDeleted.OfflinePush.Ext
reliabilityLevel = config.Config.Notification.BlackDeleted.Conversation.ReliabilityLevel
unReadCount = config.Config.Notification.BlackDeleted.Conversation.UnreadCount
}
switch reliabilityLevel {
case constant.UnreliableNotification:
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
case constant.ReliableNotificationNoMsg:
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
case constant.ReliableNotificationMsg:
}
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, unReadCount)
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, pushSwitch)
offlineInfo.Title = title
offlineInfo.Desc = desc
+3
View File
@@ -84,6 +84,7 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
continue
}
utils.CopyStructFields(&userInfo, user)
userInfo.Birth = uint32(user.Birth.Unix())
userInfoList = append(userInfoList, &userInfo)
}
} else {
@@ -239,9 +240,11 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
}
for _, v := range RpcResp.FriendInfoList {
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, v.FriendUser.UserID)
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID)
}
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID)
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
}