43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
/**
|
||
* 生成 /api/v1/authToken(或 /api/v1/authtoken)所需 signature
|
||
*
|
||
* 用法:
|
||
* php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret
|
||
* php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret --time=1713772800
|
||
*/
|
||
|
||
$options = getopt('', ['agent_id:', 'secret:', 'time::']);
|
||
|
||
$agentId = $options['agent_id'] ?? '76dc611d6ebaafc66cc0879c71b5db5c';
|
||
$secret = $options['secret'] ?? 'xF75oK91TQj13s0UmNIr1NBWMWGfflNO';
|
||
$time = $options['time'] ?? (string) time();
|
||
|
||
if ($agentId === '' || $secret === '' || $time === '') {
|
||
echo "缺少参数。\n";
|
||
echo "用法: php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret [--time=unix_timestamp]\n";
|
||
exit(1);
|
||
}
|
||
|
||
if (ctype_digit($time) === false) {
|
||
echo "time 必须是 unix 时间戳(纯数字字符串)。\n";
|
||
exit(1);
|
||
}
|
||
|
||
$signature = md5($agentId . $secret . $time);
|
||
$query = http_build_query([
|
||
'agent_id' => $agentId,
|
||
'secret' => $secret,
|
||
'time' => $time,
|
||
'signature' => $signature,
|
||
]);
|
||
|
||
echo "agent_id: {$agentId}\n";
|
||
echo "secret: {$secret}\n";
|
||
echo "time: {$time}\n";
|
||
echo "signature: {$signature}\n";
|
||
echo "query: {$query}\n";
|
||
|