/* * 获取token */ private function get_access_token(){ $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appleid}&secret={$this->secret}"; $str = file_get_contents($url); $arr = json_decode($str,true); if(isset($arr['access_token']) && $arr['access_token'] != ''){ return $arr['access_token']; }else{ return ''; } } /* * 获取用户信息 */ private function user_info($openid){ $token = $this->get_access_token(); $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$token}&openid={$openid}&lang=zh_CN"; $str = file_get_contents($url); $arr = json_decode($str,true); return $arr; }
参考:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839