'京东快递', 'com' => 'jingdong', // 修正为正确的编码 'num' => 'JD0230761381812', 'phone' => '' ], [ 'name' => '极兔速递', 'com' => 'jtexpress', 'num' => 'JT5472795424064', 'phone' => '' ], ]; foreach ($testCases as $test) { echo "测试: {$test['name']}\n"; echo "-------------------------------------------\n"; echo "快递公司编码: {$test['com']}\n"; echo "运单号: {$test['num']}\n\n"; $paramArr = [ 'com' => $test['com'], 'num' => $test['num'], 'resultv2' => '1', ]; if ($test['phone'] !== '') { $paramArr['phone'] = $test['phone']; } $paramJson = json_encode($paramArr, JSON_UNESCAPED_UNICODE); $sign = strtoupper(md5($paramJson . $key . $customer)); $postBody = http_build_query([ 'customer' => $customer, 'param' => $paramJson, 'sign' => $sign, ]); echo "请求参数:\n"; echo " customer: " . substr($customer, 0, 8) . "****\n"; echo " param: {$paramJson}\n"; echo " sign: " . substr($sign, 0, 16) . "****\n\n"; // 发送请求 $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); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); echo "HTTP状态码: {$httpCode}\n"; if ($error) { echo "CURL错误: {$error}\n\n"; continue; } if ($response === false || $response === '') { echo "错误: 无响应\n\n"; continue; } echo "原始响应:\n"; echo $response . "\n\n"; $json = json_decode($response, true); if (!is_array($json)) { echo "错误: 无法解析JSON\n\n"; continue; } 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'])) { echo " data: " . count($json['data']) . " 条轨迹记录\n"; if (count($json['data']) > 0) { echo "\n 最新轨迹:\n"; $latest = $json['data'][0]; echo " 时间: " . ($latest['ftime'] ?? $latest['time'] ?? 'N/A') . "\n"; echo " 内容: " . ($latest['context'] ?? 'N/A') . "\n"; } } else { echo " data: 无数据\n"; } echo "\n"; } echo "===========================================\n"; echo "调试完成\n"; echo "===========================================\n\n"; echo "常见错误码说明:\n"; echo "-------------------------------------------\n"; echo "200: 查询成功\n"; echo "500: 服务器错误\n"; echo "501: 重复提交\n"; echo "600: 您不是合法的订阅者\n"; echo "601: SIGN签名错误\n"; echo "700: 订阅方的订阅数据已达到上限\n"; echo "701: 快递公司参数异常\n"; echo "702: 快递单号参数异常\n"; echo "703: 查询无结果\n"; echo "704: 快递公司识别失败\n\n"; echo "如果返回 '找不到对应公司',可能原因:\n"; echo "1. 快递公司编码错误(如:jd 应该是 jingdong)\n"; echo "2. 快递100不支持该快递公司\n"; echo "3. 需要使用快递100的自动识别功能\n\n";