一站式网上办事大厅
<?php
// 定义一个基础的Web服务接口类
class WebService {
public function getStudentInfo($studentID) {
// 假设这里有一个数据库连接
$db = new PDO('mysql:host=localhost;dbname=university', 'root', 'password');
$stmt = $db->prepare("SELECT * FROM students WHERE id = :id");
$stmt->execute(['id' => $studentID]);
return $stmt->fetch();
}
}
class OneStopService {
private $webService;
public function __construct(WebService $webService) {
$this->webService = $webService;
}
public function processRequest($request) {
$response = [];

foreach ($request as $item) {
$response[] = $this->webService->getStudentInfo($item);
}
return $response;
}
}
// 使用示例
$webService = new WebService();
$oneStopService = new OneStopService($webService);
$requests = [1, 2, 3];
$responses = $oneStopService->processRequest($requests);
print_r($responses);
?>