commit 76a59fd05e98b520ff766440ea42ac74bece2cba Author: xiaowei <870653736@qq.com> Date: Wed Feb 23 10:12:42 2022 +0800 add diff --git a/README.md b/README.md new file mode 100644 index 0000000..9df2735 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +文档:前后分离项目用 \ No newline at end of file diff --git a/accesstoken/index.php b/accesstoken/index.php new file mode 100644 index 0000000..5fefcbf --- /dev/null +++ b/accesstoken/index.php @@ -0,0 +1,30 @@ + diff --git a/idapi.php b/idapi.php new file mode 100644 index 0000000..43114e4 --- /dev/null +++ b/idapi.php @@ -0,0 +1,53 @@ + 3600) { + exit('Authracation has expiried'); +} + +header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); + +if($_GET["type"]=='login' && $_GET["code"]){ + $id_user = id_CKdecrypt($_GET["code"]); + $id_userinfo = $id_user['client']; + if(!$id_user['expires_time']){ + exit('err'); + } + set_idcookie('fr_id_auth',$_GET['code'],IDCookieOptions()); + set_idcookie('fr_id_appname',$_GET['appname'],IDCookieOptions()); + + set_idcookie('fr_access_token',$id_user['access_token'],IDCookieOptions()); + set_idcookie('fr_uid',$id_userinfo['uid'],IDCookieOptions()); + set_idcookie('fr_appid',$id_userinfo['appid'],IDCookieOptions()); + set_idcookie('fr_expires_time',$id_user['expires_time'],IDCookieOptions()); + // 登录数字平台接口 + digitLogin($_GET["code"]); +} + +if($_GET["type"]=='logout'){ + set_idcookie('fr_access_token','',IDCookieOptions(0)); + set_idcookie('fr_id_auth','',IDCookieOptions(0)); + set_idcookie('fr_id_appname','',IDCookieOptions(0)); + set_idcookie('fr_id_userinfo','',IDCookieOptions(0)); + set_idcookie('fr_id_addexist_time','',IDCookieOptions(0)); + set_idcookie('fr_expires_time','',IDCookieOptions(0)); +} + +if($_GET["type"]=='userinfo'){ + $id_user = id_CKdecrypt($_COOKIE["fr_id_auth"]); + $id_userinfo = $id_user['client']; + id_user_info($id_userinfo['uid'],$id_userinfo['appid'],$id_user['access_token']); + del_access_token(); +} + +echo 'idapi 3.1'; + + + +?> \ No newline at end of file diff --git a/idapi_Extension_points.php b/idapi_Extension_points.php new file mode 100644 index 0000000..f01f5bc --- /dev/null +++ b/idapi_Extension_points.php @@ -0,0 +1,7 @@ +aes_decrypt($_COOKIE["fr_id_auth"]); + $jsonarr = json_decode($ck_auth,true); + return $jsonarr; + } + + public function getUserinfo(){ + if($_COOKIE['fr_id_auth']){ + if(!$_COOKIE["fr_id_userinfo"]){return false;} + $ck_auth = $this->aes_decrypt($_COOKIE["fr_id_userinfo"]); + $jsonarr = json_decode($ck_auth,true); + return $jsonarr; + }else{ + return false; + } + } + +} \ No newline at end of file diff --git a/idapi_com.php b/idapi_com.php new file mode 100644 index 0000000..fba5530 --- /dev/null +++ b/idapi_com.php @@ -0,0 +1,47 @@ +getAuth(); +$id_ckauthinfo = $id_ckauth['client']; +$id_getUserinfo = $idNewGetuser->getUserinfo(); + + +//获取资料 +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']){ + id_refresh_token(); + id_user_info($id_ckauthinfo['uid'],$id_ckauthinfo['appid'],$id_ckauth['access_token']); +} + +//access_token时效 +if($id_ckauthinfo['uid'] && time() > $id_ckauth['expires_time']){ + id_refresh_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,'/'); + } +} + +?> \ No newline at end of file diff --git a/idapi_config.php b/idapi_config.php new file mode 100644 index 0000000..ae741a8 --- /dev/null +++ b/idapi_config.php @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/idapi_function.php b/idapi_function.php new file mode 100644 index 0000000..64d273c --- /dev/null +++ b/idapi_function.php @@ -0,0 +1,208 @@ + $exptime ? time()+3600*24*14:0, + 'domain' => '', + 'httponly' => false, + 'samesite' => 'None', + 'secure' => true, + 'path' => '/' + ]; + return $Options; +} + + +//idapi 写cookie方式 +function set_idcookie($name, $value, array $options) +{ + setcookie($name,$value,$options['expires'],'/'); + /*if(id_ChromeVer()<79){ + setcookie($name,$value,$options['expires'],'/'); + }else{ + $header = 'Set-Cookie:'; + $header .= rawurlencode($name) . '=' . rawurlencode($value) . ';'; + if (isset($options['expires'])) { + $header .= 'expires=' . \gmdate('D, d-M-Y H:i:s T', $options['expires']) . ';'; + } + if (isset($options['expires'])) { + $header .= 'Max-Age=' . max(0, (int) ($options['expires'] - time())) . ';'; + } + if (!empty($options['path'])) { + $header .= 'path=' . $options['path']. ';'; + } + if (!empty($options['domain'])) { + $header .= 'domain=' . rawurlencode($options['domain']) . ';'; + } + if (!empty($options['secure'])) { + $header .= 'Secure;'; + } + if (!empty($options['httponly'])) { + $header .= 'HttpOnly;'; + } + if (!empty($options['samesite'])) { + $header .= 'SameSite=' . rawurlencode($options['samesite']); + } + header($header, false); + } */ +} + + + +//Chrome版本 +function id_ChromeVer(){ + if (empty($_SERVER['HTTP_USER_AGENT'])){ + return 'unknow'; + } + $agent= $_SERVER['HTTP_USER_AGENT']; + if (preg_match('/Chrome\/(\d+)\..*/i', $agent, $regs)){ + return $regs[1]; + } + else{ + return 'unknow'; + } +} + + +?> \ No newline at end of file diff --git a/idapi_logout.php b/idapi_logout.php new file mode 100644 index 0000000..943a31b --- /dev/null +++ b/idapi_logout.php @@ -0,0 +1,29 @@ +'; + +/*require 'idapi_config.php'; +require 'idapi_function.php'; + + + + +//获取应用列表 +$idaaps_curl_get = CallInterface(ID_URL.'/idapi/idapps.php','GET'); +$apps_jsonarr = json_decode($idaaps_curl_get,true); +//遍历各应用退出 +foreach($apps_jsonarr as $appid => $app) { + if($app['isopen']==1){ + echo ''; + } +} + + +*/ + +?> \ No newline at end of file diff --git a/refreshtoken/index.php b/refreshtoken/index.php new file mode 100644 index 0000000..8bf2b43 --- /dev/null +++ b/refreshtoken/index.php @@ -0,0 +1,52 @@ + + diff --git a/sid/index.php b/sid/index.php new file mode 100644 index 0000000..e2f9fd5 --- /dev/null +++ b/sid/index.php @@ -0,0 +1,30 @@ + + diff --git a/token/index.php b/token/index.php new file mode 100644 index 0000000..784fa3b --- /dev/null +++ b/token/index.php @@ -0,0 +1,69 @@ +getAuth(); +$id_ckauthinfo = $id_ckauth['client']; + + +//刷新access_token +if($id_ckauthinfo['uid'] && time() > $id_ckauth['expires_time']){ + + $id_ckuser = id_CKdecrypt($get_cookie); + $id_ckuserinfo = $id_ckuser['client']; + $data = '&appid='.$id_ckuserinfo['appid'].'&uid='.$id_ckuserinfo['uid'].'&refresh_token='.$id_ckuser['refresh_token']; + $re_login = CallInterface(API_URL.'/v1/token/refresh/'.$data,'GET'); + $jsonarr = json_decode($re_login,true); + if($jsonarr['message']=='success'){ + $new_json = json_encode($jsonarr['data'],JSON_UNESCAPED_UNICODE); + $u_data = id_aes_encrypt($new_json, API_KEY); + header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); + setcookie('fr_id_auth',$u_data,time()+3600*24*14,'/'); + }else{ + setcookie('fr_id_auth','',0,'/'); + } + + $str['code']=200; + $str['message']='success'; + $str['data']['access_token'] = $jsonarr['data']['access_token']; + $str['data']['appid'] = $jsonarr['data']['client']['appid']; + $str['data']['uid'] = $jsonarr['data']['client']['uid']; + $str['data']['ref'] = 1; + + $return_json = json_encode($str); + echo $return_json; +}else{ + $run_json = array ( + 'access_token' => $id_ckauth['access_token'], + 'appid' => $id_ckauthinfo['appid'], + 'uid' => $id_ckauth['client']['uid'], + ); + echo json_encode($run_json); + +} + + + +?> + diff --git a/userinfo/index.php b/userinfo/index.php new file mode 100644 index 0000000..88a5442 --- /dev/null +++ b/userinfo/index.php @@ -0,0 +1,77 @@ +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); + + + + +?> +