How to understand Wechat getAccessToken
This article introduces the relevant knowledge of "how to understand Wechat getAccessToken". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Memcache cache stores user information for 7000 seconds
File storage access_token
Function getAccessToken () {/ / access_token should be stored and updated globally, the following code to write to a file for example $data = json_decode (file_get_contents ("access_token.json")); if ($data- > expire_time)
< time()) { $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->AppId&secret=$this- > appSecret "; $res = json_decode ($this- > httpGet ($url)); $access_token = $res- > access_token; if ($access_token) {$data- > expire_time = time () + 7000; $data- > access_token = $access_token; $fp = fopen (" access_token.json "," w "); fwrite ($fp, json_encode ($data)); fclose ($fp);} else {$access_token = $data- > access_token } return $access_token;} "how to understand Wechat getAccessToken" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!