mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
getui
This commit is contained in:
parent
4d01aa3006
commit
9e4a2168c0
@ -7,6 +7,8 @@ import (
|
||||
"Open_IM/pkg/utils"
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
|
||||
//"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@ -18,6 +20,8 @@ import (
|
||||
|
||||
var (
|
||||
GetuiClient *Getui
|
||||
|
||||
TokenExpireError = errors.New("token expire")
|
||||
)
|
||||
|
||||
const (
|
||||
@ -68,7 +72,6 @@ type Notification struct {
|
||||
}
|
||||
|
||||
type PushResp struct {
|
||||
GetuiCommonResp
|
||||
}
|
||||
|
||||
func newGetuiClient() *Getui {
|
||||
@ -101,13 +104,16 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operat
|
||||
}
|
||||
pushResp := PushResp{}
|
||||
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 {
|
||||
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), 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 {
|
||||
return err
|
||||
}
|
||||
if commonResp.Code == 10001 {
|
||||
return TokenExpireError
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user