Keyword: Memcacheaccess_token update storage 7200 this article describes how to use cached Memcache storage and how to update accesstoken. 1. AccessTokenaccess_token is the globally unique ticket of the public account. access_token is required when the Public Account calls each interface. Under normal circumstances, the validity period of access_token is 720
Keyword: Memcacheaccess_token update storage 7200 this article describes how to use cached Memcache storage and how to update access token. 1. Access Token access_token is the globally unique ticket of the public account. access_token is required when the Public Account calls each interface. Under normal circumstances, the validity period of access_token is 720
Keyword: Memcache access_tokenUpdate Storage7200
This article describes howUseCacheMemcacheStorageAndUpdateAccess token method.
1. Access Token
Access_token is the globally unique ticket of the public account.UseAccess_token. Under normal circumstancesAccess_token is valid for 7200 seconds, Duplicate access will invalidate the last access_token.
Public Account is acceptableUseAppID and AppSecret call this interface to obtain the access_token. AppID and AppSecret can be obtained in the Development Mode (you need to become a developer and the account is not abnormal ).Note that all interfaces must be called.UseHttps protocol.
API call request description
Http Request Method: GEThttps: // api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = APPID & secret = APPSECRET
Parameter description
Parameters |
Required? |
Description |
Grant_type |
Yes |
Obtain access_token and enter client_credential |
Appid |
Yes |
Unique third-party user credential |
Secret |
Yes |
The unique credential key of a third-party user, which is appsecret |
Return description
Normally, the following JSON data packet is returned to the Public Account:
{"access_token":"ACCESS_TOKEN","expires_in":7200}
Ii. Memcache
Memcache is a high-performance distributed memory object.CacheThe system maintains a unified huge hash table in the memory, which can be usedStorageData in various formats, including images, videos, files, and database retrieval results. Simply put, the data is called to the memory and then read from the memory, which greatly improves the reading speed.
Memcache is a danga project that was first developed for the LiveJournal service and was later used by many large websites to accelerate the LiveJournal access speed.
Memcached runs on one or more servers as a daemon and receives client connections and operations at any time.
Iii. Implementation
Appid = $ appid; $ this-> appsecret = $ appsecret;} $ mem = new Memcache; $ mem-> connect ('localhost', 11211) or die ("cocould not connect"); $ this-> access_token = $ mem-> get ('Access _ token'); if (empty ($ this-> access_token )) {$ url =" https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= ". $ This-> appid. "& secret = ". $ this-> appsecret; $ res = $ this-> http_request ($ url); $ result = json_decode ($ res, true ); $ this-> access_token = $ result ["access_token"]; $ mem-> set ('Access _ token', $ this-> access_token, 0, 7200 );}} // HTTP Request (support for HTTP/HTTPS and GET/POST) protected function http_request ($ url, $ data = null) {$ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url); curl_setopt ($ curl, CURLOPT_SSL_V ERIFYPEER, FALSE); curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (! Empty ($ data) {curl_setopt ($ curl, CURLOPT_POST, 1); curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data);} curl_setopt ($ curl, expires, 1 ); $ output = curl_exec ($ curl); curl_close ($ curl); return $ output ;}}?>