define("APPID", "xxxx");
define("APPSECRET", "xxx");
$code = $_GET['code'];
if(!$code){
echo '<a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5d7a4bb756e53b28&redirect_uri=http://www.xxx.com/index.php?m=oauth2&a=init&response_type=code&scope=snsapi_base&state=1#wechat_redirect" target="_blank">点击登陆</a>';
}else{
//使用code获取OpenID
$openid_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";
$openid_data = file_get_contents($openid_url);
$arr_openid = (Array)json_decode($openid_data);
$openid = $arr_openid['openid'];
//获取全局Access Token
/*
$access_token_url = "https://api.weixin.qq.com/cgi-
微信通过网页获取用户头像与昵称等信息
最新推荐文章于 2023-04-23 10:24:41 发布