1、設定授權回呼頁域名,如 www.aaa.com
2、模擬公眾號的第三方網頁,fn_system.php
Php代碼
'user' ]);
$appid
.
'&redirect_uri=http%3a%2f%2fwww.aaa.com%2fuc%2ffn_callback.php&resp/s>
header("Location:"
.$url.$url.$url.$url.$url.$url.$url.$url。 ?>
<span>$_GET<span></span>[<span></span>"code"<span></span>]; <span></span><span></span><span></span>$get_token_url</span> = <li>
<span>'https://api.weixin.qq.com/sns/oauth2/access_token?appid='<span></span>.<span>.</span>$appid<span></span>.<span></span>'&secret='<span></span>.<span></span>$secret<span></span>.<span></span>$secret<span></span>.<span></span></span>.<span></span>$code<span></span>.<span></span>'&grant_type=authorization_code'<span></span>; ><span></span> </li>
<li>
<span></span>$ch</li>
<li> = curl_init(); curl_setopt(<span>$ch<span></span>,CURLOPT_URL,<span></span>$get_token_url</span>
</li>); <li>
<span><span>$ch</span><span>,CURLOPT_HEADER,0); </span><span></span><span></span>curl_setopt(</span>$ch</li>
<li>curl_setopt(<span>$ch<span></span>curl_setopt(<span>$ch</span></span>curl_setopt(</li>$ch<li>$ch<span></span><span></span>curl_setopt($ch</li>
<li>, CURLOPT_CONNECTTIMEOUT, 10); <span><span>$res</span><span> = curl_exec(</span></span>$ch</li>
<li>); <span><span></span><span></span> ch<span></span>); <span></span></span>
</li>
<li><span>$json_obj<span></span> > 🎜>,true); <span></span></span></li>
<li> <span><span></span><span></span>///openpid和> <span></span><span></span></span>
</li>$access_token<li><span> = </span></li>$json_obj<span>]; </span><span></span><li>$openid<span><span></span><span>$openid</span><span></span><span>$openid</span><span>[</span><span>'openid'</span></span>]; </li>
<li>
<span><span></span><span>$get_user_info_url</span><span></span>$get_user_info_url<span></span><span>$get_user_info 🎜>'https://api.weixin.qq.com/sns/userinfo?access_token='</span><span>.</span></span>$access_token</li>
<li>.<span><span></span><span>.</span><span></span> '&openid='<span></span>.<span></span>$openid<span></span>.<span></span>'&lang=zh_CN'<span></span><span>'&lang=zh_CN'</span><span> </span><span></span> <span></span></span>
</li>
<li>$ch<span></span> = curl_init(); 🎜></li> = curl_init(); 🎜>curl_setopt(<li>$ch<span><span>,CURLOPT_URL,</span><span>$get_user_info_url</span></span>); (</li>$ch<li>
<span>,CURLOPT_HEADER,0); <span></span><span></span><span>curl_setopt(</span>$ch<span></span>curl_setopt(</span>$ch</li>
<li>curl_setopt(<span>$ch</span><span></span>curl_setopt(</li>$ch<li><span>, CURLOPT_CONNECTTIMEOUT, 10);<span>, CURLOPT_CONNECTTIMEOUT, 10); ></span>$res<span></span> = curl_exec(</span></li>$ch<li>
<span>); <span></span>); </span><url>$ch</url>
</li>
<li>); <span><span></span><span></span> <span></span><span></span></span>
</li>
<li> <span><span></span><span></span></span>$user_obj</li>
<li> = json_decode(<span>$res</span>$res</li>
<li><span><span></span>$_SESSION<span></span>[</span></li>'user'<li>
<span>]>_objo<span>'user'</span><span>]>_objo</span></span>; <span></span>
</li>
<li>print_r(<span>$user_obj<span></span>);; 🎜> <span></span><span></span>?> <span></span><span></span><span>
</span>
以上就介紹了 微信公眾平台OAuth20網頁授權php範例,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。 </span>
</li>
<li>