appId}&secret={$this->appSecret}"; $token = cache("token"); if(!$token){ $data = $this->curl_get($url); $token = $data->access_token; cache("token",$token,7000); return $token; }else{ return $token; } } public function getOpenid($code) { $url = "https://api.weixin.qq.com/sns/jscode2session?appid=$this->appId&secret=$this->appSecret&js_code=$code&grant_type=authorization_code"; $result = $this->curl_get($url); return $result->openid; } public function curl_get($url) { $ch = curl_init();//初始化curl curl_setopt($ch, CURLOPT_URL,$url); //要访问的地址 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//跳过证书验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 $data = json_decode(curl_exec($ch)); if(curl_errno($ch)){ var_dump(curl_error($ch)); //若错误打印错误信息 } curl_close($ch);//关闭curl return $data; } }