//详细授权1
public function grant(){
//1户同意授权 获取code
$appid='8888888888888888888888888';
$redirect_uri=urlencode("http://wwwwwwwwwwwww/fruits/public/index.php/home/wei/role");
$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);
}
///详细授权2
public function role(){
//2 通过code 换取网页授权access_token
$appid="8888888888888888888888";
$secret="788888888888888888888888882";
$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->httpCurl($url,'get');
$openid=$res['openid'];
$access_token=$res['access_token'];
//拉去用户的详细信息
$urls="https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
$reslist=$this->httpCurl($urls);
var_dump($reslist);
}
//获取用户详细信息
public function userDescAction(){
$access_token=$this->accessTokenAction();
$openid='22222222222';
$url="https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
$res=$this->httpCurlAction($url,'get','json','');
var_export($res);
var_dump($res);
// array (size=13)
// 'subscribe' => int 1
// 'openid' => string '222222' (length=28)
// 'nickname' => string '2222' (length=9)
// 'sex' => int 2
// 'language' => string 'zh_CN' (length=5)
// 'city' => string '22222' (length=9)
// 'province' => string '江苏' (length=6)
// 'country' => string '中国' (length=6)
// 'headimgurl' => string 2/mmo2XhOPTXbs1jxMf80YyEhicpwqdQ1Yia5L9PjuqcwG1ib8YpGtXxM6PUT3UJdwrIlOGpPbKSlRzwWQyD6Kf2/0' (length=128)
// 'subscribe_time' => int 1503454568
// 'remark' => string '' (length=0)
// 'groupid' => int 0
// 'tagid_list' =>
// array (size=0)
// empty
}