前后分离项目使用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

<?php
require '../idapi_config.php';
require '../idapi_function.php';
require '../idapi_class_getuser.php';
header("Content-Type: application/json; charset=utf-8");
//实例化授权用户
$idNewGetuser = new idapi_getuser();
$id_ckauth = $idNewGetuser->getAuth();// 读取cookie中的fr_id_auth
$id_ckauthinfo = $id_ckauth['client'];
$id_getUserinfo = $idNewGetuser->getUserinfo();
//刷新access_token
/*if($id_ckauthinfo['uid'] && time() > $id_ckauth['expires_time']){
setRefreshToken();
}*/
//获取资料
if($_COOKIE['fr_id_auth'] && !$_COOKIE['fr_id_userinfo']){
id_user_info($id_ckauthinfo['uid'],$id_ckauthinfo['appid'],$id_ckauth['access_token']);
}elseif($_COOKIE['fr_id_userinfo'] && !$id_getUserinfo['data']['uid']){
//这里的token会导致无法直接写入:fr_id_auth
id_refresh_token();
id_user_info($id_ckauthinfo['uid'],$id_ckauthinfo['appid'],$id_ckauth['access_token']);
}
//每天第一次访问统计
if($_COOKIE["fr_id_auth"] && $_COOKIE["fr_id_addexist_time"] != date('Ymd')){
$addexist_data = ['uid' => $id_ckauthinfo['uid'],'device' => $_COOKIE["fr_id_appname"]];
$addexist_header = ['authentication:'.base64_encode($id_ckauthinfo['appid'].'.'.$id_ckauth['access_token'].'.'.$id_ckauthinfo['uid'])];
$re_addexist = CallInterface(API_URL.'/v1/user/addexist/','POST',$addexist_data,$addexist_header);
$addexist_jsonarr = json_decode($re_addexist,true);
if($addexist_jsonarr['code']=='201' || $addexist_jsonarr['code']=='200'){
setcookie('fr_id_addexist_time',date('Ymd'),time()+3600*24*365,'/');
}
}
// 无token更新
if(!$_COOKIE["fr_access_token"]){
setcookie('fr_access_token',$id_ckauth['access_token'],time()+3600*24*365,'/');
setcookie('fr_uid',$id_ckauthinfo['uid'],time()+3600*24*365,'/');
setcookie('fr_appid',$id_ckauthinfo['appid'],time()+3600*24*365,'/');
}
// 无auth退出
if(!$_COOKIE["fr_id_auth"]){
setcookie('fr_access_token','',0,'/');
setcookie('fr_uid','',0,'/');
setcookie('fr_appid','',0,'/');
}
$userInfo = $id_getUserinfo['data'];
$run_json=array(
'code' => 200,
'message' => 'success',
'data' => array(
'avatar' => 'https://bbs.fanruan.com/uc_server/avatar.php?uid='.$id_ckauthinfo['uid'],
'fr_uid' => $id_ckauthinfo['uid'],
'username' => $userInfo['username'],
'regdate' => $userInfo['regdate'],
'position' => $userInfo['position'],
'location' => '',
'signature' => $userInfo['signature'],
'fr_expires_time'=> $id_ckauth['expires_time'],
)
);
echo json_encode($run_json);
?>