memcache缓存存储用户信息7000秒

<"https://api.weixin.qq.com/cgi-bin/token";
    $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;
}
"htmlcode">
 function getAccessToken() {
  // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  $data = json_decode(file_get_contents("access_token.json"));
  if ($data->expire_time < time()) {
   $url = "https://api.weixin.qq.com/cgi-bin/token";
   $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;
 }


感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com