Step 1: url used to obtain the assembly code (access via Developer Tools)
HTTPS: // open.weixin.qq.com/connect/oauth2/authorize?appid= own redirect_uri = HTTP & APPID: // own URL /login.php&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
< ?php #1.获取code $code = $_GET['code']; # 2. Get openid and accessiontoken $ apiData = Array ( 'AppID' => 'wx56e3e3d75414b3d0', 'secret'=>'f8ec8178c6dda48d1cb25c07304eff44', 'code'=> $code, 'grant_type'=>'authorization_code' ); $api = "https://api.weixin.qq.com/sns/oauth2/access_token?".http_build_query($apiData); $data = json_decode(file_get_contents($api), true); // echo $data['access_token']; // echo '<hr/>'; // echo $data['openid']; # 步骤3:根据openid和access_token获取用户信息 $apiData = array( 'access_token'=> $data['access_token'], 'openid'=> $data['openid'], 'lang'=>'zh_CN' ); $api = "https://api.weixin.qq.com/sns/userinfo?".http_build_query($apiData); $data = json_decode(file_get_contents($api), true); echo '<pre>'; print_r($data);