php
<?php
// 定数定義
$accessKey = "a1";
$secretKey = "a2";
$apiURL = "https://api.upgrade.toolsetlink.com/v1/url/upgrade";
$uri = "/v1/url/upgrade";
// RFC3339 形式の時間を生成する関数
function generate_rfc3339_time() {
$base_time = date("Y-m-d\TH:i:s");
return $base_time . "+08:00";
}
// 1. リクエストボディを構築
$requestBody = '{
"urlKey": "key1",
"versionCode": 1,
"appointVersionCode": 0,
"devModelKey": "12312",
"devKey": "12312"
}';
// 2. リクエストパラメータを生成
$timestamp = generate_rfc3339_time();
echo "生成された RFC3339 形式の時間: $timestamp\n";
$nonce = bin2hex(random_bytes(8));
// 3. 署名を生成
$signStr = "body=$requestBody&nonce=$nonce&secretKey=$secretKey×tamp=$timestamp&url=$uri";
$signature = md5($signStr);
// 4. タイムスタンプを出力
echo "timestamp: $timestamp\n";
// 5. HTTP リクエストを送信
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"X-Timestamp: $timestamp",
"X-Nonce: $nonce",
"X-AccessKey: $accessKey",
"X-Signature: $signature",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
// 6. レスポンスステータスコードを取得
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// 7. レスポンスを処理
echo "Status Code: $statusCode\n";
echo "Response: $response\n";