From cbe3abeab05c530e36c54a5493a4f626b0bbf6ee Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 8 Apr 2022 16:15:22 +0800 Subject: [PATCH] getui --- config/config.yaml | 6 ++++-- internal/push/getui/push.go | 15 +++++++++++---- internal/push/logic/push_to_client.go | 1 + pkg/common/config/config.go | 10 +++++----- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 003d6f969..890a4c094 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -183,10 +183,12 @@ push: enable: false getui: #个推推送,暂未测试 暂不要使用 pushUrl: "https://restapi.getui.com/v2/$appId" - sign: "" + masterSecret: "" appKey: "" - enable: true intent: "" + enable: true + + manager: #app管理员userID和对应的secret 建议修改。 用于管理后台登录,也可以用户管理后台对应的api diff --git a/internal/push/getui/push.go b/internal/push/getui/push.go index f834337c8..5298441f8 100644 --- a/internal/push/getui/push.go +++ b/internal/push/getui/push.go @@ -6,6 +6,8 @@ import ( "Open_IM/pkg/common/log" "Open_IM/pkg/utils" "bytes" + "crypto/sha512" + "encoding/hex" "encoding/json" "io/ioutil" "net/http" @@ -71,7 +73,7 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken", err.Error()) } if token == "" || err != nil { - token, expireTime, err := g.Auth(config.Config.Push.Getui.AppKey, config.Config.Push.Getui.Sign, operationID, time.Now().Unix()) + token, expireTime, err := g.Auth(+operationID, time.Now().Unix()) if err != nil { return "", utils.Wrap(err, "Auth failed") } @@ -105,12 +107,17 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat return string(respBytes), err } -func (g *Getui) Auth(appKey, sign, operationID string, timeStamp int64) (token string, expireTime int64, err error) { - log.NewInfo(operationID, utils.GetSelfFuncName(), appKey, sign, timeStamp) +func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireTime int64, err error) { + log.NewInfo(operationID, utils.GetSelfFuncName(), timeStamp) + h := sha512.New() + h.Write([]byte(config.Config.Push.Getui.AppKey + strconv.Itoa(int(timeStamp)) + config.Config.Push.Getui.MasterSecret)) + sum := h.Sum(nil) + sign := hex.EncodeToString(sum) + log.NewInfo(operationID, utils.GetSelfFuncName(), "sha256 result", sign) reqAuth := AuthReq{ Sign: sign, Timestamp: strconv.Itoa(int(timeStamp)), - Appkey: appKey, + Appkey: config.Config.Push.Getui.AppKey, } respAuth := AuthResp{} err = g.request(reqAuth, "", &respAuth, operationID) diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index e527448ce..c6e512ccb 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -103,6 +103,7 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) { } var offlinePusher pusher.OfflinePusher if config.Config.Push.Getui.Enable { + log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui) offlinePusher = getui.GetuiClient } if config.Config.Push.Jpns.Enable { diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 5e8eb1e21..21af4ced0 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -162,11 +162,11 @@ type config struct { Enable bool `yaml:"enable"` } Getui struct { - PushUrl string `yaml:"pushUrl"` - Sign string `yaml:"sign"` - AppKey string `yaml:"appkey"` - Enable bool `yaml:"enable"` - Intent string `yaml:"intent"` + PushUrl string `yaml:"pushUrl"` + AppKey string `yaml:"appkey"` + Enable bool `yaml:"enable"` + Intent string `yaml:"intent"` + MasterSecret string `yaml:"masterSecret"` } } Manager struct {