//第一步 获取用户tokenpublic function getUserAccessToken(){$url = "https://api./cgi-bin/token?grant_type=client_credential&appid=231111&secret=232323";$res = json_decode($this->httpRequest($url),true);return $res['access_token'];}
//第二步 获取用户信息通过acccess_token和open_id获取用户信息public function getUserInfoByToken($access_token,$open_id){$url = "https://api./cgi-bin/user/info?access_token=$access_token&openid=$open_id&lang=zh_CN";$res = json_decode($this->httpRequest($url),true);if ($res['unionid']){return $res['unionid'];}}
/**** POST或GET请求* @url 请求url* @data POST数据* @return**/private function httpRequest($url, $data = ""){$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);if(!empty($data)){ //判断是否为POST请求curl_setopt($curl, CURLOPT_POST, 1);curl_setopt($curl, CURLOPT_POSTFIELDS, $data);}curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);$output = curl_exec($curl);curl_close($curl);return $output;}