mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 02:58:26 +08:00
Merge remote-tracking branch 'origin/tuoyun' into tuoyun
This commit is contained in:
commit
1d2d2b1c9c
@ -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…
x
Reference in New Issue
Block a user