pull/213/head
wangchuxiao 3 years ago
parent 4d01aa3006
commit 9e4a2168c0

@ -7,6 +7,8 @@ import (
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"bytes" "bytes"
"crypto/sha256" "crypto/sha256"
"errors"
//"crypto/sha512" //"crypto/sha512"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
@ -18,6 +20,8 @@ import (
var ( var (
GetuiClient *Getui GetuiClient *Getui
TokenExpireError = errors.New("token expire")
) )
const ( const (
@ -68,7 +72,6 @@ type Notification struct {
} }
type PushResp struct { type PushResp struct {
GetuiCommonResp
} }
func newGetuiClient() *Getui { func newGetuiClient() *Getui {
@ -101,13 +104,16 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat
} }
pushResp := PushResp{} pushResp := PushResp{}
err = g.request(PushURL, pushReq, token, &pushResp, operationID) err = g.request(PushURL, pushReq, token, &pushResp, operationID)
switch err {
case TokenExpireError:
_, err = g.getTokenAndSave2Redis(operationID)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "getTokenAndSave2Redis failed, ", err.Error())
}
}
if err != nil { if err != nil {
return "", utils.Wrap(err, "push failed") 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) respBytes, err := json.Marshal(pushResp)
return string(respBytes), utils.Wrap(err, "") return string(respBytes), utils.Wrap(err, "")
} }
@ -164,6 +170,9 @@ func (g *Getui) request(url string, content interface{}, token string, returnStr
if err := json.Unmarshal(result, &commonResp); err != nil { if err := json.Unmarshal(result, &commonResp); err != nil {
return err return err
} }
if commonResp.Code == 10001 {
return TokenExpireError
}
return nil return nil
} }

Loading…
Cancel
Save