提交 d81d78a3 authored 作者: 吕本才's avatar 吕本才

refactor(controller): 调整腾讯地图控制器路径并优化响应结构

上级 acb1580e
......@@ -3,8 +3,6 @@ package com.link.hub.controller.mp.query;
import com.alibaba.fastjson.JSONObject;
import com.link.hub.service.weChatMiniProgram.TencentMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -14,7 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
* 腾讯地图接口控制器
*/
@RestController
@RequestMapping("/miniProgram/query/tencent/map")
@RequestMapping("/miniProgram/query")
public class TencentMapController {
@Autowired
......@@ -22,26 +20,19 @@ public class TencentMapController {
/**
* 经纬度→地理位置查询接口
* @param lat 纬度(必填)
* @param lng 经度(必填)
*
* @param lat 纬度(必填)
* @param lng 经度(必填)
* @param getPoi 是否返回POI(可选,默认0)
* @return 统一响应结果
*/
@GetMapping("/geo/reverse")
public ResponseEntity<?> getLocationByLngLat(
public JSONObject getLocationByLngLat(
@RequestParam("lat") Double lat,
@RequestParam("lng") Double lng,
@RequestParam(value = "getPoi", defaultValue = "0") Integer getPoi) {
try {
JSONObject locationByLngLat = tencentMapService.getLocationByLngLat(lat, lng, getPoi);
// 返回成功结果(可封装统一响应体,这里简化)
return ResponseEntity.ok(locationByLngLat);
} catch (IllegalArgumentException e) {
// 参数错误
return ResponseEntity.badRequest().body("参数错误:" + e.getMessage());
} catch (Exception e) {
// 其他异常
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("查询失败:" + e.getMessage());
}
JSONObject locationByLngLat = tencentMapService.getLocationByLngLat(lat, lng, getPoi);
// 返回成功结果(可封装统一响应体,这里简化)
return locationByLngLat;
}
}
......@@ -21,6 +21,12 @@ public class WechatMiniProgramController {
private WechatMiniProgramService wechatMiniProgramService;
@Resource
private WechatOfficeAccountService wechatOfficeAccountService;
/**
* 小程序登录接口-mpLogin
* @param vo
* @return
*/
@PostMapping("/login")
public MiniProgramOpenIdVO mpLogin(@RequestBody MpLoginVo vo) {
MiniProgramOpenIdVO userInfo = wechatMiniProgramService.getUserInfo(vo);
......
......@@ -70,7 +70,8 @@ public class TencentMapServiceImpl implements TencentMapService {
log.error("腾讯地图API调用失败:{}(状态码:{})", geoResponse.getString("message"), geoResponse.getInteger("status"));
throw new ServiceException("腾讯地图API调用失败:" + geoResponse.getString("message") + "(状态码:" + geoResponse.getInteger("status") + ")");
}
JSONObject result = geoResponse.getJSONObject("result");
return geoResponse;
return result;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论