网页授权回调域名的说明
1、在微信公众号请求用户网页授权之前,开发者需要先到公众平台官网中的“开发 - 接口权限 - 网页服务 - 网页帐号 - 网页授权获取用户基本信息”的配置选项中,修改授权回调域名。请注意,这里填写的是域名(是一个字符串),而不是URL,因此请勿加 http:// 等协议头;
2、授权回调域名配置规范为全域名,比如需要网页授权的域名为:www.qq.com,配置以后此域名下面的页面http://www.qq.com/music.html 、 http://www.qq.com/login.html 都可以进行OAuth2.0鉴权。但http://pay.qq.com 、 http://music.qq.com 、 http://qq.com无法进行OAuth2.0鉴权
备注:回调不能设置其他域名是用户可以通过前端直接授权跳转到指定的域名会泄露信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function getBaseInfo(){ $appid="xxx"; $redirect_uri=urlencode("http://www.xxxx.cn/xxx.php/Index/getUserOpenId"); $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_base&state=123#wechat_redirect"; header('location:'.$url); }
function getUserOpenId(){ $appid="xxx"; $appsecret="xxx"; $code=$_GET['code']; $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_code "; $res = $this->http_curl($url,'get'); var_dump($res); }
|