Public functionGetopenid ($appid,$appsecret) { $SERVER _name=$_server[' server_name ']; $REQUEST _uri=$_server[' Request_uri ']; $redirect _uri=UrlEncode(' http://'.$SERVER _name.$REQUEST _uri); $code=$_get[' Code ']; if(!$code) { //Web page Authorization when Scope=snsapi_userinfo is not prompted to authorize the app $autourl= "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect _uri&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect "; Header("Location:$autourl"); } Else { //Get OpenID $url= "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code "; $row=$this->posturl ($url); return($row[' OpenID ']); } } Public functionPostURL ($url){ $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_ssl_verifypeer,FALSE); curl_setopt ($ch, Curlopt_ssl_verifyhost,FALSE); curl_setopt ($ch, Curlopt_returntransfer, 1); $output= Curl_exec ($ch); Curl_close ($ch); $jsoninfo= Json_decode ($output,true); return $jsoninfo; }//How to use: $appid= "wx18a554232c71513b"; $secret= "662xxxxxxf9xxxxxxb6xxxxxx44xxxxx"; $openid=$this->getopenid ($appid,$secret); When a Web page authorizes the scopeThe following interface appears when =snsapi_userinfo:
Thank you very much for the guidance of the Great God, let me go a few detours, I also want to see friends less detours ha.
PHP code How to get the user's OpenID Web page