Giter Club home page Giter Club logo

Comments (3)

shengbeiniao avatar shengbeiniao commented on June 22, 2024
  • var api = new API('appid', 'secret', function (callback) {
    • // 传入一个获取全局token的方法
    • fs.readFile('access_token.txt', 'utf8', function (err, txt) {
    • // if (err) {return callback(err);}
      if (err) {return callback(null,null);}
    • callback(null, JSON.parse(txt));
      
    • });
    • }, function (token, callback) {
    • // 请将token存储到全局,跨进程、跨机器级别的全局,比如写到数据库、redis等
    • // 这样才能在cluster模式及多机情况下使用,以下为写入到文件的示例
    • fs.writeFile('access_token.txt', JSON.stringify(token), callback);
    • });

from wechat-api.

JacksonTian avatar JacksonTian commented on June 22, 2024

这个地方有问题吗? 没有token就需要刷新

from wechat-api.

flight9 avatar flight9 commented on June 22, 2024

的确如果按文档写:
if (err) {return callback(err);}
就不会去调用
function (token, callback) {...}
所以永远都不会去缓存这个 token.

改为 if (err) {return callback(null,null);} 就可以,虽然还没读懂,谢谢 @shengbeiniao

from wechat-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.