Public Function 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) {//web page Authorization $autourl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid= $appid & amp;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 &SECR et= $appsecret &code= $code &grant_type=authorization_code "; $row = $this->posturl ($url); Return ($row [' OpenID ']); }} Public Function 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; }
How to get user OpenID