RefreshYilianyunToken
This commit is contained in:
@@ -43,7 +43,6 @@ type EventInfo struct {
|
||||
|
||||
type tRegisterInfo struct {
|
||||
notifyChan chan *EventInfo
|
||||
eventCategory string
|
||||
eventTypeList []string
|
||||
criteria interface{}
|
||||
}
|
||||
@@ -177,8 +176,7 @@ func (e *EventHub) registerConsumer(eventCategory string, eventTypeList []string
|
||||
realEventTypeList[index] = composeEventType(eventCategory, eventType)
|
||||
}
|
||||
info := &tRegisterInfo{
|
||||
eventCategory: eventCategory,
|
||||
eventTypeList: eventTypeList,
|
||||
eventTypeList: realEventTypeList,
|
||||
notifyChan: make(chan *EventInfo, 1),
|
||||
criteria: criteria,
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ import (
|
||||
const (
|
||||
EventCategory = "sys"
|
||||
|
||||
EventTypeWXToken = "wxtoken"
|
||||
EventTypeWXToken = "wxtoken"
|
||||
EventTypeYLYToken = "ylytoken"
|
||||
)
|
||||
|
||||
type Hub struct {
|
||||
@@ -23,7 +24,7 @@ type Hub struct {
|
||||
type Criteria struct {
|
||||
}
|
||||
|
||||
type WXTokenInfo struct {
|
||||
type TokenInfo struct {
|
||||
IsNew bool `json:"isNew"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
@@ -55,22 +56,43 @@ func (h *Hub) OnNewWXToken(token string) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Hub) GetWXToken(oldToken string, waitTime time.Duration) (tokenInfo *WXTokenInfo) {
|
||||
token := api.WeixinAPI.CBGetToken()
|
||||
func (h *Hub) OnNewYLYToken(token string) {
|
||||
h.eventHub.PostNewEvent(EventCategory, &eventhub.EventInfo{
|
||||
Type: EventTypeYLYToken,
|
||||
Data: token,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Hub) GetToken(tokenType, oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) {
|
||||
var token string
|
||||
switch tokenType {
|
||||
case EventTypeWXToken:
|
||||
token = api.WeixinAPI.CBGetToken()
|
||||
case EventTypeYLYToken:
|
||||
token = api.YilianyunAPI.GetToken()
|
||||
}
|
||||
if token != oldToken {
|
||||
tokenInfo = &WXTokenInfo{
|
||||
tokenInfo = &TokenInfo{
|
||||
IsNew: false,
|
||||
Token: token,
|
||||
}
|
||||
} else {
|
||||
eventInfo, err := h.eventHub.GetEvent(EventCategory, []string{EventTypeWXToken}, nil, waitTime)
|
||||
eventInfo, err := h.eventHub.GetEvent(EventCategory, []string{tokenType}, nil, waitTime)
|
||||
if err == nil && eventInfo != nil {
|
||||
tokenInfo = &WXTokenInfo{
|
||||
tokenInfo = &TokenInfo{
|
||||
IsNew: true,
|
||||
Token: eventInfo.Data.(string),
|
||||
}
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("GetWXToken tokenInfo:%s", utils.Format4Output(tokenInfo, true))
|
||||
globals.SugarLogger.Debugf("GetToken tokenInfo:%s", utils.Format4Output(tokenInfo, true))
|
||||
return tokenInfo
|
||||
}
|
||||
|
||||
func (h *Hub) GetWXToken(oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) {
|
||||
return h.GetToken(EventTypeWXToken, oldToken, waitTime)
|
||||
}
|
||||
|
||||
func (h *Hub) GetYLYToken(oldToken string, waitTime time.Duration) (tokenInfo *TokenInfo) {
|
||||
return h.GetToken(EventTypeYLYToken, oldToken, waitTime)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user