1
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace app\service;
|
||||
|
||||
use app\util\HttpClient;
|
||||
|
||||
class ShipService
|
||||
{
|
||||
private const API_BASE_URL = 'https://api.shipxy.com/apicall/v3';
|
||||
private const API_KEY = 'ab107a0254494d61a25749028c0f09c2';
|
||||
|
||||
/**
|
||||
* 获取单个船舶信息
|
||||
* @param string $mmsi 船舶MMSI号
|
||||
* @return array 返回船舶信息
|
||||
*/
|
||||
public static function getShipInfo(string $mmsi): array
|
||||
{
|
||||
$url = self::API_BASE_URL . '/GetSingleShip';
|
||||
$query = [
|
||||
'key' => self::API_KEY,
|
||||
'mmsi' => $mmsi
|
||||
];
|
||||
|
||||
$response = HttpClient::get($url, $query);
|
||||
|
||||
// 检查API响应状态
|
||||
if (!$response['status']) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => '请求失败: ' . $response['message'],
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
|
||||
// 检查API业务状态
|
||||
if (isset($response['data']['status']) && $response['data']['status'] !== 0) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => '获取船舶信息失败: ' . ($response['data']['msg'] ?? '未知错误'),
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => '获取成功',
|
||||
'data' => $response['data']
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user