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