添加try

This commit is contained in:
wangxiaowei 2024-09-29 14:11:38 +08:00
parent cc568d5057
commit de082bc9b1

@ -323,14 +323,16 @@ class LocalStore extends Api
// 腾讯地图逆编码
public function getLocation()
{
$post = $this->request->post();
$url = 'https://apis.map.qq.com/ws/geocoder/v1?key=' . ConfigServer::get('map', 'tx_map_key') . '&address=' . $post['address'];
$result = file_get_contents($url);
$data = json_decode($result, true);
if ($data['message'] == 'Success') {
return JsonServer::success('', $data['result']['location']);
try {
$post = $this->request->post();
$url = 'https://apis.map.qq.com/ws/geocoder/v1?key=' . ConfigServer::get('map', 'tx_map_key') . '&address=' . $post['address'];
$result = file_get_contents($url);
$data = json_decode($result, true);
if ($data['message'] == 'Success') {
return JsonServer::success('', $data['result']['location']);
}
} catch(\Exception $e) {
return JsonServer::error($e->getMessage());
}
return JsonServer::error('地理位置获取失败');
}
}