The php,php section is used as follows:
$code = $_get["code"]; $userinfo = GetUserInfo ($code); function GetUserInfo ($code) {$appid = "1111111111"; $appsecret = "1111111111111";//appid and Appsecret are hidden here, in the source code is correct $access _token = ""; Get access_token $access _token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid= $appid &secret= $appsecret &code= $code &grant_type=authorization_code "; $access _token_json = https_request ($access _token_url); $access _token_array = Json_decode ($access _token_json,true); $access _token = $access _token_array[' Access_token '); $openid = $access _token_array[' OpenID '); Get User info $userinfo _url = "https://api.weixin.qq.com/sns/userinfo?access_token= $access _token&openid= $open ID "; $userinfo _json = https_request ($access _token_url); $userinfo _array = Json_decode ($userinfo _json,ture); echo $userinfo _json; return userinfo_array; } function Https_request ($url) { $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $url); curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE); curl_setopt ($curl, Curlopt_ssl_verifyhost, FALSE); curl_setopt ($curl, Curlopt_returntransfer, 1); $data = curl_exec ($curl); if (Curl_errno ($curl)) {return ' ERROR '. Curl_error ($curl); } curl_close ($curl); return $data; }
And now the problem is that there was a problem with the Userinfo_json, which caused the final result to fail to show.
Intermediate process to Userinfo_json output, prompt {"Errcode": 40029, "errmsg": "Invalid Code"}
And if I copy the Userinfo_url link on my phone, I can still call the user's details.
So what's the problem? What's the answer? Ask the Great God for answers
Reply content:
The php,php section is used as follows:
$code = $_get["code"]; $userinfo = GetUserInfo ($code); function GetUserInfo ($code) {$appid = "1111111111"; $appsecret = "1111111111111";//appid and Appsecret are hidden here, in the source code is correct $access _token = ""; Get access_token $access _token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid= $appid &secret= $appsecret &code= $code &grant_type=authorization_code "; $access _token_json = https_request ($access _token_url); $access _token_array = Json_decode ($access _token_json,true); $access _token = $access _token_array[' Access_token '); $openid = $access _token_array[' OpenID '); Get User info $userinfo _url = "https://api.weixin.qq.com/sns/userinfo?access_token= $access _token&openid= $open ID "; $userinfo _json = https_request ($access _token_url); $userinfo _array = Json_decode ($userinfo _json,ture); echo $userinfo _json; return userinfo_array; } function Https_request ($url) { $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $url); curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE); curl_setopt ($curl, Curlopt_ssl_verifyhost, FALSE); curl_setopt ($curl, Curlopt_returntransfer, 1); $data = curl_exec ($curl); if (Curl_errno ($curl)) {return ' ERROR '. Curl_error ($curl); } curl_close ($curl); return $data; }
And now the problem is that there was a problem with the Userinfo_json, which caused the final result to fail to show.
Intermediate process to Userinfo_json output, prompt {"Errcode": 40029, "errmsg": "Invalid Code"}
And if I copy the Userinfo_url link on my phone, I can still call the user's details.
So what's the problem? What's the answer? Ask the Great God for answers
Http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
Take a good look at the documentation, the question is a bit big.
You are wrong in this case!
$userinfo _json = https_request ($access _token_url);
Should be
$userinfo _json = https_request ($userinfo _url);
This causes code to be used two times, code is allowed only once, valid for 5 minutes
Again:code can only be used once and cannot be refreshed
Https://github.com/thenbsp/wechat