178 行
6.3 KiB
PHP
178 行
6.3 KiB
PHP
<?php
|
|
/**
|
|
* 测试骑手信息获取接口
|
|
* 测试 Retail/Rider/getRiderInfo 接口
|
|
*/
|
|
|
|
// 设置测试参数
|
|
$base_url = 'http://localhost/mss.nahaichuan.com';
|
|
$test_rider_id = 1; // 测试用的骑手ID
|
|
|
|
echo "<h2>骑手信息获取接口测试</h2>\n";
|
|
echo "<hr>\n";
|
|
|
|
/**
|
|
* 测试获取骑手信息接口
|
|
*/
|
|
function testGetRiderInfo($base_url, $rider_id) {
|
|
$url = $base_url . '/index.php/Retail/Rider/getRiderInfo?id=' . $rider_id;
|
|
|
|
echo "<h3>测试获取骑手信息 (ID: $rider_id)</h3>\n";
|
|
echo "请求URL: $url<br>\n";
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
'Content-Type: application/json',
|
|
'User-Agent: Test-Client/1.0'
|
|
]);
|
|
|
|
$response = curl_exec($ch);
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$error = curl_error($ch);
|
|
curl_close($ch);
|
|
|
|
if ($error) {
|
|
echo "<span style='color: red;'>CURL错误: $error</span><br>\n";
|
|
return false;
|
|
}
|
|
|
|
echo "HTTP状态码: $http_code<br>\n";
|
|
|
|
if ($http_code == 200) {
|
|
$data = json_decode($response, true);
|
|
if ($data) {
|
|
echo "<span style='color: green;'>✓ 接口调用成功</span><br>\n";
|
|
echo "<strong>返回数据:</strong><br>\n";
|
|
echo "<pre>" . json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>\n";
|
|
|
|
// 验证返回数据结构
|
|
if (isset($data['status']) && isset($data['msg']) && isset($data['data'])) {
|
|
echo "<span style='color: green;'>✓ 数据结构正确</span><br>\n";
|
|
|
|
if ($data['status'] == 1 && !empty($data['data'])) {
|
|
echo "<span style='color: green;'>✓ 骑手信息获取成功</span><br>\n";
|
|
|
|
// 检查关键字段
|
|
$rider = $data['data'];
|
|
$required_fields = ['id', 'rider_name', 'rider_phone', 'work_status', 'auth_status'];
|
|
$missing_fields = [];
|
|
|
|
foreach ($required_fields as $field) {
|
|
if (!isset($rider[$field])) {
|
|
$missing_fields[] = $field;
|
|
}
|
|
}
|
|
|
|
if (empty($missing_fields)) {
|
|
echo "<span style='color: green;'>✓ 必要字段完整</span><br>\n";
|
|
} else {
|
|
echo "<span style='color: orange;'>⚠ 缺少字段: " . implode(', ', $missing_fields) . "</span><br>\n";
|
|
}
|
|
|
|
// 检查格式化字段
|
|
$formatted_fields = ['work_status_text', 'auth_status_text', 'status_text'];
|
|
$has_formatted = [];
|
|
|
|
foreach ($formatted_fields as $field) {
|
|
if (isset($rider[$field])) {
|
|
$has_formatted[] = $field;
|
|
}
|
|
}
|
|
|
|
if (!empty($has_formatted)) {
|
|
echo "<span style='color: green;'>✓ 包含格式化字段: " . implode(', ', $has_formatted) . "</span><br>\n";
|
|
}
|
|
|
|
} else {
|
|
echo "<span style='color: red;'>✗ 获取骑手信息失败: " . $data['msg'] . "</span><br>\n";
|
|
}
|
|
} else {
|
|
echo "<span style='color: red;'>✗ 返回数据结构不正确</span><br>\n";
|
|
}
|
|
} else {
|
|
echo "<span style='color: red;'>✗ JSON解析失败</span><br>\n";
|
|
echo "原始响应: " . htmlspecialchars($response) . "<br>\n";
|
|
}
|
|
} else {
|
|
echo "<span style='color: red;'>✗ HTTP请求失败</span><br>\n";
|
|
echo "响应内容: " . htmlspecialchars($response) . "<br>\n";
|
|
}
|
|
|
|
echo "<hr>\n";
|
|
return $http_code == 200;
|
|
}
|
|
|
|
/**
|
|
* 测试无效参数
|
|
*/
|
|
function testInvalidParams($base_url) {
|
|
echo "<h3>测试无效参数</h3>\n";
|
|
|
|
// 测试无ID参数
|
|
$url = $base_url . '/index.php/Retail/Rider/getRiderInfo';
|
|
echo "测试无ID参数: $url<br>\n";
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
|
|
$response = curl_exec($ch);
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($http_code == 200) {
|
|
$data = json_decode($response, true);
|
|
if ($data && isset($data['status']) && $data['status'] == 0) {
|
|
echo "<span style='color: green;'>✓ 正确处理无效参数</span><br>\n";
|
|
} else {
|
|
echo "<span style='color: red;'>✗ 未正确处理无效参数</span><br>\n";
|
|
}
|
|
}
|
|
|
|
// 测试不存在的ID
|
|
$url = $base_url . '/index.php/Retail/Rider/getRiderInfo?id=99999';
|
|
echo "测试不存在的ID: $url<br>\n";
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
|
|
$response = curl_exec($ch);
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($http_code == 200) {
|
|
$data = json_decode($response, true);
|
|
if ($data && isset($data['status']) && $data['status'] == 0) {
|
|
echo "<span style='color: green;'>✓ 正确处理不存在的骑手ID</span><br>\n";
|
|
} else {
|
|
echo "<span style='color: red;'>✗ 未正确处理不存在的骑手ID</span><br>\n";
|
|
}
|
|
}
|
|
|
|
echo "<hr>\n";
|
|
}
|
|
|
|
// 执行测试
|
|
echo "<p><strong>开始测试骑手信息获取接口...</strong></p>\n";
|
|
|
|
// 测试正常获取骑手信息
|
|
testGetRiderInfo($base_url, $test_rider_id);
|
|
|
|
// 测试无效参数
|
|
testInvalidParams($base_url);
|
|
|
|
echo "<p><strong>测试完成!</strong></p>\n";
|
|
echo "<p><em>注意:如果测试失败,请检查:</em></p>\n";
|
|
echo "<ul>\n";
|
|
echo "<li>数据库中是否存在ID为 $test_rider_id 的骑手记录</li>\n";
|
|
echo "<li>数据库连接是否正常</li>\n";
|
|
echo "<li>RiderModel 和 ImageGalleryModel 是否正确加载</li>\n";
|
|
echo "<li>权限设置是否正确</li>\n";
|
|
echo "</ul>\n";
|
|
?>
|