|
|
|
@ -68,6 +68,7 @@ type Notification struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PushResp struct {
|
|
|
|
|
GetuiCommonResp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newGetuiClient() *Getui {
|
|
|
|
@ -81,14 +82,10 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat
|
|
|
|
|
log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken failed", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if token == "" || err != nil {
|
|
|
|
|
token, expireTime, err := g.Auth(operationID, time.Now().UnixNano()/1e6)
|
|
|
|
|
token, err = g.getTokenAndSave2Redis(operationID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", utils.Wrap(err, "Auth failed")
|
|
|
|
|
}
|
|
|
|
|
log.NewDebug(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err)
|
|
|
|
|
err = db.DB.SetGetuiToken(token, 60*60*23)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", utils.Wrap(err, "Auth failed")
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), "getTokenAndSave2Redis failed", err.Error())
|
|
|
|
|
return "", utils.Wrap(err, "")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pushReq := PushReq{
|
|
|
|
@ -107,8 +104,12 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", utils.Wrap(err, "push failed")
|
|
|
|
|
}
|
|
|
|
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "resp: ", pushResp)
|
|
|
|
|
if pushResp.Code == 10001 {
|
|
|
|
|
_, _ = g.getTokenAndSave2Redis(operationID)
|
|
|
|
|
}
|
|
|
|
|
respBytes, err := json.Marshal(pushResp)
|
|
|
|
|
return string(respBytes), err
|
|
|
|
|
return string(respBytes), utils.Wrap(err, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireTime int64, err error) {
|
|
|
|
@ -124,7 +125,6 @@ func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireT
|
|
|
|
|
Appkey: config.Config.Push.Getui.AppKey,
|
|
|
|
|
}
|
|
|
|
|
respAuth := AuthResp{}
|
|
|
|
|
|
|
|
|
|
err = g.request(AuthURL, reqAuth, "", &respAuth, operationID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", 0, err
|
|
|
|
@ -166,3 +166,16 @@ func (g *Getui) request(url string, content interface{}, token string, returnStr
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *Getui) getTokenAndSave2Redis(operationID string) (token string, err error) {
|
|
|
|
|
token, expireTime, err := g.Auth(operationID, time.Now().UnixNano()/1e6)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", utils.Wrap(err, "Auth failed")
|
|
|
|
|
}
|
|
|
|
|
log.NewDebug(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err)
|
|
|
|
|
err = db.DB.SetGetuiToken(token, 60*60*23)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", utils.Wrap(err, "Auth failed")
|
|
|
|
|
}
|
|
|
|
|
return token, nil
|
|
|
|
|
}
|
|
|
|
|