How to save access_token For A Long Time During php WeChat Development

Source: Internet
Author: User
{Code ...}

  

Reply content:

  

Scheduled tasks and timed refresh

You need https://github.com/dodgepudding/wechat-php-sdk

Https://github.com/thenbsp/wechat/blob/master/src/AccessToken.php

Shake your teeth and use Redis to set an expiration time
This is what we plan to do in subsequent development.

Access_token can be saved for a long time but only valid for 7200 seconds.

Save method:

  1. File

  2. Database

  3. Redis

Let me use a soil method. The database creates a table with the id, content, and updated_at fields.
Put a data entry in Initialization: 1, accesstoken, 1440121354
Then, when you need to obtain the access_token, use the current timestamp time () to go to the database and check where id = 1 and updated_at> time ()-expiration time
If a value is obtained, it will be used directly. If it is not stated that it takes too long, re-obtain the accesstoken, save it to the database, and update the timestamp.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.