Publicfunction Getopenid ($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) { //website Authorization$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']); } } Publicfunction PostURL ($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; }
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