作者:mobiledu2502939777 | 来源:互联网 | 2022-07-27 11:08
memcache缓存存储用户信息7000秒
<&#63;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&#63;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;
}
&#63;>
文件存储access_token
function getAccessToken() {
// access_token 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode(file_get_contents("access_token.json"));
if ($data->expire_time
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!