a4667007 by Yokihito Oki

2020-11-12 まとめ

1 parent 36886d7f
{"hash":"79e2df35bd0c42235cbe191d12011b0d"}
\ No newline at end of file
{"hash":"360be1890c5847863fce614473b73e8d"}
\ No newline at end of file
No preview for this file type
<?php
$url = "https://api.researchmap.jp/SNI/education";
// $url = "https://api.researchmap.jp/erad_id:20724818/published_papers";
// $url = "https://api.researchmap.jp/20724818/profile";
$token = "3bd6cbdc59adfbecd96bdb759b7d32e310cfba7e";
$header = array(
"Authorization: Bearer $token",
"Accept: application/ld+json,application/json;q=0.1",
"Accept-Encoding: gzip",
"Content-Type: application/json;"
);
$curl = curl_init($url);
// curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
// curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie');
curl_setopt($curl, CURLOPT_COOKIEFILE, 'tmp');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
$api_responese = curl_exec($curl);
header('Content-Type: application/json; charset=utf8');
header('Access-Control-Allow-Origin: *');
echo $api_responese;
?>
<?php
declare(strict_types=1);
use \Firebase\JWT\JWT;
require __DIR__ . '/vendor/autoload.php';
// .storeフォルダにアクセストークン、エラーログを出力する
// .storeの権限を設定する必要あり(apache or www-data)
$store_folder = "/var/www/.store/";
// 研究者番号
$erad_id = null;
if (array_key_exists('erad_id', $_GET)){
$erad_id = $_GET['erad_id'];
}
if (is_null($erad_id)) {
header('Content-Type: application/json; charset=utf8');
header('Access-Control-Allow-Origin: https://www.nifs-k.ac.jp');
print(json_encode([], JSON_FORCE_OBJECT));
exit;
}
$type = $_GET["type"];
$start = $_GET["start"];
$limit = 1000;
function api_request (string $url, array $header, string $method, ?array $post_params = null) {
global $store_folder;
$curl = curl_init($url);
$setopt_array = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $header,
];
$post_fields = '';
if (is_null($post_params) === false) {
$post_fields = http_build_query($post_params);
$setopt_array[CURLOPT_POSTFIELDS] = $post_fields;
}
curl_setopt_array($curl, $setopt_array);
$api_responese = curl_exec($curl);
if ($api_responese === false) {
// 失敗
$errno = curl_errno($curl);
$error = curl_error($curl);
$ymd = date('Ymd');
$file = $store_folder . "error_{$ymd}.txt";
$error_message = '[' . date('Y-m-d H:i:s') . ']'
. 'ErrorNo:' . $errno . "\n"
. 'Error:' . $error . "\n"
. 'URL:' . $url . "\n"
. 'Method:' . $method . "\n"
. 'header:' . print_r($header, true) . "\n"
. 'post_fields:' . $post_fields . "\n";
file_put_contents($file, $error_message, FILE_APPEND | LOCK_EX);
}
// ステータスコード取得
$http_status_code = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
if (($http_status_code < 200) || ($http_status_code >= 300)) {
$ymd = date('Ymd');
$file = $store_folder . "error_{$ymd}.txt";
$error_message = '[' . date('Y-m-d H:i:s') . ']'
. 'HTTP Status Code:' . $http_status_code . "\n"
. 'response:' . $api_responese . "\n"
. 'URL:' . $url . "\n"
. 'Method:' . $method . "\n"
. 'header:' . print_r($header, true) . "\n"
. 'post_fields:' . $post_fields . "\n";
file_put_contents($file, $error_message, FILE_APPEND | LOCK_EX);
return false;
}
return $api_responese;
}
// アクセストークン
$access_token = null;
// 保存している情報からアクセストークン取得
$access_token_file = $store_folder . "access_token.txt";
if (file_exists($access_token_file)) {
$access_token_text = file_get_contents($access_token_file);
$access_token_json = json_decode($access_token_text, true);
if (is_null($access_token_json) === false) {
$expire = $access_token_json['expire'];
$expiration = (new DateTime())->format('U');
// 有効期限確認
if ($expiration < $expire) {
$access_token = $access_token_json['access_token'];
}
}
}
if (is_null($access_token)) {
// トークン取得URL
$url = 'https://api.researchmap.jp/oauth2/token';
// キー取得
$client_key = file_get_contents('/var/www/.rmap_keys/rmap_client_id.key');
$client_key = rtrim($client_key);
$private_key = file_get_contents('/var/www/.rmap_keys/rmap_jwt_private.key');
// JWTの発行時間と有効期限を設定
$date_time = new DateTime(date('Y-m-d H:i:s'));
$date_time->setTimezone(new DateTimeZone('UTC'));
// JWTの発行時間
$iat = $date_time->format('U');
// JWTの有効期限
$expiration = $date_time->modify('+30 minutes')->format('U');
$claim = [
'iss' => $client_key,
'aud' => $url,
'sub' => "0",
'exp' => $expiration,
'iat' => $iat
];
$jwt = JWT::encode($claim, $private_key, 'RS256');
$post_params = [
"grant_type" => "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion" => $jwt,
"version" => "2"
];
$header = [
"Content-Type: application/x-www-form-urlencoded;"
];
$api_responese = api_request($url, $header, 'POST', $post_params);
if ($api_responese) {
$response = json_decode($api_responese, true);
$access_token = $response['access_token'];
$response['expire'] = $expiration;
file_put_contents($access_token_file, json_encode($response));
}
}
// プロフィール情報取得
$profile = [];
if (is_null($access_token) === false) {
$url = "https://api.researchmap.jp/erad_id:{$erad_id}";
if (!empty($type)) {
$url = $url . '/' . $type . '?limit=' . $limit;
};
if (!empty($start)) {
$url = $url . '&start=' . $start;
}
$header = array(
"Authorization: Bearer $access_token",
"Accept: application/ld+json,application/json;q=0.1",
"Accept-Encoding: gzip",
// "X-HTTP-Method-Override: GET",
// "Content-Type: application/json;"
// "Content-Type: application/x-www-form-urlencoded;"
);
$api_responese = api_request($url, $header, 'GET', null);
if ($api_responese) {
$profile = json_decode($api_responese, true);
}
}
header('Content-Type: application/json; charset=utf8');
header('Access-Control-Allow-Origin: https://www.nifs-k.ac.jp');
print(json_encode($profile, JSON_FORCE_OBJECT));
<?php
require_once('./vendor/autoload.php');
use \Firebase\JWT\JWT;
$url = 'https://api.researchmap.jp/oauth2/token';
$client_key = file_get_contents('/var/www/.rmap_keys/rmap_client_id.key');
$client_key = rtrim($client_key);
$private_key = file_get_contents('/var/www/.rmap_keys/rmap_jwt_private.key');
# 時刻
$now = time();
$hour = date('H', $now);
$min = date('m', $now);
$sec = date('s', $now);
$year = date('Y', $now);
$month = date('m', $now);
$day = date('d', $now);
$date = mktime($hour, $min, $sec, $month, $day, $year);
$expiration = mktime(0, 0, 0, $month, $day+1, $year);
$claim = Array(
'iss' => $client_key,
'aud' => $url,
'sub' => "0",
'exp' => $expiration,
'iat' => $date
);
$jwt = JWT::encode($claim, $private_key, 'RS256');
$data = Array(
"grant_type" => "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion" => $jwt,
// "scope" => "researchers write",
"version" => "2"
);
$header = array(
"Content-Type: application/x-www-form-urlencoded;"
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie');
curl_setopt($curl, CURLOPT_COOKIEFILE, 'tmp');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
$api_responese = curl_exec($curl);
header('Content-Type: application/json; charset=utf8');
header('Access-Control-Allow-Origin: *');
echo $api_responese;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
</head>
<body>
</body>
<script>
const tokenUrl = 'https://www.nifs-k.ac.jp/rmap/getToken.php';
let rmToken = JSON.parse(localStorage.getItem('rmToken'));
// トークン未取得 or 有効期限切れ
if (!rmToken) {
getToken();
} else {
const expDate = new Date(rmToken.exp);
const now = new Date();
if (expDate > now) {
getToken();
} else {
console.log(rmToken);
}
}
function getToken() {
$.ajax({
type: 'GET',
url: tokenUrl,
dataType: 'json',
headers: {
// 'Authorization': `Bearer ${token}`,
// 'Accept': 'application/ld+json,application/json;q=0.1',
// 'Accept-Encoding': 'gzip',
'Content-Type': 'application/json;'
},
success: function (data) {
const now = new Date();
const exp = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes() + 55);
rmToken = {
token: data.access_token,
exp: exp
};
localStorage.setItem('rmToken', JSON.stringify(rmToken));
console.log(rmToken);
}
});
}
</script>
</html>
\ No newline at end of file
......@@ -608,6 +608,7 @@ if ($this->params->get('logoFile')) {
<li><a href="/outline/feel-approach-program/sports-performance.html" title="スポーツパフォーマンス研究">スポーツパフォーマンス研究</a></li>
<li><a href="/outline/feel-approach-program/nifisa.html" title="スポーツ・アカデミー形成支援事業">スポーツ・アカデミー形成支援事業</a></li>
<li><a href="/outline/feel-approach-program/ap-program.html" title="大学教育加速プログラム">大学教育加速プログラム</a></li>
<li><a href="/outline/feel-approach-program/discretion/discretion.html" title="重点プロジェクト事業経費(学長裁量経費)">重点プロジェクト事業経費<br>(学長裁量経費)</a></li>
<li><a href="/outline/feel-approach-program/past-efforts.html" title="過去の取組">過去の取組</a></li>
</ul>
<div class="title"><a href="public/bid.html">入札情報等</a></div>
......@@ -821,6 +822,10 @@ if ($this->params->get('logoFile')) {
<li><a href="/faculties/thesis/exam.html" title="論文博士の論文提出に係る外国語試験の実施について">論文博士の論文提出に係る外国語試験の実施について</a></li>
<li><a href="/faculties/thesis/degrees.html" title="論文博士の学位論文について">論文博士の学位論文について</a></li>
</ul>
<div class="title"><a href="/faculties/questionnaire.html">大学教育の満足度アンケート調査結果</a></div>
<ul>
<li><a href="/faculties/questionnaire/questionnaire.html" title="アンケート調査結果">アンケート調査結果</a></li>
</ul>
</div>
<!-- ▲4列目 -->
......@@ -1040,6 +1045,7 @@ if ($this->params->get('logoFile')) {
<div class="title"><a href="/property/ssc.html">スポーツサイエンスキャンプ</a></div>
<div class="title"><a href="/property/tokyo-satellite-campus.html">東京サテライトキャンパス</a></div>
<div class="title"><a href="property/workshop.html">教員免許状更新講習プログラム 詳細</a></div>
<div class="title"><a href="/property/open-project.html">大学開放事業</a></div>
<!-- ▲4列目 -->
</div>
......
......@@ -2213,7 +2213,7 @@ body.itemid-101 #c_wrap {
/* ▼スマホで横長テーブルが切れるのを回避する */
.scroll {
overflow: auto;
/*white-space: nowrap;*/
white-space: nowrap;
}
.scroll::-webkit-scrollbar{  /*tableにスクロールバーを追加*/
height: 5px;
......
......@@ -47,7 +47,7 @@ JHtml::_('script', 'template.js', array('version' => 'auto', 'relative' => true)
JHtml::_('script', 'jui/html5.js', array('version' => 'auto', 'relative' => true, 'conditional' => 'lt IE 9'));
// Add Stylesheets
JHtml::_('stylesheet', 'template.css', array('version' => '20200625001', 'relative' => true));
JHtml::_('stylesheet', 'template.css', array('version' => '20201104001', 'relative' => true));
// Use of Google Font
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!