<?php
set_time_limit(0);
header("Content-Type: text/html;charset=utf-8");
//告诉浏览器不要缓存数据
header("Cache-Control: no-cache");
$code=$_GET["code"];
//var_dump($code);
//echo $code."111";
//exit;
if($code==NULL){
$url5="https://cas.hrbcu.edu.cn/cas/oauth2.0/authorize?response_type=code&client_id=jeTVmqw8a2iF96OiPN&redirect_uri=https://xt.hrbcu.edu.cn/rz.php";
header("Location:".$url5);
}
//echo $code."<br>";
//exit;
//echo file_get_contents("http://www.baidu.com");
$url="https://cas.h.cn/cas/oauth2.0/accessToken?client_id=jeTVmqw8a2iF96OiPN&client_secret=1b365b69ec254707b4ee84ef0000c0e4&code=".$code."&redirect_uri=https://xt.hrbcu.edu.cn/rz.php";
//echo $url."<br>";
//header("Location:".$url);
//exit;
//$html = fopen($url,"r");
//$aaaa=file_get_contents("http://5.4/cas/oauth2.0/accessToken?client_id=jeTVmqw8a2iF96OiPN&client_secret=1b365b69ec254707b4ee84ef0000c0e4&code=".$code."&redirect_uri=http://12.96/ceshi.php");
$param="";
$postUrl = $url;
$curlPost = $param;
$ch = curl_init();
/*$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch); */
$timeout = 5;
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);//运行curl
curl_close($ch);
//echo $file_contents."555";
$result = json_decode($file_contents, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
$access_token = $result["access_token"];
//echo $access_token;
$url1="https://cas.hrbcu.edu.cn/cas/oauth2.0/profile?access_token=".$access_token."";
//echo $url1;
$param1="";
$postUrl1 = $url1;
$curlPost1 = $param1;
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL,$postUrl1);//抓取指定网页
curl_setopt($ch1, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch1, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $curlPost1);
$file_contents1 = curl_exec($ch1);//运行curl
curl_close($ch1);
/*$timeout1 = 5;
curl_setopt ($ch1, CURLOPT_URL, $url1);
curl_setopt($ch1, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
curl_setopt ($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt ($ch1, CURLOPT_CONNECTTIMEOUT, $timeout1);
$file_contents1 = curl_exec($ch1);
curl_close($ch1); */
$result1 = json_decode($file_contents1, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
//var_dump($result1);
$username=$result1["id"];
//echo $id;
//$username=urlencode($id);
//echo $username;
$url2="http://xt.hrbcu.edu.cn/logincheck_new.php?username=".$username;
//echo "<br>";
//echo $url2;
?>
<script>location.href="<?=$url2?>";</script>
<?
//header("Location:".$url2);
exit;
/*$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL,'$url');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$url = curl_exec($ch);*/
echo $url."<br>";
$result = json_decode($url, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
$access_token = $result["access_token"];
echo $access_token;
exit;
/*$url="http://.3:1003/open/accessToken?client_id=vTG041gw&response_type=code&scope=baseInfo&client_secret=BcXxkw&grant_type=authorization_code&code=$access_code&redirect_uri=http://60.219.114.4:8081/ceshi.php";
//echo $url;
$html = file_get_contents($url);
echo $html;
$result = json_decode($html, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
$access_token = $result["data"]["access_token"];
echo $access_token;
$url1="http://6.219.14.3:1003/open/userInfo?access_token=$access_token";
$html1 = file_get_contents($url1);
echo $html1;
$result1 = json_decode($html1, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
$username = $result1["data"]["user"]["username"];
echo $username;
//file_get_contents($url2);*/
?>