Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access_token 过期之后没有重新获取 #37

Open
mangojuju opened this issue Jan 10, 2018 · 2 comments
Open

access_token 过期之后没有重新获取 #37

mangojuju opened this issue Jan 10, 2018 · 2 comments

Comments

@mangojuju
Copy link

微信企业号的某个agent在access_token 过期之后,就没调用setToken方法。 access_token 是存在redis 里的, 设置的两小时过期。
下面是错误log。

  • log
[2018-01-10 10:55:23]10.0.1.94
content: [2018-01-10 10:55:23.577] [INFO] app - begin e93f55ba-9a6c-4738-a668-8bc7a475534d POST /message/send ::ffff:10.0.1.93 
body: {"to":{"touser":"3"},"agentid":"agentid","message":{"msgtype":"text","text":{"content":"xxx"},"safe":"0"}}

[2018-01-10 10:55:23]10.0.1.94content: [2018-01-10 10:55:23.580] [INFO] app - get access token by redis: token = null

|[2018-01-10 10:55:23]10.0.1.94content: [2018-01-10 10:55:23.796] [ERROR] app - wechatAPI response error: method=send, error=invalid credential, hint: [1515552923_6_1c32f77d5bb48e4e928ca8e9c257f188], more info at https://open.work.weixin.qq.com/devtool/query?e=40001 code=40001
[2018-01-10 10:55:23]10.0.1.94content: [2018-01-10 10:55:23.797] [INFO] app - end e93f55ba-9a6c-4738-a668-8bc7a475534d POST /message/send - 500 - 220.157 ms
  • 代码
class WechatApi{
  constructor({corpId, secret, agentid}){
    this.api = new API(corpId, secret, agentid,
      (cb) => this._getToken(agentid).then( token=> cb(null, token)).catch( err => cb(err, null) ),
      (token, cb) => this._setToken(agentid, token).then( token=> cb && cb(null, token)))
  }

  _getToken(agentid) {
    // 取redis里token
    return redis.client('get', accessTokenPrefix+agentid)
      .then( token=>{
        logger.info(` get access token by redis: token =`, token)
        return JSON.parse(token)
      })
  }

  _setToken(agentid, token) {
    logger.info(` set access token: token = `, token)
    // 经过expire时间后过期
    redis.client('set', accessTokenPrefix+agentid, JSON.stringify(token), 'EX', expire)
    return Promise.resolve(token)
  }
}
@superlbr
Copy link

@JacksonTian 是否有继续维护的计划?

@JacksonTian
Copy link
Member

我感觉是你的实现问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants