mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 19:46:57 +08:00
Merge remote-tracking branch 'origin/v2.3.0release' into v2.3.0release
This commit is contained in:
commit
0d16fbe4ab
23
cmd/open_im_cron_task/Makefile
Normal file
23
cmd/open_im_cron_task/Makefile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
.PHONY: all build run gotool install clean help
|
||||||
|
|
||||||
|
BINARY_NAME=open_im_cron_task
|
||||||
|
BIN_DIR=../../bin/
|
||||||
|
|
||||||
|
all: gotool build
|
||||||
|
|
||||||
|
build:
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
||||||
|
|
||||||
|
run:
|
||||||
|
@go run ./
|
||||||
|
|
||||||
|
gotool:
|
||||||
|
go fmt ./
|
||||||
|
go vet ./
|
||||||
|
|
||||||
|
install:
|
||||||
|
make build
|
||||||
|
mv ${BINARY_NAME} ${BIN_DIR}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
@ -252,7 +252,7 @@ singleMessageHasReadReceiptEnable: true
|
|||||||
tokenpolicy:
|
tokenpolicy:
|
||||||
accessSecret: "open_im_server" #token生成相关,默认即可
|
accessSecret: "open_im_server" #token生成相关,默认即可
|
||||||
# Token effective time day as a unit
|
# Token effective time day as a unit
|
||||||
accessExpire: 3650 #token过期时间(天) 默认即可
|
accessExpire: 90 #token过期时间(天) 默认即可
|
||||||
messageverify:
|
messageverify:
|
||||||
friendVerify: false
|
friendVerify: false
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package apiAuth
|
|||||||
import (
|
import (
|
||||||
api "Open_IM/pkg/base_info"
|
api "Open_IM/pkg/base_info"
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/common/token_verify"
|
"Open_IM/pkg/common/token_verify"
|
||||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||||
@ -10,10 +11,11 @@ import (
|
|||||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/structs"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @Summary 用户注册
|
// @Summary 用户注册
|
||||||
@ -65,11 +67,15 @@ func UserRegister(c *gin.Context) {
|
|||||||
if reply.CommonResp.ErrCode != 0 {
|
if reply.CommonResp.ErrCode != 0 {
|
||||||
errMsg := req.OperationID + " " + " UserRegister failed " + reply.CommonResp.ErrMsg + req.String()
|
errMsg := req.OperationID + " " + " UserRegister failed " + reply.CommonResp.ErrMsg + req.String()
|
||||||
log.NewError(req.OperationID, errMsg)
|
log.NewError(req.OperationID, errMsg)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
if reply.CommonResp.ErrCode == constant.RegisterLimit {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterLimit, "errMsg": "用户注册被限制"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pbDataToken := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
|
pbDataToken := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID, LoginIp: params.CreateIp}
|
||||||
replyToken, err := client.UserToken(context.Background(), pbDataToken)
|
replyToken, err := client.UserToken(context.Background(), pbDataToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := req.OperationID + " " + " client.UserToken failed " + err.Error() + pbDataToken.String()
|
errMsg := req.OperationID + " " + " client.UserToken failed " + err.Error() + pbDataToken.String()
|
||||||
@ -110,7 +116,7 @@ func UserToken(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": errMsg})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": errMsg})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
|
req := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID, LoginIp: params.LoginIp}
|
||||||
log.NewInfo(req.OperationID, "UserToken args ", req.String())
|
log.NewInfo(req.OperationID, "UserToken args ", req.String())
|
||||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName, req.OperationID)
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName, req.OperationID)
|
||||||
if etcdConn == nil {
|
if etcdConn == nil {
|
||||||
|
@ -15,6 +15,8 @@ import (
|
|||||||
_ "github.com/minio/minio-go/v7"
|
_ "github.com/minio/minio-go/v7"
|
||||||
cr "github.com/minio/minio-go/v7/pkg/credentials"
|
cr "github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @Summary minio上传文件(web api)
|
// @Summary minio上传文件(web api)
|
||||||
@ -176,6 +178,7 @@ func UploadUpdateApp(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||||
|
|
||||||
var yamlName string
|
var yamlName string
|
||||||
if req.Yaml == nil {
|
if req.Yaml == nil {
|
||||||
yamlName = ""
|
yamlName = ""
|
||||||
@ -218,6 +221,13 @@ func UploadUpdateApp(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func version2Int(version string) (int, error) {
|
||||||
|
versions := strings.Split(version, ".")
|
||||||
|
s := strings.Join(versions, "")
|
||||||
|
versionInt, err := strconv.Atoi(s)
|
||||||
|
return versionInt, err
|
||||||
|
}
|
||||||
|
|
||||||
func GetDownloadURL(c *gin.Context) {
|
func GetDownloadURL(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
req api.GetDownloadURLReq
|
req api.GetDownloadURLReq
|
||||||
@ -238,7 +248,13 @@ func GetDownloadURL(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), "app: ", app)
|
log.Debug(req.OperationID, utils.GetSelfFuncName(), "app: ", app)
|
||||||
if app != nil {
|
if app != nil {
|
||||||
if app.Version != req.Version && app.Version != "" {
|
appVersion, err := version2Int(app.Version)
|
||||||
|
reqVersion, err := version2Int(req.Version)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), "req version", req.Version, "app version", app.Version)
|
||||||
|
}
|
||||||
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "req version:", reqVersion, "app version:", appVersion)
|
||||||
|
if appVersion > reqVersion && app.Version != "" {
|
||||||
resp.Data.HasNewVersion = true
|
resp.Data.HasNewVersion = true
|
||||||
if app.ForceUpdate == true {
|
if app.ForceUpdate == true {
|
||||||
resp.Data.ForceUpdate = true
|
resp.Data.ForceUpdate = true
|
||||||
|
@ -2,11 +2,13 @@ package cronTask
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
const oldestList = 0
|
const oldestList = 0
|
||||||
@ -19,6 +21,7 @@ func ResetUserGroupMinSeq(operationID, groupID string, userIDList []string) erro
|
|||||||
log.NewError(operationID, utils.GetSelfFuncName(), groupID, "deleteMongoMsg failed")
|
log.NewError(operationID, utils.GetSelfFuncName(), groupID, "deleteMongoMsg failed")
|
||||||
return utils.Wrap(err, "")
|
return utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDList:", delMsgIDList, "minSeq", minSeq)
|
||||||
for _, userID := range userIDList {
|
for _, userID := range userIDList {
|
||||||
userMinSeq, err := db.DB.GetGroupUserMinSeq(groupID, userID)
|
userMinSeq, err := db.DB.GetGroupUserMinSeq(groupID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -43,17 +46,34 @@ func DeleteMongoMsgAndResetRedisSeq(operationID, userID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return utils.Wrap(err, "")
|
return utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDMap: ", userID, delMsgIDList)
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDMap: ", delMsgIDList, "minSeq", minSeq)
|
||||||
err = db.DB.SetUserMinSeq(userID, minSeq)
|
err = db.DB.SetUserMinSeq(userID, minSeq)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delMongoMsgs(operationID string, delMsgIDList *[][2]interface{}) error {
|
||||||
|
if len(*delMsgIDList) > 0 {
|
||||||
|
var IDList []string
|
||||||
|
for _, v := range *delMsgIDList {
|
||||||
|
IDList = append(IDList, v[0].(string))
|
||||||
|
}
|
||||||
|
err := db.DB.DelMongoMsgs(IDList)
|
||||||
|
if err != nil {
|
||||||
|
return utils.Wrap(err, "DelMongoMsgs failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// recursion
|
// recursion
|
||||||
func deleteMongoMsg(operationID string, ID string, index int64, delMsgIDList *[][2]interface{}) (uint32, error) {
|
func deleteMongoMsg(operationID string, ID string, index int64, delMsgIDList *[][2]interface{}) (uint32, error) {
|
||||||
// 从最旧的列表开始找
|
// 从最旧的列表开始找
|
||||||
msgs, err := db.DB.GetUserMsgListByIndex(ID, index)
|
msgs, err := db.DB.GetUserMsgListByIndex(ID, index)
|
||||||
if err != nil {
|
if err != nil || msgs.UID == "" {
|
||||||
return 0, utils.Wrap(err, "GetUserMsgListByIndex failed")
|
if err != nil {
|
||||||
|
log.NewError(operationID, utils.GetSelfFuncName(), "GetUserMsgListByIndex failed", err.Error(), index, ID)
|
||||||
|
}
|
||||||
|
return getDelMaxSeqByIDList(*delMsgIDList), delMongoMsgs(operationID, delMsgIDList)
|
||||||
}
|
}
|
||||||
if len(msgs.Msg) > db.GetSingleGocMsgNum() {
|
if len(msgs.Msg) > db.GetSingleGocMsgNum() {
|
||||||
log.NewWarn(operationID, utils.GetSelfFuncName(), "msgs too large", len(msgs.Msg), msgs.UID)
|
log.NewWarn(operationID, utils.GetSelfFuncName(), "msgs too large", len(msgs.Msg), msgs.UID)
|
||||||
@ -62,15 +82,8 @@ func deleteMongoMsg(operationID string, ID string, index int64, delMsgIDList *[]
|
|||||||
for i, msg := range msgs.Msg {
|
for i, msg := range msgs.Msg {
|
||||||
// 找到列表中不需要删除的消息了
|
// 找到列表中不需要删除的消息了
|
||||||
if utils.GetCurrentTimestampByMill() < msg.SendTime+int64(config.Config.Mongo.DBRetainChatRecords)*24*60*60*1000 {
|
if utils.GetCurrentTimestampByMill() < msg.SendTime+int64(config.Config.Mongo.DBRetainChatRecords)*24*60*60*1000 {
|
||||||
if len(*delMsgIDList) > 0 {
|
if err := delMongoMsgs(operationID, delMsgIDList); err != nil {
|
||||||
var IDList []string
|
return 0, err
|
||||||
for _, v := range *delMsgIDList {
|
|
||||||
IDList = append(IDList, v[0].(string))
|
|
||||||
}
|
|
||||||
err := db.DB.DelMongoMsgs(IDList)
|
|
||||||
if err != nil {
|
|
||||||
return 0, utils.Wrap(err, "DelMongoMsgs failed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
minSeq := getDelMaxSeqByIDList(*delMsgIDList)
|
minSeq := getDelMaxSeqByIDList(*delMsgIDList)
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
@ -84,19 +97,21 @@ func deleteMongoMsg(operationID string, ID string, index int64, delMsgIDList *[]
|
|||||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), msgs.UID, i)
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), msgs.UID, i)
|
||||||
return minSeq, nil
|
return minSeq, nil
|
||||||
}
|
}
|
||||||
minSeq = msgPb.Seq - 1
|
minSeq = msgPb.Seq
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return minSeq, nil
|
return minSeq, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msgPb := &server_api_params.MsgData{}
|
if len(msgs.Msg) > 0 {
|
||||||
err = proto.Unmarshal(msgs.Msg[len(msgs.Msg)-1].Msg, msgPb)
|
msgPb := &server_api_params.MsgData{}
|
||||||
if err != nil {
|
err = proto.Unmarshal(msgs.Msg[len(msgs.Msg)-1].Msg, msgPb)
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), len(msgs.Msg)-1, msgs.UID)
|
if err != nil {
|
||||||
return 0, utils.Wrap(err, "proto.Unmarshal failed")
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), len(msgs.Msg)-1, msgs.UID)
|
||||||
|
return 0, utils.Wrap(err, "proto.Unmarshal failed")
|
||||||
|
}
|
||||||
|
*delMsgIDList = append(*delMsgIDList, [2]interface{}{msgs.UID, msgPb.Seq})
|
||||||
}
|
}
|
||||||
*delMsgIDList = append(*delMsgIDList, [2]interface{}{msgs.UID, msgPb.Seq})
|
|
||||||
// 没有找到 代表需要全部删除掉 继续递归查找下一个比较旧的列表
|
// 没有找到 代表需要全部删除掉 继续递归查找下一个比较旧的列表
|
||||||
seq, err := deleteMongoMsg(operationID, utils.GetSelfFuncName(), index+1, delMsgIDList)
|
seq, err := deleteMongoMsg(operationID, utils.GetSelfFuncName(), index+1, delMsgIDList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -111,3 +126,29 @@ func getDelMaxSeqByIDList(delMsgIDList [][2]interface{}) uint32 {
|
|||||||
}
|
}
|
||||||
return delMsgIDList[len(delMsgIDList)-1][1].(uint32)
|
return delMsgIDList[len(delMsgIDList)-1][1].(uint32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkMaxSeqWithMongo(operationID, ID string, diffusionType int) error {
|
||||||
|
var maxSeq uint64
|
||||||
|
var err error
|
||||||
|
if diffusionType == constant.WriteDiffusion {
|
||||||
|
maxSeq, err = db.DB.GetUserMaxSeq(ID)
|
||||||
|
} else {
|
||||||
|
maxSeq, err = db.DB.GetGroupMaxSeq(ID)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return utils.Wrap(err, "GetUserMaxSeq failed")
|
||||||
|
}
|
||||||
|
msg, err := db.DB.GetNewestMsg(ID)
|
||||||
|
if err != nil {
|
||||||
|
return utils.Wrap(err, "GetNewestMsg failed")
|
||||||
|
}
|
||||||
|
msgPb := &server_api_params.MsgData{}
|
||||||
|
err = proto.Unmarshal(msg.Msg, msgPb)
|
||||||
|
if err != nil {
|
||||||
|
return utils.Wrap(err, "")
|
||||||
|
}
|
||||||
|
if math.Abs(float64(msgPb.Seq-uint32(maxSeq))) > 10 {
|
||||||
|
log.NewWarn(operationID, utils.GetSelfFuncName(), maxSeq, msgPb.Seq, "redis maxSeq is different with msg.Seq")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cronTask
|
package cronTask
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||||
@ -16,8 +17,10 @@ const cronTaskOperationID = "cronTaskOperationID-"
|
|||||||
func StartCronTask() {
|
func StartCronTask() {
|
||||||
log.NewInfo(utils.OperationIDGenerator(), "start cron task")
|
log.NewInfo(utils.OperationIDGenerator(), "start cron task")
|
||||||
c := cron.New()
|
c := cron.New()
|
||||||
_, err := c.AddFunc("30 3-6,20-23 * * *", func() {
|
fmt.Println("config", config.Config.Mongo.ChatRecordsClearTime)
|
||||||
|
_, err := c.AddFunc(config.Config.Mongo.ChatRecordsClearTime, func() {
|
||||||
operationID := getCronTaskOperationID()
|
operationID := getCronTaskOperationID()
|
||||||
|
log.NewInfo(operationID, "start", utils.GetSelfFuncName())
|
||||||
userIDList, err := im_mysql_model.SelectAllUserID()
|
userIDList, err := im_mysql_model.SelectAllUserID()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
||||||
@ -25,6 +28,9 @@ func StartCronTask() {
|
|||||||
if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil {
|
if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil {
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), userID)
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), userID)
|
||||||
}
|
}
|
||||||
|
if err := checkMaxSeqWithMongo(operationID, userID, constant.WriteDiffusion); err != nil {
|
||||||
|
log.NewError(operationID, utils.GetSelfFuncName(), userID, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||||
@ -42,7 +48,9 @@ func StartCronTask() {
|
|||||||
if err := ResetUserGroupMinSeq(operationID, groupID, userIDList); err != nil {
|
if err := ResetUserGroupMinSeq(operationID, groupID, userIDList); err != nil {
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID, userIDList)
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID, userIDList)
|
||||||
}
|
}
|
||||||
|
if err := checkMaxSeqWithMongo(operationID, groupID, constant.ReadDiffusion); err != nil {
|
||||||
|
log.NewError(operationID, utils.GetSelfFuncName(), groupID, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||||
@ -53,6 +61,7 @@ func StartCronTask() {
|
|||||||
fmt.Println("start cron failed", err.Error())
|
fmt.Println("start cron failed", err.Error())
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Start()
|
c.Start()
|
||||||
fmt.Println("start cron task success")
|
fmt.Println("start cron task success")
|
||||||
for {
|
for {
|
||||||
|
3
internal/cron_task/test/main.go
Normal file
3
internal/cron_task/test/main.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {}
|
@ -10,8 +10,9 @@ import (
|
|||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ParamsLogin struct {
|
type ParamsLogin struct {
|
||||||
@ -62,6 +63,11 @@ func Login(c *gin.Context) {
|
|||||||
openIMGetUserToken.Platform = params.Platform
|
openIMGetUserToken.Platform = params.Platform
|
||||||
openIMGetUserToken.Secret = config.Config.Secret
|
openIMGetUserToken.Secret = config.Config.Secret
|
||||||
openIMGetUserToken.UserID = userID
|
openIMGetUserToken.UserID = userID
|
||||||
|
loginIp := c.Request.Header.Get("X-Forward-For")
|
||||||
|
if loginIp == "" {
|
||||||
|
loginIp = c.ClientIP()
|
||||||
|
}
|
||||||
|
openIMGetUserToken.LoginIp = loginIp
|
||||||
openIMGetUserTokenResp := api.UserTokenResp{}
|
openIMGetUserTokenResp := api.UserTokenResp{}
|
||||||
bMsg, err := http2.Post(url, openIMGetUserToken, 2)
|
bMsg, err := http2.Post(url, openIMGetUserToken, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -72,7 +78,11 @@ func Login(c *gin.Context) {
|
|||||||
err = json.Unmarshal(bMsg, &openIMGetUserTokenResp)
|
err = json.Unmarshal(bMsg, &openIMGetUserTokenResp)
|
||||||
if err != nil || openIMGetUserTokenResp.ErrCode != 0 {
|
if err != nil || openIMGetUserTokenResp.ErrCode != 0 {
|
||||||
log.NewError(params.OperationID, "request get user token", account, "err", "")
|
log.NewError(params.OperationID, "request get user token", account, "err", "")
|
||||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.GetIMTokenErr, "errMsg": ""})
|
if openIMGetUserTokenResp.ErrCode == constant.LoginLimit {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.LoginLimit, "errMsg": "用户登录被限制"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.GetIMTokenErr, "errMsg": ""})
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMGetUserTokenResp.UserToken})
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMGetUserTokenResp.UserToken})
|
||||||
|
@ -10,11 +10,12 @@ import (
|
|||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ParamsSetPassword struct {
|
type ParamsSetPassword struct {
|
||||||
@ -81,6 +82,11 @@ func SetPassword(c *gin.Context) {
|
|||||||
openIMRegisterReq.Nickname = params.Nickname
|
openIMRegisterReq.Nickname = params.Nickname
|
||||||
openIMRegisterReq.Secret = config.Config.Secret
|
openIMRegisterReq.Secret = config.Config.Secret
|
||||||
openIMRegisterReq.FaceURL = params.FaceURL
|
openIMRegisterReq.FaceURL = params.FaceURL
|
||||||
|
createIp := c.Request.Header.Get("X-Forward-For")
|
||||||
|
if createIp == "" {
|
||||||
|
createIp = c.ClientIP()
|
||||||
|
}
|
||||||
|
openIMRegisterReq.CreateIp = createIp
|
||||||
openIMRegisterResp := api.UserRegisterResp{}
|
openIMRegisterResp := api.UserRegisterResp{}
|
||||||
log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "register req:", openIMRegisterReq)
|
log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "register req:", openIMRegisterReq)
|
||||||
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
|
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
|
||||||
@ -95,7 +101,11 @@ func SetPassword(c *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
|
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
|
if openIMRegisterResp.ErrCode == constant.RegisterLimit {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterLimit, "errMsg": "用户注册被限制"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info(params.OperationID, "begin store mysql", account, params.Password, "info", params.FaceURL, params.Nickname)
|
log.Info(params.OperationID, "begin store mysql", account, params.Password, "info", params.FaceURL, params.Nickname)
|
||||||
|
@ -83,6 +83,7 @@ type Alert struct {
|
|||||||
type Android struct {
|
type Android struct {
|
||||||
Ups struct {
|
Ups struct {
|
||||||
Notification Notification `json:"notification"`
|
Notification Notification `json:"notification"`
|
||||||
|
Options Options `json:"options"`
|
||||||
} `json:"ups"`
|
} `json:"ups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,6 +93,18 @@ type Notification struct {
|
|||||||
ClickType string `json:"click_type"`
|
ClickType string `json:"click_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
HW struct {
|
||||||
|
DefaultSound bool `json:"/message/android/notification/default_sound"`
|
||||||
|
ChannelID string `json:"/message/android/notification/channel_id"`
|
||||||
|
Sound string `json:"/message/android/notification/sound"`
|
||||||
|
Importance string `json:"/message/android/notification/importance"`
|
||||||
|
} `json:"HW"`
|
||||||
|
XM struct {
|
||||||
|
ChannelID string `json:"/extra.channel_id"`
|
||||||
|
} `json:""`
|
||||||
|
}
|
||||||
|
|
||||||
type PushResp struct {
|
type PushResp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +146,17 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, operationID stri
|
|||||||
Body: alert,
|
Body: alert,
|
||||||
ClickType: "startapp",
|
ClickType: "startapp",
|
||||||
}
|
}
|
||||||
|
pushReq.PushChannel.Android.Ups.Options = Options{
|
||||||
|
HW: struct {
|
||||||
|
DefaultSound bool `json:"/message/android/notification/default_sound"`
|
||||||
|
ChannelID string `json:"/message/android/notification/channel_id"`
|
||||||
|
Sound string `json:"/message/android/notification/sound"`
|
||||||
|
Importance string `json:"/message/android/notification/importance"`
|
||||||
|
}{ChannelID: "RingRing4", Sound: "/raw/ring001", Importance: "importance"},
|
||||||
|
XM: struct {
|
||||||
|
ChannelID string `json:"/extra.channel_id"`
|
||||||
|
}{ChannelID: "Default"},
|
||||||
|
}
|
||||||
pushResp := PushResp{}
|
pushResp := PushResp{}
|
||||||
err = g.request(PushURL, pushReq, token, &pushResp, operationID)
|
err = g.request(PushURL, pushReq, token, &pushResp, operationID)
|
||||||
switch err {
|
switch err {
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
|
||||||
@ -29,6 +30,13 @@ func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq)
|
|||||||
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
||||||
}
|
}
|
||||||
log.Debug(req.OperationID, "copy ", user, req.UserInfo)
|
log.Debug(req.OperationID, "copy ", user, req.UserInfo)
|
||||||
|
Limited, LimitError := imdb.IsLimitRegisterIp(req.UserInfo.CreateIp)
|
||||||
|
if LimitError != nil {
|
||||||
|
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: LimitError.Error()}}, nil
|
||||||
|
}
|
||||||
|
if Limited {
|
||||||
|
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.RegisterLimit, ErrMsg: "Register Limit"}}, nil
|
||||||
|
}
|
||||||
err := imdb.UserRegister(user)
|
err := imdb.UserRegister(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := req.OperationID + " imdb.UserRegister failed " + err.Error() + user.UserID
|
errMsg := req.OperationID + " imdb.UserRegister failed " + err.Error() + user.UserID
|
||||||
@ -42,20 +50,43 @@ func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq)
|
|||||||
|
|
||||||
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||||
_, err := imdb.GetUserByUserID(req.FromUserID)
|
user, err := imdb.GetUserByUserID(req.FromUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.FromUserID
|
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.FromUserID
|
||||||
log.NewError(req.OperationID, errMsg)
|
log.NewError(req.OperationID, errMsg)
|
||||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||||
}
|
}
|
||||||
|
var Limited bool
|
||||||
|
var LimitError error
|
||||||
|
if user.LoginLimit == 0 {
|
||||||
|
Limited, LimitError = imdb.IsLimitLoginIp(req.LoginIp)
|
||||||
|
} else if user.LoginLimit == 1 {
|
||||||
|
Limited, LimitError = imdb.IsLimitUserLoginIp(user.UserID, req.LoginIp)
|
||||||
|
} else if user.LoginLimit == 2 {
|
||||||
|
Limited, LimitError = imdb.UserIsBlock(user.UserID)
|
||||||
|
}
|
||||||
|
if LimitError != nil {
|
||||||
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: LimitError.Error()}}, nil
|
||||||
|
}
|
||||||
|
if Limited {
|
||||||
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.LoginLimit, ErrMsg: "用户被限制"}}, nil
|
||||||
|
}
|
||||||
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, int(req.Platform))
|
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, int(req.Platform))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := req.OperationID + " token_verify.CreateToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
|
errMsg := req.OperationID + " token_verify.CreateToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
|
||||||
log.NewError(req.OperationID, errMsg)
|
log.NewError(req.OperationID, errMsg)
|
||||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||||
}
|
}
|
||||||
|
//增加用户登录信息
|
||||||
|
user.LoginTimes = user.LoginTimes + 1
|
||||||
|
user.LastLoginIp = req.LoginIp
|
||||||
|
user.LastLoginTime = time.Now()
|
||||||
|
err = imdb.UpdateUserInfo(*user)
|
||||||
|
if err != nil {
|
||||||
|
errMsg := req.OperationID + " imdb.UpdateUserInfo failed " + err.Error() + req.FromUserID
|
||||||
|
log.NewError(req.OperationID, errMsg)
|
||||||
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||||
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime})
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime})
|
||||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime}, nil
|
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime}, nil
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func (rpc *rpcConversation) ModifyConversationField(c context.Context, req *pbCo
|
|||||||
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
if groupInfo.Status == constant.GroupStatusDismissed && !req.Conversation.IsNotInGroup {
|
if groupInfo.Status == constant.GroupStatusDismissed && !req.Conversation.IsNotInGroup && req.FieldType != constant.FieldUnread {
|
||||||
errMsg := "group status is dismissed"
|
errMsg := "group status is dismissed"
|
||||||
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}
|
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||||
"Open_IM/pkg/common/db/rocks_cache"
|
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||||
errors "Open_IM/pkg/common/http"
|
errors "Open_IM/pkg/common/http"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/common/token_verify"
|
"Open_IM/pkg/common/token_verify"
|
||||||
@ -540,11 +540,20 @@ func (s *userServer) GetUsersByName(ctx context.Context, req *pbUser.GetUsersByN
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resp.Users = append(resp.Users, &pbUser.User{
|
resp.Users = append(resp.Users, &pbUser.User{
|
||||||
ProfilePhoto: user.FaceURL,
|
ProfilePhoto: user.FaceURL,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
UserId: user.UserID,
|
UserId: user.UserID,
|
||||||
CreateTime: user.CreateTime.String(),
|
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
|
||||||
IsBlock: isBlock,
|
CreateIp: user.CreateIp,
|
||||||
|
IsBlock: isBlock,
|
||||||
|
Birth: user.Birth.Format("2006-01-02"),
|
||||||
|
PhoneNumber: user.PhoneNumber,
|
||||||
|
Email: user.Email,
|
||||||
|
LastLoginIp: user.LastLoginIp,
|
||||||
|
LastLoginTime: user.LastLoginTime.Format("2006-01-02 15:04:05"),
|
||||||
|
LoginTimes: user.LoginTimes,
|
||||||
|
Gender: user.Gender,
|
||||||
|
LoginLimit: user.LoginLimit,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
user := db.User{Nickname: req.UserName}
|
user := db.User{Nickname: req.UserName}
|
||||||
@ -576,11 +585,20 @@ func (s *userServer) GetUserById(ctx context.Context, req *pbUser.GetUserByIdReq
|
|||||||
return resp, errors.WrapError(constant.ErrDB)
|
return resp, errors.WrapError(constant.ErrDB)
|
||||||
}
|
}
|
||||||
resp.User = &pbUser.User{
|
resp.User = &pbUser.User{
|
||||||
ProfilePhoto: user.FaceURL,
|
ProfilePhoto: user.FaceURL,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
UserId: user.UserID,
|
UserId: user.UserID,
|
||||||
CreateTime: user.CreateTime.String(),
|
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
|
||||||
IsBlock: isBlock,
|
CreateIp: user.CreateIp,
|
||||||
|
IsBlock: isBlock,
|
||||||
|
Birth: user.Birth.Format("2006-01-02"),
|
||||||
|
PhoneNumber: user.PhoneNumber,
|
||||||
|
Email: user.Email,
|
||||||
|
LastLoginIp: user.LastLoginIp,
|
||||||
|
LastLoginTime: user.LastLoginTime.Format("2006-01-02 15:04:05"),
|
||||||
|
LoginTimes: user.LoginTimes,
|
||||||
|
Gender: user.Gender,
|
||||||
|
LoginLimit: user.LoginLimit,
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -598,11 +616,20 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
|||||||
isBlock, err := imdb.UserIsBlock(v.UserID)
|
isBlock, err := imdb.UserIsBlock(v.UserID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
user := &pbUser.User{
|
user := &pbUser.User{
|
||||||
ProfilePhoto: v.FaceURL,
|
ProfilePhoto: v.FaceURL,
|
||||||
UserId: v.UserID,
|
UserId: v.UserID,
|
||||||
CreateTime: v.CreateTime.String(),
|
CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"),
|
||||||
Nickname: v.Nickname,
|
CreateIp: v.CreateIp,
|
||||||
IsBlock: isBlock,
|
Nickname: v.Nickname,
|
||||||
|
Birth: v.Birth.Format("2006-01-02"),
|
||||||
|
PhoneNumber: v.PhoneNumber,
|
||||||
|
Email: v.Email,
|
||||||
|
IsBlock: isBlock,
|
||||||
|
LastLoginIp: v.LastLoginIp,
|
||||||
|
LastLoginTime: v.LastLoginTime.Format("2006-01-02 15:04:05"),
|
||||||
|
LoginTimes: v.LoginTimes,
|
||||||
|
Gender: v.Gender,
|
||||||
|
LoginLimit: v.LoginLimit,
|
||||||
}
|
}
|
||||||
resp.User = append(resp.User, user)
|
resp.User = append(resp.User, user)
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,6 +30,7 @@ type UserTokenReq struct {
|
|||||||
Secret string `json:"secret" binding:"required,max=32"`
|
Secret string `json:"secret" binding:"required,max=32"`
|
||||||
Platform int32 `json:"platform" binding:"required,min=1,max=8"`
|
Platform int32 `json:"platform" binding:"required,min=1,max=8"`
|
||||||
UserID string `json:"userID" binding:"required,min=1,max=64"`
|
UserID string `json:"userID" binding:"required,min=1,max=64"`
|
||||||
|
LoginIp string `json:"loginIp" binding:"required,max=15"`
|
||||||
OperationID string `json:"operationID" binding:"required"`
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
package base_info
|
package base_info
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ApiUserInfo struct {
|
type ApiUserInfo struct {
|
||||||
UserID string `json:"userID" binding:"required,min=1,max=64" swaggo:"true,用户ID,"`
|
UserID string `json:"userID" binding:"required,min=1,max=64" swaggo:"true,用户ID,"`
|
||||||
Nickname string `json:"nickname" binding:"omitempty,min=1,max=64" swaggo:"true,my id,19"`
|
Nickname string `json:"nickname" binding:"omitempty,min=1,max=64" swaggo:"true,my id,19"`
|
||||||
FaceURL string `json:"faceURL" binding:"omitempty,max=1024"`
|
FaceURL string `json:"faceURL" binding:"omitempty,max=1024"`
|
||||||
Gender int32 `json:"gender" binding:"omitempty,oneof=0 1 2"`
|
Gender int32 `json:"gender" binding:"omitempty,oneof=0 1 2"`
|
||||||
PhoneNumber string `json:"phoneNumber" binding:"omitempty,max=32"`
|
PhoneNumber string `json:"phoneNumber" binding:"omitempty,max=32"`
|
||||||
Birth uint32 `json:"birth" binding:"omitempty"`
|
Birth uint32 `json:"birth" binding:"omitempty"`
|
||||||
Email string `json:"email" binding:"omitempty,max=64"`
|
Email string `json:"email" binding:"omitempty,max=64"`
|
||||||
Ex string `json:"ex" binding:"omitempty,max=1024"`
|
CreateIp string `json:"createIp" binding:"omitempty,max=15"`
|
||||||
|
CreateTime int64 `json:"createTime"`
|
||||||
|
LastLoginIp string `json:"LastLoginIp" binding:"omitempty,max=15"`
|
||||||
|
LastLoginTime int64 `json:"lastLoginTime"`
|
||||||
|
LoginTimes int32 `json:"loginTimes" binding:"omitempty"`
|
||||||
|
LoginLimit int32 `json:"loginLimit" binding:"omitempty"`
|
||||||
|
Ex string `json:"ex" binding:"omitempty,max=1024"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//type Conversation struct {
|
//type Conversation struct {
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
package cms_api_struct
|
package cms_api_struct
|
||||||
|
|
||||||
type UserResponse struct {
|
type UserResponse struct {
|
||||||
ProfilePhoto string `json:"profile_photo"`
|
ProfilePhoto string `json:"profile_photo"`
|
||||||
Nickname string `json:"nick_name"`
|
Nickname string `json:"nick_name"`
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
CreateTime string `json:"create_time,omitempty"`
|
CreateTime string `json:"create_time,omitempty"`
|
||||||
IsBlock bool `json:"is_block"`
|
CreateIp string `json:"create_ip,omitempty"`
|
||||||
|
LastLoginTime string `json:"last_login_time,omitempty"`
|
||||||
|
LastLoginIp string `json:"last_login_ip,omitempty"`
|
||||||
|
LoginTimes int32 `json:"login_times"`
|
||||||
|
LoginLimit int32 `json:"login_limit"`
|
||||||
|
IsBlock bool `json:"is_block"`
|
||||||
|
PhoneNumber string `json:"phone_number"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Birth string `json:"birth"`
|
||||||
|
Gender int `json:"gender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetUserRequest struct {
|
type GetUserRequest struct {
|
||||||
|
@ -227,6 +227,11 @@ const (
|
|||||||
WorkMomentAtUserNotification = 2
|
WorkMomentAtUserNotification = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
WriteDiffusion = 0
|
||||||
|
ReadDiffusion = 1
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AtAllString = "AtAllTag"
|
AtAllString = "AtAllTag"
|
||||||
AtNormal = 0
|
AtNormal = 0
|
||||||
|
@ -67,6 +67,8 @@ const (
|
|||||||
CodeInvalidOrExpired = 10009
|
CodeInvalidOrExpired = 10009
|
||||||
RegisterFailed = 10010
|
RegisterFailed = 10010
|
||||||
ResetPasswordFailed = 10011
|
ResetPasswordFailed = 10011
|
||||||
|
RegisterLimit = 10012
|
||||||
|
LoginLimit = 10013
|
||||||
DatabaseError = 10002
|
DatabaseError = 10002
|
||||||
ServerError = 10004
|
ServerError = 10004
|
||||||
HttpError = 10005
|
HttpError = 10005
|
||||||
|
@ -153,8 +153,9 @@ type GroupRequest struct {
|
|||||||
//string Birth = 6;
|
//string Birth = 6;
|
||||||
//string Email = 7;
|
//string Email = 7;
|
||||||
//string Ex = 8;
|
//string Ex = 8;
|
||||||
//int64 CreateTime = 9;
|
//string CreateIp = 9;
|
||||||
//int32 AppMangerLevel = 10;
|
//int64 CreateTime = 10;
|
||||||
|
//int32 AppMangerLevel = 11;
|
||||||
//open_im_sdk.User == imdb.User
|
//open_im_sdk.User == imdb.User
|
||||||
type User struct {
|
type User struct {
|
||||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||||
@ -166,11 +167,30 @@ type User struct {
|
|||||||
Email string `gorm:"column:email;size:64"`
|
Email string `gorm:"column:email;size:64"`
|
||||||
Ex string `gorm:"column:ex;size:1024"`
|
Ex string `gorm:"column:ex;size:1024"`
|
||||||
CreateTime time.Time `gorm:"column:create_time"`
|
CreateTime time.Time `gorm:"column:create_time"`
|
||||||
|
CreateIp string `gorm:"column:create_ip;size:15"`
|
||||||
|
LastLoginTime time.Time `gorm:"column:last_login_time"`
|
||||||
|
LastLoginIp string `gorm:"column:last_login_ip;size:15"`
|
||||||
|
LoginTimes int32 `gorm:"column:login_times"`
|
||||||
|
LoginLimit int32 `gorm:"column:login_limit"`
|
||||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||||
status int32 `gorm:"column:status"`
|
status int32 `gorm:"column:status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IpLimit struct {
|
||||||
|
Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||||
|
LimitRegister int32 `gorm:"column:limit_register;size:1"`
|
||||||
|
LimitLogin int32 `gorm:"column:limit_login;size:1"`
|
||||||
|
CreateTime time.Time `gorm:"column:create_time"`
|
||||||
|
LimitTime time.Time `gorm:"column:limit_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserIpLimit struct {
|
||||||
|
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||||
|
Ip string `gorm:"column:ip;primary_key;size:15"`
|
||||||
|
CreateTime time.Time `gorm:"column:create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
//message BlackInfo{
|
//message BlackInfo{
|
||||||
//string OwnerUserID = 1;
|
//string OwnerUserID = 1;
|
||||||
//int64 CreateTime = 2;
|
//int64 CreateTime = 2;
|
||||||
|
@ -259,18 +259,22 @@ func (d *DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID st
|
|||||||
return seqMsg, nil
|
return seqMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (msg *UserChat, err error) {
|
func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, error) {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
||||||
regex := fmt.Sprintf("^%s", ID)
|
regex := fmt.Sprintf("^%s", ID)
|
||||||
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"$regex": regex})
|
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"$regex": regex}).SetSort(bson.M{"uid": 1})
|
||||||
msg = &UserChat{}
|
var msgs []UserChat
|
||||||
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
|
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = cursor.Decode(&msg)
|
err = cursor.Decode(&msgs)
|
||||||
return msg, err
|
if len(msgs) > 0 {
|
||||||
|
return &msgs[0], err
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("get msg list failed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataBases) DelMongoMsgs(IDList []string) error {
|
func (d *DataBases) DelMongoMsgs(IDList []string) error {
|
||||||
@ -298,6 +302,26 @@ func (d *DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DataBases) GetNewestMsg(ID string) (msg *MsgInfo, err error) {
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
||||||
|
regex := fmt.Sprintf("^%s", ID)
|
||||||
|
findOpts := options.Find().SetLimit(1).SetSort(bson.M{"$regex": regex}).SetSort(bson.M{"uid": -1})
|
||||||
|
var userChats []UserChat
|
||||||
|
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = cursor.Decode(&userChats)
|
||||||
|
if len(userChats) > 0 {
|
||||||
|
if len(userChats[0].Msg) > 0 {
|
||||||
|
return &userChats[0].Msg[len(userChats[0].Msg)], nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("len(userChats[0].Msg) < 0")
|
||||||
|
}
|
||||||
|
return nil, errors.New("len(userChats) < 0")
|
||||||
|
}
|
||||||
|
|
||||||
func (d *DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
|
func (d *DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
|
||||||
var hasSeqList []uint32
|
var hasSeqList []uint32
|
||||||
singleCount := 0
|
singleCount := 0
|
||||||
|
@ -2,14 +2,13 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"gorm.io/gorm/logger"
|
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mysqlDB struct {
|
type mysqlDB struct {
|
||||||
@ -79,7 +78,7 @@ func initMysqlDB() {
|
|||||||
&GroupMember{},
|
&GroupMember{},
|
||||||
&GroupRequest{},
|
&GroupRequest{},
|
||||||
&User{},
|
&User{},
|
||||||
&Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{}, &Department{})
|
&Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{}, &Department{}, &BlackList{}, &IpLimit{}, &UserIpLimit{})
|
||||||
db.Set("gorm:table_options", "CHARSET=utf8")
|
db.Set("gorm:table_options", "CHARSET=utf8")
|
||||||
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||||
|
|
||||||
@ -143,6 +142,18 @@ func initMysqlDB() {
|
|||||||
fmt.Println("CreateTable DepartmentMember")
|
fmt.Println("CreateTable DepartmentMember")
|
||||||
db.Migrator().CreateTable(&AppVersion{})
|
db.Migrator().CreateTable(&AppVersion{})
|
||||||
}
|
}
|
||||||
|
if !db.Migrator().HasTable(&BlackList{}) {
|
||||||
|
fmt.Println("CreateTable BlackList")
|
||||||
|
db.Migrator().CreateTable(&BlackList{})
|
||||||
|
}
|
||||||
|
if !db.Migrator().HasTable(&IpLimit{}) {
|
||||||
|
fmt.Println("CreateTable IpLimit")
|
||||||
|
db.Migrator().CreateTable(&IpLimit{})
|
||||||
|
}
|
||||||
|
if !db.Migrator().HasTable(&UserIpLimit{}) {
|
||||||
|
fmt.Println("CreateTable UserIpLimit")
|
||||||
|
db.Migrator().CreateTable(&UserIpLimit{})
|
||||||
|
}
|
||||||
DB.MysqlDB.db = db
|
DB.MysqlDB.db = db
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,9 @@ func UserRegister(user db.User) error {
|
|||||||
if user.Birth.Unix() < 0 {
|
if user.Birth.Unix() < 0 {
|
||||||
user.Birth = utils.UnixSecondToTime(0)
|
user.Birth = utils.UnixSecondToTime(0)
|
||||||
}
|
}
|
||||||
|
user.LastLoginTime = time.Now()
|
||||||
|
user.LoginTimes = 0
|
||||||
|
user.LastLoginIp = user.CreateIp
|
||||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error
|
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -130,7 +133,7 @@ func UserIsBlock(userId string) (bool, error) {
|
|||||||
var user db.BlackList
|
var user db.BlackList
|
||||||
rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
|
rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
|
||||||
if rows >= 1 {
|
if rows >= 1 {
|
||||||
return true, nil
|
return user.EndDisableTime.After(time.Now()), nil
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
@ -151,6 +154,9 @@ func BlockUser(userId, endDisableTime string) error {
|
|||||||
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&blockUser)
|
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&blockUser)
|
||||||
if blockUser.UserId != "" {
|
if blockUser.UserId != "" {
|
||||||
db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
|
db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
|
||||||
|
if user.LoginLimit != 2 {
|
||||||
|
db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
blockUser = db.BlackList{
|
blockUser = db.BlackList{
|
||||||
@ -159,11 +165,20 @@ func BlockUser(userId, endDisableTime string) error {
|
|||||||
EndDisableTime: end,
|
EndDisableTime: end,
|
||||||
}
|
}
|
||||||
result := db.DB.MysqlDB.DefaultGormDB().Create(&blockUser)
|
result := db.DB.MysqlDB.DefaultGormDB().Create(&blockUser)
|
||||||
|
if result.Error == nil {
|
||||||
|
if user.LoginLimit != 2 {
|
||||||
|
db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnBlockUser(userId string) error {
|
func UnBlockUser(userId string) error {
|
||||||
return db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userId).Delete(&db.BlackList{}).Error
|
err := db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userId).Delete(&db.BlackList{}).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userId).Update("login_limit", 0).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlockUserInfo struct {
|
type BlockUserInfo struct {
|
||||||
@ -238,3 +253,30 @@ func GetBlockUsersNumCount() (int32, error) {
|
|||||||
}
|
}
|
||||||
return int32(count), nil
|
return int32(count), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsLimitRegisterIp(RegisterIp string) (bool, error) {
|
||||||
|
//如果已经存在则限制
|
||||||
|
var count int64
|
||||||
|
if err := db.DB.MysqlDB.DefaultGormDB().Table("ip_limits").Where("ip=? and limit_register=? and limit_time>now()", RegisterIp, 1).Count(&count).Error; err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return count > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsLimitLoginIp(LoginIp string) (bool, error) {
|
||||||
|
//如果已经存在则限制
|
||||||
|
var count int64
|
||||||
|
if err := db.DB.MysqlDB.DefaultGormDB().Table("ip_limits").Where("ip=? and limit_login=? and limit_time>now()", LoginIp, 1).Count(&count).Error; err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return count > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsLimitUserLoginIp(userID string, LoginIp string) (bool, error) {
|
||||||
|
//如果已经存在则放行
|
||||||
|
var count int64
|
||||||
|
if err := db.DB.MysqlDB.DefaultGormDB().Table("user_ip_limits").Where("ip=? and user_id=?", LoginIp, userID).Count(&count).Error; err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return count == 0, nil
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,7 @@ message UserTokenReq {
|
|||||||
string FromUserID = 2;
|
string FromUserID = 2;
|
||||||
string OpUserID = 3;
|
string OpUserID = 3;
|
||||||
string OperationID = 4;
|
string OperationID = 4;
|
||||||
|
string LoginIp = 5;
|
||||||
}
|
}
|
||||||
message UserTokenResp {
|
message UserTokenResp {
|
||||||
CommonResp CommonResp = 1;
|
CommonResp CommonResp = 1;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -72,9 +72,14 @@ message UserInfo{
|
|||||||
uint32 birth = 6;
|
uint32 birth = 6;
|
||||||
string email = 7;
|
string email = 7;
|
||||||
string ex = 8;
|
string ex = 8;
|
||||||
uint32 createTime = 9;
|
string createIp = 9;
|
||||||
int32 appMangerLevel = 10;
|
uint32 createTime = 10;
|
||||||
int32 globalRecvMsgOpt = 11;
|
string LastLoginIp =11;
|
||||||
|
uint32 LastLoginTime = 12;
|
||||||
|
int32 LoginTimes = 13;
|
||||||
|
int32 LoginLimit = 14;
|
||||||
|
int32 appMangerLevel = 15;
|
||||||
|
int32 globalRecvMsgOpt = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FriendInfo{
|
message FriendInfo{
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -178,7 +178,16 @@ message User{
|
|||||||
string Nickname = 2;
|
string Nickname = 2;
|
||||||
string UserId = 3;
|
string UserId = 3;
|
||||||
string CreateTime = 4;
|
string CreateTime = 4;
|
||||||
bool IsBlock = 5;
|
string PhoneNumber = 5;
|
||||||
|
string Email = 6;
|
||||||
|
string Birth = 7;
|
||||||
|
string CreateIp = 8;
|
||||||
|
string LastLoginTime = 9;
|
||||||
|
string LastLoginIp = 10;
|
||||||
|
int32 LoginTimes = 11;
|
||||||
|
int32 Gender = 12;
|
||||||
|
int32 LoginLimit = 13;
|
||||||
|
bool IsBlock = 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetUserByIdResp{
|
message GetUserByIdResp{
|
||||||
|
@ -56,11 +56,11 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
#check=$(ps aux | grep -w ./${timer_task_name} | grep -v grep | wc -l)
|
#check=$(ps aux | grep -w ./${cron_task_name} | grep -v grep | wc -l)
|
||||||
#if [ $check -ge 1 ]; then
|
#if [ $check -ge 1 ]; then
|
||||||
# echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImMsgTimer"${COLOR_SUFFIX}
|
# echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is cron_task_name"${COLOR_SUFFIX}
|
||||||
#else
|
#else
|
||||||
# echo -e ${RED_PREFIX}"openImMsgTimer service does not start normally"${COLOR_SUFFIX}
|
# echo -e ${RED_PREFIX}"cron_task_name service does not start normally"${COLOR_SUFFIX}
|
||||||
# echo -e ${RED_PREFIX}"please check ../logs/openIM.log "${COLOR_SUFFIX}
|
# echo -e ${RED_PREFIX}"please check ../logs/openIM.log "${COLOR_SUFFIX}
|
||||||
# exit -1
|
# exit -1
|
||||||
#fi
|
#fi
|
||||||
|
@ -27,6 +27,10 @@ demo_server_name="open_im_demo"
|
|||||||
demo_server_binary_root="../bin/"
|
demo_server_binary_root="../bin/"
|
||||||
demo_server_source_root="../cmd/open_im_demo/"
|
demo_server_source_root="../cmd/open_im_demo/"
|
||||||
|
|
||||||
|
cron_task_name="open_im_cron_task"
|
||||||
|
cron_task_binary_root="../bin/"
|
||||||
|
cron_task_source_root="../cmd/open_im_cron_task/"
|
||||||
|
|
||||||
|
|
||||||
#Global configuration file default dir
|
#Global configuration file default dir
|
||||||
config_path="../config/config.yaml"
|
config_path="../config/config.yaml"
|
||||||
@ -48,6 +52,7 @@ service_source_root=(
|
|||||||
../cmd/rpc/open_im_organization/
|
../cmd/rpc/open_im_organization/
|
||||||
../cmd/rpc/open_im_conversation/
|
../cmd/rpc/open_im_conversation/
|
||||||
../cmd/rpc/open_im_cache/
|
../cmd/rpc/open_im_cache/
|
||||||
|
../cmd/open_im_cron_task
|
||||||
${msg_gateway_source_root}
|
${msg_gateway_source_root}
|
||||||
${msg_transfer_source_root}
|
${msg_transfer_source_root}
|
||||||
${msg_source_root}
|
${msg_source_root}
|
||||||
@ -72,6 +77,7 @@ service_names=(
|
|||||||
open_im_organization
|
open_im_organization
|
||||||
open_im_conversation
|
open_im_conversation
|
||||||
open_im_cache
|
open_im_cache
|
||||||
|
open_im_cron_task
|
||||||
${msg_gateway_name}
|
${msg_gateway_name}
|
||||||
${msg_transfer_name}
|
${msg_transfer_name}
|
||||||
${msg_name}
|
${msg_name}
|
||||||
|
@ -10,6 +10,7 @@ need_to_start_server_shell=(
|
|||||||
sdk_svr_start.sh
|
sdk_svr_start.sh
|
||||||
msg_gateway_start.sh
|
msg_gateway_start.sh
|
||||||
demo_svr_start.sh
|
demo_svr_start.sh
|
||||||
|
# start_cron.sh
|
||||||
)
|
)
|
||||||
time=`date +"%Y-%m-%d %H:%M:%S"`
|
time=`date +"%Y-%m-%d %H:%M:%S"`
|
||||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||||
|
36
script/start_cron.sh
Normal file
36
script/start_cron.sh
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#Include shell font styles and some basic information
|
||||||
|
source ./style_info.cfg
|
||||||
|
source ./path_info.cfg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#Check if the service exists
|
||||||
|
#If it is exists,kill this process
|
||||||
|
check=`ps aux | grep -w ./${cron_task_name} | grep -v grep| wc -l`
|
||||||
|
if [ $check -ge 1 ]
|
||||||
|
then
|
||||||
|
oldPid=`ps aux | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'`
|
||||||
|
kill -9 $oldPid
|
||||||
|
fi
|
||||||
|
#Waiting port recycling
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
cd ${cron_task_binary_root}
|
||||||
|
#for ((i = 0; i < ${cron_task_service_num}; i++)); do
|
||||||
|
nohup ./${cron_task_name} >>../logs/openIM.log 2>&1 &
|
||||||
|
#done
|
||||||
|
|
||||||
|
#Check launched service process
|
||||||
|
check=`ps aux | grep -w ./${cron_task_name} | grep -v grep| wc -l`
|
||||||
|
if [ $check -ge 1 ]
|
||||||
|
then
|
||||||
|
newPid=`ps aux | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'`
|
||||||
|
allPorts=""
|
||||||
|
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX}
|
||||||
|
echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${YELLOW_PREFIX}${cron_task_name}${COLOR_SUFFIX}
|
||||||
|
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${newPid}${COLOR_SUFFIX}
|
||||||
|
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX}
|
||||||
|
else
|
||||||
|
echo -e ${YELLOW_PREFIX}${cron_task_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR, PLEASE CHECK openIM.log"${COLOR_SUFFIX}
|
||||||
|
fi
|
Loading…
x
Reference in New Issue
Block a user