Skip to content

Commit 36115dc

Browse files
committed
fix(repo): 公交新版本-获取线路列表
1 parent f110d35 commit 36115dc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

laravel/app/Http/Repository/BusRepository.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,51 @@ public function getList($line, $refresh = false)
216216
return $listData;
217217
}
218218

219+
public function getListV2($line, $refresh = false)
220+
{
221+
if (empty($line)) {
222+
return [];
223+
}
224+
// 新版本直接调用接口
225+
$url = 'http://www.szjt.gov.cn/BusQu/APTSLine.aspx/GetData';
226+
$param = '{"num":"'.$line.'"}';
227+
$header = [
228+
'content-type: Application/json',
229+
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36',
230+
'Accept: application/json',
231+
'Host: www.szjt.gov.cn',
232+
'Origin: http://www.szjt.gov.cn',
233+
];
234+
$data = Http::getInstent()->post($url, $param, 4, $header);
235+
236+
if ($data['content']) {
237+
$res = json_decode($data['content'], true);
238+
if (isset($res['d'])) {
239+
$arr = json_decode($res['d'], true);
240+
// 处理数组
241+
$return = [];
242+
if ($arr['Document']) {
243+
$lName = $arr['Document']['LName'] ?? '';
244+
$lDir = $arr['Document']['LDirection'] ?? '';
245+
$return['to'] = $lName.'-'.$lDir;
246+
247+
foreach ($arr['Document']['StandInfo'] as $item) {
248+
$return['line'][] = [
249+
'stationName' => $item['SName'] ?? '',
250+
'stationCode' => $item['SCode'] ?? '',
251+
'carCode' => $item['BusInfo'] ?? '',
252+
'ArrivalTime' => str_replace('/', '-', $item['InTime'] ?? ''),
253+
'OutTime' => str_replace('/', '-', $item['OutTime'] ?? ''),
254+
'SGuid' => $item['SGuid'] ?? '',
255+
];
256+
}
257+
return $return;
258+
}
259+
}
260+
}
261+
return [];
262+
}
263+
219264

220265
/**
221266
* 获取实时公交站台数据 table 列表

0 commit comments

Comments
 (0)