标签:grant scope use urlencode index curl res 用户 fun
//第一种方式:只获取用户的openid
function getBaseInfo(){
//1.获取到code
$appid = "wx75f3d0f10c8567ad";
$redirect_uri = urlencode("www.test.com/test/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(){
//2.获取到网页授权的access_token
$appid = "wx75f3d0f10c8567ad";
$secret = "0088c7c976aa6de93ff92e177540786f";
$code = $_GET[‘code‘];
$url = " https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret="..$secret"&code=".$code."&grant_type=authorization_code ";
//3.拉去用户的openid
$res = $this->http_curl($url,‘get‘);
//页面index.tpl
//$this->display(‘index.tpl‘)
var_dump($res);
}
//第二种方式:获取用户的详细信息
function getUserDetail(){
//1.获取到code
$appid = "wx75f3d0f10c8567ad";
$redirect_uri = urlencode("www.test.com/test/Index/getUserInfo");
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
header("location:".$url);
}
function getUserInfo(){
/2.获取到网页授权的access_token
$appid = "wx75f3d0f10c8567ad";
$secret = "0088c7c976aa6de93ff92e177540786f";
$code = $_GET[‘code‘];
$url = " https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret="..$secret"&code=".$code."&grant_type=authorization_code ";
//3.拉去用户的openid
$res = $this->http_curl($url,‘get‘);
$openid = $res[‘openid‘];
$access_token = $res[‘access_token‘];
//拉取用户的详细信息
$url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN ";
$res = $this->http_curl($url);
var_dump($res);
}
标签:grant scope use urlencode index curl res 用户 fun
原文地址:http://www.cnblogs.com/zrkailml/p/7646994.html