Code Monkey home page Code Monkey logo

Comments (4)

jiananshi avatar jiananshi commented on August 17, 2024

方式二需要使用者手动维护 access_token,每次 get 时判断 access_token 的 TTL,若过期则重新向微信请求获取并更新内存及缓存(如果有)中的值。而方式一则不需要

from wechat-python-sdk.

evilxyz avatar evilxyz commented on August 17, 2024

实例化完成后(首次实例化两个参数均使用 None),你需要在该实例有效期内的任意时刻调用 .get_access_token() 方法获得自动维护过的新的 access_token 和 access_token_expires_at 值,然后将他们用你自己的方式(磁盘文件/数据库/缓存)进行保存,方便下次实例化的时候传入。

对方式1有几个问题不理解

  1. 我需要自行去获取access_token和access_token_expires_at的值吗?
  2. 第一次调用需要怎么调用?
  3. 方式1会自动维护access_token吗? 还是需要我手动调用expires过期时间 ?

from wechat-python-sdk.

kekekedeng avatar kekekedeng commented on August 17, 2024

看了看他的代码,才明白:

  • @shijn 第二种方法,不需要维护过期时间,看下WechatConf类中的access_token属性方法,它会判断过期时间的,你只需要完成存储的事情。
  • 我看到WechatConf类中的get_access_token方法,有一句注释仅为兼容 v0.6.0 以前版本使用, 自行维护 access_token 请使用 access_token_setfunc 和 access_token_getfunc 进行操作。豁然开朗,第二种设计明显比第一种高明,而第一种是向下兼容用的。 @doraemonext 如果只是兼容用的,建议在文档里特意说明下。

from wechat-python-sdk.

kekekedeng avatar kekekedeng commented on August 17, 2024

@evilxyz 建议用方式2,效果一样,更容易理解,作者代码中说方式1只是为了保持向下兼容。

from wechat-python-sdk.

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.