Files
dafuweng-saiadmin6.x/server/scripts/gen_auth_token_signature.php
2026-05-13 09:47:25 +08:00

43 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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'] ?? '5ef059938ba799aaa845e1c2e8a762bd';
$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";