Comments (4)
方式二需要使用者手动维护 access_token,每次 get 时判断 access_token 的 TTL,若过期则重新向微信请求获取并更新内存及缓存(如果有)中的值。而方式一则不需要
from wechat-python-sdk.
实例化完成后(首次实例化两个参数均使用 None),你需要在该实例有效期内的任意时刻调用 .get_access_token() 方法获得自动维护过的新的 access_token 和 access_token_expires_at 值,然后将他们用你自己的方式(磁盘文件/数据库/缓存)进行保存,方便下次实例化的时候传入。
对方式1有几个问题不理解
- 我需要自行去获取access_token和access_token_expires_at的值吗?
- 第一次调用需要怎么调用?
- 方式1会自动维护access_token吗? 还是需要我手动调用expires过期时间 ?
from wechat-python-sdk.
看了看他的代码,才明白:
- @shijn 第二种方法,不需要维护过期时间,看下
WechatConf
类中的access_token
属性方法,它会判断过期时间的,你只需要完成存储的事情。 - 我看到
WechatConf
类中的get_access_token
方法,有一句注释仅为兼容 v0.6.0 以前版本使用, 自行维护 access_token 请使用 access_token_setfunc 和 access_token_getfunc 进行操作。豁然开朗,第二种设计明显比第一种高明,而第一种是向下兼容用的。 @doraemonext 如果只是兼容用的,建议在文档里特意说明下。
from wechat-python-sdk.
@evilxyz 建议用方式2,效果一样,更容易理解,作者代码中说方式1只是为了保持向下兼容。
from wechat-python-sdk.
Related Issues (20)
- crypto in base.py case insensitive导致ImportError: cannot import name BaseCrypto HOT 1
- lib/crypto/__init__.py import后未使用,可清空该文件 HOT 1
- 在SAE上部署时出现了编码问题,Python版本3.5.1 HOT 1
- Python 3下加密模式有些Bug HOT 3
- sae下,调用wechat-sdk报错:ImportError: cannot import name _AES HOT 3
- sccess_token维护
- 关于线程安全 HOT 2
- 文档网址无法访问 HOT 2
- 微信支付
- 看了issue,企业号这个是怎么用来着,没看到文档有说呀 HOT 1
- 与WeRoBot一同使用
- 上传素材 upload_media接口 media data missing hint HOT 1
- 兄弟,你的网站挂了... HOT 2
- SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",)
- windows 10 64bit pychrm install issue
- certificate verify failed
- wechat_context' doesn't exist
- wechat-python-sdk
- 文档地址进不去了 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wechat-python-sdk.