This commit is contained in:
Your Name
2026-04-07 18:13:03 +08:00
parent a780356908
commit fdf714f833
397 changed files with 15086 additions and 1043 deletions
+90
View File
@@ -0,0 +1,90 @@
<?php
/**
* 测试快递100自动识别功能
*/
// 从 .env 读取配置
$envFile = __DIR__ . '/.env';
$envContent = file_get_contents($envFile);
$lines = explode("\n", $envContent);
$config = [];
foreach ($lines as $line) {
$line = trim($line);
if (empty($line) || $line[0] === '#' || $line[0] === ';' || $line[0] === '[') {
continue;
}
if (strpos($line, '=') !== false) {
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value);
$value = trim($value, '"\'');
$config[$key] = $value;
}
}
$customer = $config['LOGISTICS_KUAIDI100_CUSTOMER'] ?? '';
$key = $config['LOGISTICS_KUAIDI100_KEY'] ?? '';
echo "===========================================\n";
echo "快递100 自动识别测试\n";
echo "===========================================\n\n";
$testNumber = 'JD0230761381812';
echo "测试单号: {$testNumber}\n";
echo "使用自动识别(com=auto\n\n";
$paramArr = [
'com' => 'auto',
'num' => $testNumber,
'resultv2' => '1',
];
$paramJson = json_encode($paramArr, JSON_UNESCAPED_UNICODE);
$sign = strtoupper(md5($paramJson . $key . $customer));
$postBody = http_build_query([
'customer' => $customer,
'param' => $paramJson,
'sign' => $sign,
]);
$url = 'https://poll.kuaidi100.com/poll/query.do';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded',
]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
curl_close($ch);
echo "响应:\n";
echo $response . "\n\n";
$json = json_decode($response, true);
if (is_array($json)) {
echo "解析:\n";
echo " result: " . var_export($json['result'] ?? null, true) . "\n";
echo " message: " . ($json['message'] ?? 'N/A') . "\n";
echo " returnCode: " . ($json['returnCode'] ?? 'N/A') . "\n";
if (isset($json['data']) && is_array($json['data']) && count($json['data']) > 0) {
echo " 轨迹数量: " . count($json['data']) . "\n";
echo "\n最新3条轨迹:\n";
for ($i = 0; $i < min(3, count($json['data'])); $i++) {
$trace = $json['data'][$i];
echo " " . ($i + 1) . ". " . ($trace['ftime'] ?? $trace['time'] ?? '') . " - " . ($trace['context'] ?? '') . "\n";
}
}
}
echo "\n===========================================\n";