主要利用ThinkPHP6的缓存机制
public function getWxAccessToken($appId,$appSecret){ $access_token = Cache::get('wx_access_token:'.$appId); if($access_token){ return createResult(200,'success',$access_token); }else{ //1.请求url地址 $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appId."&secret=".$appSecret; $res = $this->http_curl($url); if(isset($res['errcode']) && $res['errcode']!=0){ return createResult($res['errcode'],$res['errmsg']); } $access_token = $res['access_token']; Cache::tag('AToken')->set('wx_access_token:'.$appId,$access_token,3600); return createResult(200,'success',$access_token); } }