public function login(){
$urlencode = urlencode("http://www.zhangxuhui.com/index/Index/callback");
$url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=XXXXXXXX&redirect_uri={$urlencode}&state=shop";
$data = compact("url");
return view("",$data);
}
// 回调地址
public function callback($code){
// 1.获取code
// 2.发起请求 获取access_token
$urlencode = urlencode("http://www.zhangxuhui.com/index/Index/callback");
$url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=XXXXXXX&client_secret=YYYYYYYYYYYY&code={$code}&redirect_uri={$urlencode}&fmt=json";
$json = file_get_contents($url);
$obj = json_decode($json);
$access_token = $obj->access_token;
// 3.发起请求 获取openid
$url = "https://graph.qq.com/oauth2.0/me?access_token={$access_token}&fmt=json";
$obj = json_decode(file_get_contents($url));
$openid = $obj->openid;
// 4.获取用户的信息
$url = "https://graph.qq.com/user/get_user_info?access_token={$access_token}&oauth_consumer_key=XXXXXXXXX&openid={$openid}";
dump(file_get_contents($url));
// 1.qq_member表写入数据,id,openid,nickname,gender,login_num,mid
// 2.写session
// 3. 跳转到首页
}