176 行
5.6 KiB
PHP
176 行
5.6 KiB
PHP
<?php
|
|
/**
|
|
* 骑手管理API测试脚本
|
|
* 用于测试RiderController的各个接口
|
|
*/
|
|
|
|
// 设置错误报告
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
// 模拟POST请求函数
|
|
function simulatePost($url, $data) {
|
|
$postData = http_build_query($data);
|
|
|
|
$context = stream_context_create([
|
|
'http' => [
|
|
'method' => 'POST',
|
|
'header' => 'Content-type: application/x-www-form-urlencoded',
|
|
'content' => $postData
|
|
]
|
|
]);
|
|
|
|
$result = file_get_contents($url, false, $context);
|
|
return json_decode($result, true);
|
|
}
|
|
|
|
// 测试基础URL
|
|
$baseUrl = 'http://localhost:8080/Application/Retail/Controller/RiderController.class.php';
|
|
|
|
echo "<h1>骑手管理API测试</h1>";
|
|
|
|
// 测试1: 获取骑手列表
|
|
echo "<h2>测试1: 获取骑手列表</h2>";
|
|
try {
|
|
$listData = [
|
|
'page' => 1,
|
|
'limit' => 10,
|
|
'search_name' => '',
|
|
'search_phone' => '',
|
|
'work_status' => '',
|
|
'auth_status' => ''
|
|
];
|
|
|
|
$response = simulatePost($baseUrl . '/getRiderList', $listData);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
}
|
|
|
|
// 测试2: 添加骑手
|
|
echo "<h2>测试2: 添加骑手</h2>";
|
|
try {
|
|
$addData = [
|
|
'rider_name' => '测试骑手',
|
|
'rider_phone' => '13800138000',
|
|
'id_card' => '110101199001011234',
|
|
'emergency_contact' => '紧急联系人',
|
|
'emergency_phone' => '13900139000'
|
|
];
|
|
|
|
$response = simulatePost($baseUrl . '/addRider', $addData);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
|
|
// 保存新添加的骑手ID用于后续测试
|
|
$newRiderId = isset($response['rider_id']) ? $response['rider_id'] : null;
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
$newRiderId = null;
|
|
}
|
|
|
|
// 测试3: 获取骑手详情
|
|
if ($newRiderId) {
|
|
echo "<h2>测试3: 获取骑手详情</h2>";
|
|
try {
|
|
$detailData = ['rider_id' => $newRiderId];
|
|
$response = simulatePost($baseUrl . '/getRiderDetail', $detailData);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
}
|
|
}
|
|
|
|
// 测试4: 编辑骑手
|
|
if ($newRiderId) {
|
|
echo "<h2>测试4: 编辑骑手</h2>";
|
|
try {
|
|
$editData = [
|
|
'rider_id' => $newRiderId,
|
|
'rider_name' => '测试骑手(已编辑)',
|
|
'rider_phone' => '13800138000',
|
|
'id_card' => '110101199001011234',
|
|
'emergency_contact' => '紧急联系人(已编辑)',
|
|
'emergency_phone' => '13900139000',
|
|
'work_status' => 1
|
|
];
|
|
|
|
$response = simulatePost($baseUrl . '/editRider', $editData);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
}
|
|
}
|
|
|
|
// 测试5: 重置密码
|
|
if ($newRiderId) {
|
|
echo "<h2>测试5: 重置密码</h2>";
|
|
try {
|
|
$resetData = [
|
|
'rider_id' => $newRiderId,
|
|
'new_password' => '123456789'
|
|
];
|
|
|
|
$response = simulatePost($baseUrl . '/resetPassword', $resetData);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
}
|
|
}
|
|
|
|
// 测试6: 认证审核
|
|
if ($newRiderId) {
|
|
echo "<h2>测试6: 认证审核</h2>";
|
|
try {
|
|
$authData = [
|
|
'rider_id' => $newRiderId,
|
|
'auth_status' => 2, // 认证通过
|
|
'review_note' => '认证通过'
|
|
];
|
|
|
|
$response = simulatePost($baseUrl . '/authReview', $authData);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
}
|
|
}
|
|
|
|
// 测试7: 获取骑手统计数据
|
|
echo "<h2>测试7: 获取骑手统计数据</h2>";
|
|
try {
|
|
$response = simulatePost($baseUrl . '/getRiderStats', []);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
}
|
|
|
|
// 测试8: 更新骑手状态
|
|
if ($newRiderId) {
|
|
echo "<h2>测试8: 更新骑手状态</h2>";
|
|
try {
|
|
$statusData = [
|
|
'rider_id' => $newRiderId,
|
|
'status' => 2 // 禁用
|
|
];
|
|
|
|
$response = simulatePost($baseUrl . '/updateStatus', $statusData);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
}
|
|
}
|
|
|
|
// 测试9: 删除骑手 (软删除)
|
|
if ($newRiderId) {
|
|
echo "<h2>测试9: 删除骑手</h2>";
|
|
try {
|
|
$deleteData = ['rider_id' => $newRiderId];
|
|
$response = simulatePost($baseUrl . '/deleteRider', $deleteData);
|
|
echo "<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
} catch (Exception $e) {
|
|
echo "<p style='color: red;'>错误: " . $e->getMessage() . "</p>";
|
|
}
|
|
}
|
|
|
|
echo "<h2>测试完成</h2>";
|
|
echo "<p>所有API接口测试已完成。请检查上述输出结果。</p>";
|
|
?>
|