应用场景
(1)点击菜单直接链接跳转,这样直接跳是获取不到用户的openid的,需要用到这个
(2)获取用户的一些基本信息,头像,呢称,需要用到这个
准备
需要在公众号里面配置一个应用域名,不配置这个的话,跳转后就是空白页面
步骤
(一)
//$callback="一个回调的网址比如http://www.baidu.com/auth.php";
$param ['redirect_uri'] = $callback . '&getOpenId=1';
//&getOpenId=1 这个参数是自己加着用的,跟微信无关$param ['response_type'] = 'code';$param ['scope'] = 'snsapi_userinfo';$param ['state'] = 123;$param ['appid'] = $info ['appid'];//拼凑出一个url 请求此url
$url = 'https://open.weixin.qq.com/connect/oauth2/authorize?' . http_build_query ( $param ) . '#wechat_redirect';/*url大致的样子如下
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxxxxxxx8xx9b9&redirect_uri=http%3A%2F%2Fxxxn.xingames.com%2Fweiphp%2Fixxxex.php%3Fs%3D%2Faddon%2FMxxber%2FMexxxber%2Findex%26getOpenId%3D1&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect*/redirect ($url );
***$param ['scope'] = 'snsapi_userinfo'诸如这样的参数什么意思,可以查询微信的手册
地址:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
(二) 跳转到上面的url后,微信会返回给你这个u