JavaScript-WeChat JS interface, Access_token and Jsapi_ticket no cache caused by the service is not available how to solve?

Source: Internet
Author: User
Now has been jumping invalid signature signature error, do not know how to solve, is waiting for a period of time on the line or can not be used?

Reply content:

Now has been jumping invalid signature signature error, do not know how to solve, is waiting for a period of time on the line or can not be used?

then cache it. Conditional on Memcache,redis, simple point directly with the file cache also line (the official demo is)

The document seems to say that Access_token is 7,200 seconds overdue,
So, we just have to simply write the file to achieve the purpose of caching,

For example, the following code is to read the cache first, if not, then ask again

$token = Lib_Cache::read('access_token', 3600);if (!$token || strlen($token) < 6) {    $res = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.Lib_Weixin::$appId.'&secret='.Lib_Weixin::$appSecret);    $res = json_decode($res, true);    $token = $res['access_token'];    Lib_Cache::write('access_token', $token, 3600);}return $token;

After this independence, the cache part can be replaced by any scheme, I am here to simple file as an example, mainly I also use the file, not trouble:

class Lib_Cache {    public static function read($file, $expires) {        if(file_exists($file)) {            $time = filemtime($file);            if(time() - $time > $expires) {                return null;            }else {                return file_get_contents($file);            }        }        return null;    }    public static function write($file, $value) {        @file_put_contents($file, $value);    }}

Access_token request, there are 2000 times a day limit, but 7,200 seconds expired, so 3,600 seconds one hours once, how to use and will not expire

Access_token official limit to get 2000 times a day, but the signature is wrong, you have to check your signature in the end there is no problem ah.

Save in database, write timed tasks, request every 110 minutes ... Use Accesstoken to decide whether to expire

  • 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.