@@ -227,52 +227,56 @@ public function getListV2($line, $refresh = false)
227
227
if (empty ($ line )) {
228
228
return [];
229
229
}
230
- // 新版本直接调用接口
231
- $ url = 'http://www.szjt.gov.cn/BusQu/APTSLine.aspx/GetData ' ;
232
- $ param = '{"num":" ' .$ line .'"} ' ;
233
- $ header = [
234
- 'content-type: Application/json ' ,
235
- '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 ' ,
236
- 'Accept: application/json ' ,
237
- 'Host: www.szjt.gov.cn ' ,
238
- 'Origin: http://www.szjt.gov.cn ' ,
239
- ];
240
- $ data = Http::getInstent ()->post ($ url , $ param , 4 , $ header );
241
-
242
- if ($ data ['content ' ]) {
243
- $ res = json_decode ($ data ['content ' ], true );
244
- if (isset ($ res ['d ' ])) {
245
- $ arr = json_decode ($ res ['d ' ], true );
246
- // 处理数组
247
- $ return = [];
248
- if ($ arr ['Document ' ]) {
249
- foreach ($ arr ['Document ' ]['LineInfo ' ] as $ item ) {
250
- // "Guid": "921f91ad-757e-49d6-86ae-8e5f205117be",
251
- // "LName": "快线1号",
252
- // "LDirection": "星塘公交中心首末站",
253
- // "LFStdFTime": "06:00:00",
254
- // "LFStdETime": "21:00:00",
255
- // "LFStdName": "木渎公交换乘枢纽站",
256
- // "LEStdName": "星塘公交中心",
257
- // "LineType": ""
258
- $ fromTo = $ item ['LDirection ' ] ?? '' ;
259
- $ bus = $ item ['LName ' ] ?? '' ;
260
- $ Guid = $ item ['Guid ' ] ?? '' ;
261
- $ link = 'APTSLine.aspx?cid=&LineInfo= ' .$ bus .'( ' .$ fromTo .') ' .'&Guid= ' .$ Guid ;
262
- $ return [] = [
263
- 'FromTo ' => $ fromTo ,
264
- 'bus ' => $ bus ,
265
- 'link ' => $ link ,
266
- 'start_time ' => $ item ['LFStdFTime ' ] ?? '' ,
267
- 'end_time ' => $ item ['LFStdETime ' ] ?? '' ,
268
- 'line_type ' => $ item ['LineType ' ] ?? '' ,
269
- ];
230
+ if ($ refresh ) {
231
+ Cache::forget ('line_name: ' .$ line );
232
+ }
233
+ return Cache::remember ('line_name: ' .$ line , 3600 * 24 * 30 , function () use ($ line ) {
234
+ // 新版本直接调用接口
235
+ $ url = 'http://www.szjt.gov.cn/BusQu/APTSLine.aspx/GetData ' ;
236
+ $ param = '{"num":" ' .$ line .'"} ' ;
237
+ $ header = [
238
+ 'content-type: Application/json ' ,
239
+ '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 ' ,
240
+ 'Accept: application/json ' ,
241
+ 'Host: www.szjt.gov.cn ' ,
242
+ 'Origin: http://www.szjt.gov.cn ' ,
243
+ ];
244
+ $ data = Http::getInstent ()->post ($ url , $ param , 4 , $ header );
245
+
246
+ if ($ data ['content ' ]) {
247
+ $ res = json_decode ($ data ['content ' ], true );
248
+ if (isset ($ res ['d ' ])) {
249
+ $ arr = json_decode ($ res ['d ' ], true );
250
+ // 处理数组
251
+ $ return = [];
252
+ if ($ arr ['Document ' ]) {
253
+ foreach ($ arr ['Document ' ]['LineInfo ' ] as $ item ) {
254
+ // "Guid": "921f91ad-757e-49d6-86ae-8e5f205117be",
255
+ // "LName": "快线1号",
256
+ // "LDirection": "星塘公交中心首末站",
257
+ // "LFStdFTime": "06:00:00",
258
+ // "LFStdETime": "21:00:00",
259
+ // "LFStdName": "木渎公交换乘枢纽站",
260
+ // "LEStdName": "星塘公交中心",
261
+ // "LineType": ""
262
+ $ fromTo = $ item ['LDirection ' ] ?? '' ;
263
+ $ bus = $ item ['LName ' ] ?? '' ;
264
+ $ Guid = $ item ['Guid ' ] ?? '' ;
265
+ $ link = 'APTSLine.aspx?cid=&LineInfo= ' .$ bus .'( ' .$ fromTo .') ' .'&Guid= ' .$ Guid ;
266
+ $ return [] = [
267
+ 'FromTo ' => $ fromTo ,
268
+ 'bus ' => $ bus ,
269
+ 'link ' => $ link ,
270
+ 'start_time ' => $ item ['LFStdFTime ' ] ?? '' ,
271
+ 'end_time ' => $ item ['LFStdETime ' ] ?? '' ,
272
+ 'line_type ' => $ item ['LineType ' ] ?? '' ,
273
+ ];
274
+ }
275
+ return $ return ;
270
276
}
271
- return $ return ;
272
277
}
273
278
}
274
- }
275
- return [];
279
+ });
276
280
}
277
281
278
282
0 commit comments