This commit is contained in:
wangchuxiao 2022-04-08 16:15:22 +08:00
parent 3d5e3ce6cf
commit cbe3abeab0
4 changed files with 21 additions and 11 deletions

View File

@ -183,10 +183,12 @@ push:
enable: false enable: false
getui: #个推推送,暂未测试 暂不要使用 getui: #个推推送,暂未测试 暂不要使用
pushUrl: "https://restapi.getui.com/v2/$appId" pushUrl: "https://restapi.getui.com/v2/$appId"
sign: "" masterSecret: ""
appKey: "" appKey: ""
enable: true
intent: "" intent: ""
enable: true
manager: manager:
#app管理员userID和对应的secret 建议修改。 用于管理后台登录也可以用户管理后台对应的api #app管理员userID和对应的secret 建议修改。 用于管理后台登录也可以用户管理后台对应的api

View File

@ -6,6 +6,8 @@ import (
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"bytes" "bytes"
"crypto/sha512"
"encoding/hex"
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -71,7 +73,7 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat
log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken", err.Error()) log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken", err.Error())
} }
if token == "" || err != nil { 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 { if err != nil {
return "", utils.Wrap(err, "Auth failed") return "", utils.Wrap(err, "Auth failed")
} }
@ -105,12 +107,17 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat
return string(respBytes), err return string(respBytes), err
} }
func (g *Getui) Auth(appKey, sign, operationID string, timeStamp int64) (token string, expireTime int64, err error) { func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireTime int64, err error) {
log.NewInfo(operationID, utils.GetSelfFuncName(), appKey, sign, timeStamp) 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{ reqAuth := AuthReq{
Sign: sign, Sign: sign,
Timestamp: strconv.Itoa(int(timeStamp)), Timestamp: strconv.Itoa(int(timeStamp)),
Appkey: appKey, Appkey: config.Config.Push.Getui.AppKey,
} }
respAuth := AuthResp{} respAuth := AuthResp{}
err = g.request(reqAuth, "", &respAuth, operationID) err = g.request(reqAuth, "", &respAuth, operationID)

View File

@ -103,6 +103,7 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
} }
var offlinePusher pusher.OfflinePusher var offlinePusher pusher.OfflinePusher
if config.Config.Push.Getui.Enable { if config.Config.Push.Getui.Enable {
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui)
offlinePusher = getui.GetuiClient offlinePusher = getui.GetuiClient
} }
if config.Config.Push.Jpns.Enable { if config.Config.Push.Jpns.Enable {

View File

@ -163,10 +163,10 @@ type config struct {
} }
Getui struct { Getui struct {
PushUrl string `yaml:"pushUrl"` PushUrl string `yaml:"pushUrl"`
Sign string `yaml:"sign"`
AppKey string `yaml:"appkey"` AppKey string `yaml:"appkey"`
Enable bool `yaml:"enable"` Enable bool `yaml:"enable"`
Intent string `yaml:"intent"` Intent string `yaml:"intent"`
MasterSecret string `yaml:"masterSecret"`
} }
} }
Manager struct { Manager struct {