From b55cd9aad0835a96a790e61f9f89edc2fae1be9f Mon Sep 17 00:00:00 2001
From: 刘帅 <rr.iii@qq.com>
Date: 星期二, 29 九月 2026 01:26:37 +0800
Subject: [PATCH] 注释优化、格式优化
---
cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java | 153 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 146 insertions(+), 7 deletions(-)
diff --git a/cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java b/cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java
index 17adc31..69e1c50 100644
--- a/cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java
+++ b/cloud-server-account/src/main/java/com/dsh/account/controller/AppUserController.java
@@ -11,6 +11,7 @@
import com.dsh.account.model.AdvertisementChangeStateDTO;
import com.dsh.account.model.AppUserByNameAndPhoneDTO;
import com.dsh.account.model.AppUserIdsByCityName;
+import com.dsh.account.model.ImageCaptchaVo;
import com.dsh.account.model.JoinPlayPaiVo;
import com.dsh.account.model.LoginSMSCodeVo;
import com.dsh.account.model.LoginWeChatVo;
@@ -38,6 +39,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.RequestHeader;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -61,6 +63,8 @@
@Autowired
private TAppUserService appUserService;
+ @Autowired
+ private ImageCaptchaService imageCaptchaService;
@Autowired
private VipClient vipClient;
@@ -243,6 +247,44 @@
}
/**
+ * 仅供管理端敏感信息查询使用的内部数据接口。
+ * 调用方由管理服务完成认证和授权;其 Feign 拦截器会添加请求头,
+ * 以允许本次响应不进行脱敏。
+ */
+ @PostMapping("/internal/sensitive/app-user/{id}")
+ public Map<String, Object> sensitiveAppUser(@PathVariable("id") Integer id,
+ @RequestHeader(value = "X-Internal-Sensitive-Access", required = false) String access) {
+ if (!"true".equalsIgnoreCase(access)) {
+ throw new IllegalStateException("Sensitive data access is restricted to the management service");
+ }
+ TAppUser user = appUserService.getById(id);
+ if (user == null) return null;
+ Map<String, Object> result = new java.util.HashMap<String, Object>();
+ result.put("id", user.getId());
+ result.put("name", user.getName());
+ result.put("phone", user.getPhone());
+ result.put("idCard", user.getIdCard());
+ return result;
+ }
+
+ /**
+ * APP 订场提交页面展示的脱敏手机号时使用的内部数据接口。
+ * 仅返回该预约所需的手机号字段;调用方必须携带内部敏感数据访问请求头。
+ */
+ @PostMapping("/internal/sensitive/site-booking/app-user/{id}/phone")
+ public Map<String, Object> siteBookingPhone(@PathVariable("id") Integer id,
+ @RequestHeader(value = "X-Internal-Sensitive-Access", required = false) String access) {
+ if (!"true".equalsIgnoreCase(access)) {
+ throw new IllegalStateException("Sensitive data access is restricted to site booking");
+ }
+ TAppUser user = appUserService.getById(id);
+ if (user == null) return null;
+ Map<String, Object> result = new java.util.HashMap<String, Object>();
+ result.put("phone", user.getPhone());
+ return result;
+ }
+
+ /**
* 冻结/解冻 1=解冻 2=冻结
*/
@RequestMapping("/base/appUser/changeState")
@@ -316,26 +358,119 @@
}
@ResponseBody
- @PostMapping("/base/appUser/getSMSCode")
- @ApiOperation(value = "获取短信验证码", tags = {"APP-登录注册"})
+ @PostMapping("/base/appUser/imageCaptcha")
+ @ApiOperation(value = "获取短信发送前置图形验证码", tags = {"APP-登录注册"})
@ApiImplicitParams({
@ApiImplicitParam(value = "类型(1:登录,2:注册,3:修改密码,4:忘记密码)", name = "type", dataType = "int", required = true),
@ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true)
})
- public ResultUtil getSMSCode(Integer type, String phone) {
- if (ToolUtil.isEmpty(phone)) {
+ public ResultUtil<ImageCaptchaVo> getImageCaptcha(Integer type, String phone, HttpServletRequest request) {
+ if (!isValidPhone(phone)) {
return ResultUtil.paranErr("phone");
}
- if (ToolUtil.isEmpty(type)) {
+ if (!isValidSmsType(type)) {
return ResultUtil.paranErr("type");
}
try {
- ResultUtil smsCode = appUserService.getSMSCode(type, phone);
- return smsCode;
+ ImageCaptchaVo captcha = imageCaptchaService.create(phone, type, getClientIp(request));
+ if (captcha == null) {
+ return ResultUtil.error("图形验证码获取过于频繁,请稍后重试", null);
+ }
+ return ResultUtil.success(captcha);
} catch (Exception e) {
e.printStackTrace();
return ResultUtil.runErr();
}
+ }
+
+ @ResponseBody
+ @PostMapping("/base/appUser/getSMSCode")
+ @ApiOperation(value = "获取短信验证码", tags = {"APP-登录注册"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "类型(1:登录,2:注册,3:修改密码,4:忘记密码)", name = "type", dataType = "int", required = true),
+ @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true),
+ @ApiImplicitParam(value = "图形验证码唯一标识", name = "captchaId", dataType = "string", required = true),
+ @ApiImplicitParam(value = "图形验证码", name = "captchaCode", dataType = "string", required = true)
+ })
+ public ResultUtil getSMSCode(Integer type, String phone, String captchaId, String captchaCode,
+ HttpServletRequest request) {
+ if (!isValidPhone(phone)) {
+ return ResultUtil.paranErr("phone");
+ }
+ if (!isValidSmsType(type)) {
+ return ResultUtil.paranErr("type");
+ }
+ if (ToolUtil.isEmpty(captchaId)|| ToolUtil.isEmpty(captchaCode) ) {
+ return ResultUtil.error("系统维护中,注册或登录请联系场地管理员");
+ }
+ if (!imageCaptchaService.verifyAndConsume(captchaId, captchaCode, phone, type)) {
+ return ResultUtil.error("图形验证码错误或已失效,请刷新后重试");
+ }
+ try {
+ return appUserService.getSMSCode(type, phone, getClientIp(request));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+
+ private boolean isValidPhone(String phone) {
+ return phone != null && phone.matches("^1\\d{10}$");
+ }
+
+ private boolean isValidSmsType(Integer type) {
+ return type != null && type >= 1 && type <= 4;
+ }
+
+ private String getClientIp(HttpServletRequest request) {
+ String remoteAddress = request.getRemoteAddr();
+ if (!isInternalProxyAddress(remoteAddress)) {
+ return remoteAddress;
+ }
+
+ String forwardedFor = request.getHeader("X-Forwarded-For");
+ if (ToolUtil.isNotEmpty(forwardedFor)) {
+ String[] addresses = forwardedFor.split(",");
+ for (int i = addresses.length - 1; i >= 0; i--) {
+ String clientIp = addresses[i].trim();
+ if (isValidIpText(clientIp) && !isInternalProxyAddress(clientIp)) {
+ return clientIp;
+ }
+ }
+ }
+ String realIp = request.getHeader("X-Real-IP");
+ if (isValidIpText(realIp)) {
+ return realIp.trim();
+ }
+ return remoteAddress;
+ }
+
+ private boolean isInternalProxyAddress(String ip) {
+ if (ip == null) {
+ return false;
+ }
+ if ("127.0.0.1".equals(ip) || "0:0:0:0:0:0:0:1".equals(ip) || "::1".equals(ip)
+ || ip.startsWith("10.") || ip.startsWith("192.168.")) {
+ return true;
+ }
+ if (ip.startsWith("172.")) {
+ String[] parts = ip.split("\\.");
+ if (parts.length == 4) {
+ try {
+ int secondPart = Integer.parseInt(parts[1]);
+ return secondPart >= 16 && secondPart <= 31;
+ } catch (NumberFormatException ignored) {
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isValidIpText(String ip) {
+ return ToolUtil.isNotEmpty(ip)
+ && ip.length() <= 45
+ && ip.trim().matches("[0-9a-fA-F:.]+");
}
@@ -746,6 +881,10 @@
public void updateAppUser(@RequestBody TAppUser appUser) {
try {
TAppUser appUser1 = appUserService.getById(appUser.getId());
+ // 管理端编辑表单可能携带页面展示的脱敏值。
+ // 不得使用该展示值覆盖原始证件或联系方式。
+ if (appUser.getPhone() != null && appUser.getPhone().contains("*")) appUser.setPhone(appUser1.getPhone());
+ if (appUser.getIdCard() != null && appUser.getIdCard().contains("*")) appUser.setIdCard(appUser1.getIdCard());
appUserService.updateById(appUser);
if (appUser.getIntegral().compareTo(appUser1.getIntegral()) != 0) {
UserIntegralChanges userIntegralChanges = new UserIntegralChanges();
--
Gitblit v1.7.1