Blogger Information
Blog 17
fans 0
comment 0
visits 23400
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
TP5开发微信公众号时,access_token存储和刷新问题
星辰幽梦
Original
1171 people have browsed it

TP5开发微信公众号时,access_token存储和刷新问题

主要利用tp5的缓存机制

  1. public function getWxAccessToken($appId,$appSecret){
  2. $access_token = Cache::get('wx_access_token:'.$appId);
  3. if($access_token){
  4. return createResult(200,'success',$access_token);
  5. }else{
  6. //1.请求url地址
  7. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appId."&secret=".$appSecret;
  8. $res = $this->http_curl($url);
  9. if(isset($res['errcode']) && $res['errcode']!=0){
  10. return createResult($res['errcode'],$res['errmsg']);
  11. }
  12. $access_token = $res['access_token'];
  13. Cache::tag('AToken')->set('wx_access_token:'.$appId,$access_token,3600);
  14. return createResult(200,'success',$access_token);
  15. }
  16. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post