微信 getAccessToken方法詳解及實例
更新時間:2016年11月23日 15:09:04 投稿:lqh
這篇文章主要介紹了微信 getAccessToken方法詳解及實例的相關(guān)資料,這里提供了簡單的實例代碼,需要的朋友可以參考下
memcache緩存存儲用戶信息7000秒
<?php function getAccessToken($appid,$appsecret) { $mem = new CacheMemcache(); $acc = $mem->get('access_token_'.$appid); if (!$acc) { $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $result = https_request($url); $jsoninfo = json_decode($result, true); $access_token = $jsoninfo['access_token']; if ($access_token) { $expire = time() + 7000; $mem = new CacheMemcache(); $mem->set('access_token_'.$appid,$access_token,$expire); } } else { $access_token = $acc; } return $access_token; } ?>
文件存儲access_token
function getAccessToken() { // access_token 應(yīng)該全局存儲與更新,以下代碼以寫入到文件中做示例 $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; }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
您可能感興趣的文章:
- 微信支付java版本之獲取Access_token
- java微信公眾號開發(fā)第一步 公眾號接入和access_token管理
- PHP cURL獲取微信公眾號access_token的實例
- 詳解Node.js access_token的獲取、存儲及更新
- PHP定時任務(wù)獲取微信access_token的方法
- .Net微信開發(fā)之如何解決access_token過期問題
- C#微信公眾平臺開發(fā)之a(chǎn)ccess_token的獲取存儲與更新
- .net微信開發(fā) 如何獲取AccessToken
- iOS開發(fā)之路--微博OAuth授權(quán)_取得用戶授權(quán)的accessToken
- 使用java代碼獲取新浪微博應(yīng)用的access token代碼實例
相關(guān)文章
jQuery EasyUI API 中文文檔 - DateBox日期框
jQuery EasyUI API 中文文檔 - DateBox日期框,需要的朋友可以參考下。2011-10-10php生成復(fù)雜驗證碼(傾斜,正弦干擾線,黏貼,旋轉(zhuǎn))
現(xiàn)在好多網(wǎng)站使用的驗證碼非常容易被軟件自動識別到,本文介紹了一種PHP生成驗證碼并加入傾斜,弦干擾線,黏貼,旋轉(zhuǎn)等效果2018-03-03shell編程入門之變量,字符串,數(shù)組,函數(shù)使用方法總結(jié)
這篇文章主要介紹了shell編程入門之變量,字符串,數(shù)組,函數(shù)使用方法總結(jié),需要的朋友可以參考下2022-01-01