Coder Social home page Coder Social logo

Comments (5)

sbzhu avatar sbzhu commented on June 3, 2024 1

@hi500 @xiaoyouxi01
是以类里的一个变量存的
比如api/src/CorpAPI.class.php 里的$accessToken变量
在类的生命周期里,这个accessToken都是存在的, 当且仅当发现token过期,就自动刷新 token。
刷新机制在 api/src/API.class.php
所以,使用时,只需要全局实例化一个CorpAPI类,不要析构它,就可一直用它调函数,不用关心 token。

$api = new CorpAPI(corpid, corpsecret);
$api->dosomething()
$api->dosomething()
$api->dosomething()
....

from weworkapi_php.

walkonthemarz avatar walkonthemarz commented on June 3, 2024 1

@sbzhu 那你的这个accessToken缓存也仅仅只在当前请求中有效,如果一个新的请求过来的话,你还是重新获取了一遍token,并没有实现多个请求之间共享一个token

from weworkapi_php.

xiaoyouxi01 avatar xiaoyouxi01 commented on June 3, 2024

我也挺想知道这个的。。

官网文档中下载的示例代码里,倒是有缓存的,是存在本地一个文件中。

GitHub上的代码,我也看不出来缓存。。。

from weworkapi_php.

walkonthemarz avatar walkonthemarz commented on June 3, 2024

而且看你的类里面把token设成了private,我都没法把token缓存到redis,想到的一个办法也许可以把整个类serialize以后存到redis,或者你能把token设成public或添加一个set方法 @sbzhu

from weworkapi_php.

sbzhu avatar sbzhu commented on June 3, 2024

@walkonthemarz 只要保证全局只实例化一个这个类,即实现了共享token,当然,你拿到token后,用redis或者文件来缓存,也是可以的。

from weworkapi_php.

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.