using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using SKIT.FlurlHttpClient.Wechat.Api.Models; using SKIT.FlurlHttpClient.Wechat.Api; using System.Web; using Org.BouncyCastle.Utilities; using System.Net; using ZR.Common; using ZR.Model.Dto; using Infrastructure.Model; using System.Threading.Tasks; using ZR.Common.Model; namespace ZR.Admin.WebApi.Controllers { /// /// webApi /// [Route("[controller]/[action]")] [AllowAnonymous] [ApiExplorerSettings(GroupName = "webapi")] public class WebApiController : BaseController { private readonly TencentMapService _tencentMapService; public WebApiController(TencentMapService tencentMapService) { _tencentMapService = tencentMapService; } /// /// 转换 GPS 经纬度到腾讯地图坐标 /// /// 坐标转换请求参数 /// 转换后的坐标 [HttpPost] [Route("GetLocationTranslate")] public async Task GetLocationTranslate([FromBody] CoordinateTranslateRequest request) { try { if (request == null || string.IsNullOrWhiteSpace(request.Locations)) { return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空"); } var result = await _tencentMapService.GetLocationTranslateAsync(request.Locations, request.Type); return SUCCESS(result); } catch (Exception ex) { return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message); } } /// /// 根据坐标获取地址信息 /// /// 地理编码请求参数 /// 地址信息 [HttpPost] [Route("GetLocationGeocoder")] public async Task GetLocationGeocoder([FromBody] GeocoderRequest request) { try { if (request == null || string.IsNullOrWhiteSpace(request.Location)) { return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空"); } var result = await _tencentMapService.GetLocationGeocoderAsync(request.Location); return SUCCESS(result); } catch (Exception ex) { return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message); } } /// /// 批量转换GPS坐标并获取地址 /// /// 坐标转换请求参数 /// 转换后的坐标和地址信息 [HttpPost] [Route("GetLocationTranslateAndGeocoder")] public async Task GetLocationTranslateAndGeocoder([FromBody] CoordinateTranslateRequest request) { try { if (request == null || string.IsNullOrWhiteSpace(request.Locations)) { return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空"); } var result = await _tencentMapService.GetLocationTranslateAndGeocoderAsync(request.Locations); return SUCCESS(new { Location = result.Location, Address = result.Address }); } catch (Exception ex) { return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message); } } /// /// 转换 GPS 经纬度到腾讯地图坐标 (GET方式) /// /// 坐标点,格式:lat,lng;lat,lng /// 转换类型,默认1表示GPS坐标转腾讯坐标 /// 转换后的坐标 [HttpGet] [Route("/webapi/GetLocationTranslate")] [AllowAnonymous] public async Task GetLocationTranslateGet([FromQuery] string locations, [FromQuery] int type = 1) { try { if (string.IsNullOrWhiteSpace(locations)) { return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空"); } var result = await _tencentMapService.GetLocationTranslateAsync(locations, type); return SUCCESS(result); } catch (Exception ex) { return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message); } } /// /// 根据坐标获取地址信息 (GET方式) /// /// 坐标点,格式:lat,lng /// 地址信息 [HttpGet] [Route("/webapi/GetLocationGeocoder")] [AllowAnonymous] public async Task GetLocationGeocoderGet([FromQuery] string location) { try { if (string.IsNullOrWhiteSpace(location)) { return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空"); } var result = await _tencentMapService.GetLocationGeocoderAsync(location); return SUCCESS(result); } catch (Exception ex) { return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message); } } } }