做商城网站可以个人备案,太原室内设计公司排名,网站建设柚子网络科技怎么样,深圳个人形象设计工作室在开发之前#xff0c;我们要确保我们的服务号#xff0c;在接口权限处#xff0c;已经获得了网页授权权限 此外#xff0c;我们还需要有个备案通过的域名#xff0c;比如www.myname.com#xff0c;并确保你的域名可以访问到你的服务器#xff0c;于是在公众…在开发之前我们要确保我们的服务号在接口权限处已经获得了网页授权权限 此外我们还需要有个备案通过的域名比如www.myname.com并确保你的域名可以访问到你的服务器于是在公众号设置那里把域名配置好把校验文件MP_verify_lS1VtPAOta6l5jrQ.txt放置到你的网站的根目录于是提交成功变成如下设置 接下来我们要去建立一个php文件getinfo.php内容如下
?php
$appid wxxxxa95xxx0xxxxx;#你的公众号appid$urlhttps://open.weixin.qq.com/connect/oauth2/authorize?appid$appidredirect_urihttp%3A%2F%2Fwww.xingchuangpinzhi.com%2FgetinfoDetail.phpresponse_typecodescopesnsapi_userinfostateSTATE#wechat_redirect;#redirect_uri改为你的网页授权域名和刚刚跳转到的显示页面比如我的是getinfoDetail.phpheader(location:.$url);
?
建立一个php文件getinfoDetail.php内容如下
?php
header(Access-Control-Allow-Origin:*); #设置跨域
header(Content-Type: application/json; charsetUTF-8);
//获取存放在cookies里面的token
$code $_GET[code];
$state $_GET[state];
//换成自己的接口信息
$appid wxxxxxxxxxxxxxx;#你的公众号appid
$appsecret 7xxfxxxxxxxxxxxxxxxxx;#你的公众号appsecret
if (empty($code)) $this-error(授权失败);
$token_url https://api.weixin.qq.com/sns/oauth2/access_token?appid.$appid.secret.$appsecret.code.$code.grant_typeauthorization_code;
$token json_decode(file_get_contents($token_url));
if (isset($token-errcode)) {echo h1错误/h1.$token-errcode;echo br/h2错误信息/h2.$token-errmsg;exit;
}
$access_token_url https://api.weixin.qq.com/sns/oauth2/refresh_token?appid.$appid.grant_typerefresh_tokenrefresh_token.$token-refresh_token;
//转成对象
$access_token json_decode(file_get_contents($access_token_url));
if (isset($access_token-errcode)) {echo h1错误/h1.$access_token-errcode;echo br/h2错误信息/h2.$access_token-errmsg;exit;
}
$user_info_url https://api.weixin.qq.com/sns/userinfo?access_token.$access_token-access_token.openid.$access_token-openid.langzh_CN;
//转成对象
$user_info json_decode(file_get_contents($user_info_url));
if (isset($user_info-errcode)) {echo h1错误/h1.$user_info-errcode;echo br/h2错误信息/h2.$user_info-errmsg;exit;
}$rs json_decode(json_encode($user_info),true);//返回的json数组转换成array数组
$openid $rs[openid];
$nickname$rs[nickname];
$sex$rs[sex];
$language$rs[language];
$city$rs[city];
$province$rs[province];
$country$rs[country];
$headuri$rs[headimgurl];
//打印用户信息
echo $openid;
echo $nickname;
echo $sex;
echo $language;
echo $city;
echo $province;
echo $nickname;
echo $headuri;
echo $country;
?完成后访问urlhttp://www.我的域名.com/getinfo.php显示 点击获取打印出授权用户信息 任何程序错误以及技术疑问或需要解答的请扫码添加作者VX