39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
function sign_message($data) {
|
|
$timestamp = time();
|
|
$nonce = generate_random_string(64); // 生成一个六位随机数,包含大小写字母和数字
|
|
$message = "$timestamp|$nonce|" . json_encode($data);
|
|
$key = 'qZ6v1&H#Wjx+yRm2D@*sJF$tnfL83Ia';
|
|
$signature = hash_hmac('sha256', $message, $key);
|
|
$signed_message = array(
|
|
'TaskData' => $data,
|
|
'signature' => array(
|
|
'signature' => $signature,
|
|
'timestamp' => $timestamp,
|
|
'nonce' => $nonce
|
|
)
|
|
);
|
|
return json_encode($signed_message);
|
|
}
|
|
|
|
function generate_random_string($length) {
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()_-+=';
|
|
$random_string = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$index = mt_rand(0, strlen($characters) - 1);
|
|
$random_string .= $characters[$index];
|
|
}
|
|
return $random_string;
|
|
}
|
|
|
|
$data = array(
|
|
"command" => "lastCall",
|
|
"excluded_filename" => "lastCall.txt",
|
|
"batch_filename" => "Communication_definition_SMS_1_wemedia_20230303185518.txt",
|
|
"data_filename" => "Communication_targets_SMS_1_wemedia_20230303185518.txt"
|
|
);
|
|
|
|
echo sign_message($data);
|
|
|