[ '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 "

骑手管理API测试

"; // 测试1: 获取骑手列表 echo "

测试1: 获取骑手列表

"; try { $listData = [ 'page' => 1, 'limit' => 10, 'search_name' => '', 'search_phone' => '', 'work_status' => '', 'auth_status' => '' ]; $response = simulatePost($baseUrl . '/getRiderList', $listData); echo "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; } // 测试2: 添加骑手 echo "

测试2: 添加骑手

"; try { $addData = [ 'rider_name' => '测试骑手', 'rider_phone' => '13800138000', 'id_card' => '110101199001011234', 'emergency_contact' => '紧急联系人', 'emergency_phone' => '13900139000' ]; $response = simulatePost($baseUrl . '/addRider', $addData); echo "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; // 保存新添加的骑手ID用于后续测试 $newRiderId = isset($response['rider_id']) ? $response['rider_id'] : null; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; $newRiderId = null; } // 测试3: 获取骑手详情 if ($newRiderId) { echo "

测试3: 获取骑手详情

"; try { $detailData = ['rider_id' => $newRiderId]; $response = simulatePost($baseUrl . '/getRiderDetail', $detailData); echo "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; } } // 测试4: 编辑骑手 if ($newRiderId) { echo "

测试4: 编辑骑手

"; 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 "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; } } // 测试5: 重置密码 if ($newRiderId) { echo "

测试5: 重置密码

"; try { $resetData = [ 'rider_id' => $newRiderId, 'new_password' => '123456789' ]; $response = simulatePost($baseUrl . '/resetPassword', $resetData); echo "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; } } // 测试6: 认证审核 if ($newRiderId) { echo "

测试6: 认证审核

"; try { $authData = [ 'rider_id' => $newRiderId, 'auth_status' => 2, // 认证通过 'review_note' => '认证通过' ]; $response = simulatePost($baseUrl . '/authReview', $authData); echo "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; } } // 测试7: 获取骑手统计数据 echo "

测试7: 获取骑手统计数据

"; try { $response = simulatePost($baseUrl . '/getRiderStats', []); echo "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; } // 测试8: 更新骑手状态 if ($newRiderId) { echo "

测试8: 更新骑手状态

"; try { $statusData = [ 'rider_id' => $newRiderId, 'status' => 2 // 禁用 ]; $response = simulatePost($baseUrl . '/updateStatus', $statusData); echo "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; } } // 测试9: 删除骑手 (软删除) if ($newRiderId) { echo "

测试9: 删除骑手

"; try { $deleteData = ['rider_id' => $newRiderId]; $response = simulatePost($baseUrl . '/deleteRider', $deleteData); echo "
" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "
"; } catch (Exception $e) { echo "

错误: " . $e->getMessage() . "

"; } } echo "

测试完成

"; echo "

所有API接口测试已完成。请检查上述输出结果。

"; ?>