Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-link-module-fortune-hub
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-link-module-fortune-hub
Commits
bd3ae3a9
提交
bd3ae3a9
authored
12月 12, 2025
作者:
吕本才
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(tencent-map): 集成腾讯地图逆地理编码功能
上级
23734aca
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
162 行增加
和
5 行删除
+162
-5
TencentMapConfig.java
src/main/java/com/link/hub/config/TencentMapConfig.java
+27
-0
TencentMapController.java
...om/link/hub/controller/mp/query/TencentMapController.java
+47
-0
TencentMapService.java
...link/hub/service/weChatMiniProgram/TencentMapService.java
+7
-0
TencentMapServiceImpl.java
...service/weChatMiniProgram/impl/TencentMapServiceImpl.java
+76
-0
WechatMiniProgramServiceServiceImpl.java
...MiniProgram/impl/WechatMiniProgramServiceServiceImpl.java
+3
-0
WechatMiniProgramUserServiceServiceImpl.java
...Program/impl/WechatMiniProgramUserServiceServiceImpl.java
+2
-5
没有找到文件。
src/main/java/com/link/hub/config/TencentMapConfig.java
0 → 100644
浏览文件 @
bd3ae3a9
package
com
.
link
.
hub
.
config
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.client.RestTemplate
;
/**
* 腾讯地图配置类
*/
@Configuration
public
class
TencentMapConfig
{
@Value
(
"${tencent.map.key:UTEBZ-UJ3KG-OORQO-QT3PT-JDWU7-YRBZA}"
)
private
String
tencentMapKey
;
// 腾讯地图逆地理编码API地址
public
static
final
String
TENCENT_MAP_GEOCODER_URL
=
"https://apis.map.qq.com/ws/geocoder/v1/"
;
// 替换为你申请的腾讯地图Key
public
static
final
String
TENCENT_MAP_KEY
=
"UTEBZ-UJ3KG-OORQO-QT3PT-JDWU7-YRBZA"
;
// 注入RestTemplate(用于发送HTTP请求)
@Bean
public
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
}
}
src/main/java/com/link/hub/controller/mp/query/TencentMapController.java
0 → 100644
浏览文件 @
bd3ae3a9
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
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 腾讯地图接口控制器
*/
@RestController
@RequestMapping
(
"/miniProgram/query/tencent/map"
)
public
class
TencentMapController
{
@Autowired
private
TencentMapService
tencentMapService
;
/**
* 经纬度→地理位置查询接口
* @param lat 纬度(必填)
* @param lng 经度(必填)
* @param getPoi 是否返回POI(可选,默认0)
* @return 统一响应结果
*/
@GetMapping
(
"/geo/reverse"
)
public
ResponseEntity
<?>
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
());
}
}
}
src/main/java/com/link/hub/service/weChatMiniProgram/TencentMapService.java
0 → 100644
浏览文件 @
bd3ae3a9
package
com
.
link
.
hub
.
service
.
weChatMiniProgram
;
import
com.alibaba.fastjson.JSONObject
;
public
interface
TencentMapService
{
JSONObject
getLocationByLngLat
(
Double
lat
,
Double
lng
,
Integer
getPoi
);
}
src/main/java/com/link/hub/service/weChatMiniProgram/impl/TencentMapServiceImpl.java
0 → 100644
浏览文件 @
bd3ae3a9
package
com
.
link
.
hub
.
service
.
weChatMiniProgram
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.link.hub.config.TencentMapConfig
;
import
com.link.hub.service.weChatMiniProgram.TencentMapService
;
import
com.sfa.common.core.exception.ServiceException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.util.UriComponentsBuilder
;
/**
* 腾讯地图业务层
*/
@Slf4j
@Service
public
class
TencentMapServiceImpl
implements
TencentMapService
{
@Autowired
private
RestTemplate
restTemplate
;
/**
* 根据经纬度查询地理位置
* @param latitude 纬度(如:39.984154)
* @param longitude 经度(如:116.307490)
* @param getPoi 是否返回周边POI(1=返回,0=不返回)
* @return 腾讯地图地理信息响应
* @throws Exception 调用异常/解析异常
*/
public
JSONObject
getLocationByLngLat
(
Double
latitude
,
Double
longitude
,
Integer
getPoi
)
{
// 1. 参数校验
if
(
latitude
==
null
||
longitude
==
null
)
{
throw
new
IllegalArgumentException
(
"纬度/经度不能为空"
);
}
if
(
getPoi
==
null
)
{
getPoi
=
0
;
// 默认不返回POI
}
// 2. 拼接请求URL(带参数)
String
location
=
latitude
+
","
+
longitude
;
String
requestUrl
=
UriComponentsBuilder
.
fromHttpUrl
(
TencentMapConfig
.
TENCENT_MAP_GEOCODER_URL
)
.
queryParam
(
"location"
,
location
)
.
queryParam
(
"key"
,
TencentMapConfig
.
TENCENT_MAP_KEY
)
.
queryParam
(
"get_poi"
,
getPoi
)
.
toUriString
();
// 3. 发送GET请求调用腾讯地图API
ResponseEntity
<
String
>
responseEntity
;
try
{
responseEntity
=
restTemplate
.
getForEntity
(
requestUrl
,
String
.
class
);
}
catch
(
RestClientException
e
)
{
log
.
error
(
String
.
format
(
"调用腾讯地图API失败:%s"
,
e
.
getMessage
()),
e
);
throw
new
ServiceException
(
"调用腾讯地图API失败:"
+
e
.
getMessage
());
}
// 4. 解析JSON响应
String
responseBody
=
responseEntity
.
getBody
();
if
(
responseBody
==
null
)
{
log
.
error
(
"腾讯地图API返回空结果"
);
throw
new
ServiceException
(
"腾讯地图API返回空结果"
);
}
JSONObject
geoResponse
=
JSON
.
parseObject
(
responseBody
);
// 5. 校验API返回状态
if
(
geoResponse
.
getInteger
(
"status"
)
!=
0
)
{
log
.
error
(
"腾讯地图API调用失败:{}(状态码:{})"
,
geoResponse
.
getString
(
"message"
),
geoResponse
.
getInteger
(
"status"
));
throw
new
ServiceException
(
"腾讯地图API调用失败:"
+
geoResponse
.
getString
(
"message"
)
+
"(状态码:"
+
geoResponse
.
getInteger
(
"status"
)
+
")"
);
}
return
geoResponse
;
}
}
src/main/java/com/link/hub/service/weChatMiniProgram/impl/WechatMiniProgramServiceServiceImpl.java
浏览文件 @
bd3ae3a9
...
...
@@ -18,6 +18,7 @@ import com.sfa.common.core.utils.uuid.IdUtils;
import
com.sfa.common.core.utils.wechat.WeChatPlatFormUtils
;
import
com.sfa.common.security.service.TokenService
;
import
com.sfa.system.api.model.LoginUser
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -29,6 +30,7 @@ import java.util.Map;
/**
* 小程序服务实现
*/
@Slf4j
@Service
public
class
WechatMiniProgramServiceServiceImpl
implements
WechatMiniProgramService
{
@Resource
...
...
@@ -52,6 +54,7 @@ public class WechatMiniProgramServiceServiceImpl implements WechatMiniProgramSer
openid
=
"test1"
+
code
;
}
if
(
ObjectUtil
.
isEmpty
(
openid
))
{
log
.
error
(
"获取openid失败,code:{},返回信息:{}"
,
code
,
jsonObject
.
toString
());
throw
new
ServiceException
(
"获取openid失败"
);
}
MpUserDto
mpUserDto
=
new
MpUserDto
();
...
...
src/main/java/com/link/hub/service/weChatMiniProgram/impl/WechatMiniProgramUserServiceServiceImpl.java
浏览文件 @
bd3ae3a9
...
...
@@ -34,10 +34,7 @@ public class WechatMiniProgramUserServiceServiceImpl implements WechatMiniProgra
wechatMiniProgramUserWq
.
setOpenid
(
mpUserDto
.
getOpenid
());
wechatMiniProgramUserWq
.
setUserId
(
mpUserDto
.
getId
());
WechatMiniProgramUser
wechatMiniProgramUser
=
wechatMiniProgramUserDao
.
queryMiniProgramUserOne
(
wechatMiniProgramUserWq
);
// if (wechatMiniProgramUser == null) {
// log.error("用户不存在,openid:{},userId:{}", mpUserDto.getOpenid(), mpUserDto.getId());
// throw new ServiceException("用户不存在");
// }
return
wechatMiniProgramUser
;
}
...
...
@@ -45,10 +42,10 @@ public class WechatMiniProgramUserServiceServiceImpl implements WechatMiniProgra
public
Long
saveMiniProgramUser
(
MpOpenIdDTO
mpOpenIdDTO
)
{
WechatMiniProgramUser
wechatMiniProgramUser
=
new
WechatMiniProgramUser
();
wechatMiniProgramUser
.
setOpenid
(
mpOpenIdDTO
.
getOpenid
());
wechatMiniProgramUser
.
setUnionid
(
mpOpenIdDTO
.
getUnionid
());
wechatMiniProgramUser
.
setCreateTime
(
DateUtil
.
date
());
wechatMiniProgramUser
.
setUpdateTime
(
DateUtil
.
date
());
wechatMiniProgramUserDao
.
insert
(
wechatMiniProgramUser
);
return
wechatMiniProgramUser
.
getId
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论