Compare commits

...

3 Commits

5 changed files with 45 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
package com.yolo.keyborad.interceptor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.yolo.keyborad.utils.SignUtils;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.http.HttpServletRequest;
@@ -21,6 +22,8 @@ public class SignInterceptor implements HandlerInterceptor {
// appId -> secret 的映射(可从 DB 等处加载)
private final Map<String, String> appSecretMap;
private final ObjectMapper objectMapper = new ObjectMapper();
private final ObjectMapper signValueObjectMapper = new ObjectMapper()
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
private final StringRedisTemplate redisTemplate;
// 允许时间误差 5 分钟
@@ -103,7 +106,7 @@ public class SignInterceptor implements HandlerInterceptor {
Map<String, Object> bodyMap = objectMapper.readValue(body, Map.class);
bodyMap.forEach((k, v) -> {
if (v != null) {
params.put(k, String.valueOf(v));
params.put(k, stringifyForSign(v));
}
});
}
@@ -118,6 +121,23 @@ public class SignInterceptor implements HandlerInterceptor {
return true;
}
private String stringifyForSign(Object value) {
if (value == null) {
return null;
}
if (value instanceof CharSequence || value instanceof Number || value instanceof Boolean) {
return String.valueOf(value);
}
if (value.getClass().isArray() || value instanceof Collection || value instanceof Map) {
try {
return signValueObjectMapper.writeValueAsString(value);
} catch (Exception e) {
throw new RuntimeException("Sign body param serialize error", e);
}
}
return String.valueOf(value);
}
private String buildNonceKey(String appId, String nonce) {
// 可以按需加上前缀,便于区分业务
return "sign:nonce:" + appId + ":" + nonce;

View File

@@ -4,6 +4,7 @@ import cn.dev33.satoken.stp.StpUtil;
import com.yolo.keyborad.common.BaseResponse;
import com.yolo.keyborad.common.ResultUtils;
import com.yolo.keyborad.model.dto.purchase.ThemePurchaseReq;
import com.yolo.keyborad.model.dto.purchase.ThemeRestoreReq;
import com.yolo.keyborad.model.vo.purchase.ThemePurchaseListRespVO;
import com.yolo.keyborad.model.vo.purchase.ThemePurchaseRespVO;
import com.yolo.keyborad.model.vo.themes.KeyboardThemeStylesRespVO;
@@ -101,9 +102,9 @@ public class ThemesController {
@PostMapping("/restore")
@Operation(summary = "恢复已删除的主题", description = "将用户已删除的主题重新展示")
public BaseResponse<Void> restoreTheme(@RequestParam Long themeId) {
public BaseResponse<Void> restoreTheme(@RequestBody ThemeRestoreReq req) {
Long userId = StpUtil.getLoginIdAsLong();
themePurchaseService.restoreDeletedTheme(userId, themeId);
themePurchaseService.restoreDeletedTheme(userId, req.getThemeId());
return ResultUtils.success(null);
}

View File

@@ -0,0 +1,16 @@
package com.yolo.keyborad.model.dto.purchase;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/*
* @author: ziin
* @date: 2026/2/27
*/
@Schema(description = "恢复已删除的主题请求")
@Data
public class ThemeRestoreReq {
@Schema(description = "主题ID", requiredMode = Schema.RequiredMode.REQUIRED)
private Long themeId;
}

View File

@@ -84,6 +84,7 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
return keyboardUserMapper.selectOne(
new LambdaQueryWrapper<KeyboardUser>()
.eq(KeyboardUser::getSubjectId, sub)
.eq(KeyboardUser::getDeleted, false)
.eq(KeyboardUser::getStatus, false));
}
@@ -107,6 +108,7 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
KeyboardUser keyboardUser = keyboardUserMapper.selectOne(
new LambdaQueryWrapper<KeyboardUser>()
.eq(KeyboardUser::getEmail, userLoginDTO.getMail())
.eq(KeyboardUser::getDeleted, false)
.eq(KeyboardUser::getStatus, false));
if (keyboardUser == null) {
throw new BusinessException(ErrorCode.USER_NOT_FOUND);
@@ -130,6 +132,7 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
KeyboardUser keyboardUserDB = keyboardUserMapper.selectOne(
new LambdaQueryWrapper<KeyboardUser>()
.eq(KeyboardUser::getId, loginIdAsLong)
.eq(KeyboardUser::getDeleted, false)
.eq(KeyboardUser::getStatus, false));
if (keyboardUserDB == null) {
throw new BusinessException(ErrorCode.USER_NOT_FOUND);

View File

@@ -86,7 +86,8 @@ public class UserRegistrationHandler {
private void ensureUserNotExists(String mailAddress) {
KeyboardUser userMail = keyboardUserMapper.selectOne(new LambdaQueryWrapper<KeyboardUser>()
.eq(KeyboardUser::getEmail, mailAddress));
.eq(KeyboardUser::getEmail, mailAddress)
.eq(KeyboardUser::getDeleted, false));
if (userMail != null) {
throw new BusinessException(ErrorCode.USER_HAS_EXISTED);
}