Commit 33d07dd9 by 叶立庆

兼容Bigdecimal类型传参验签

1 parent 456870da
package com.gsc4cloud.gsc.gateway.filter; package com.gsc4cloud.gsc.gateway.filter;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.gsc4cloud.gsc.gateway.config.SignConfigProperties; import com.gsc4cloud.gsc.gateway.config.SignConfigProperties;
import com.gsc4cloud.gsc.gateway.utils.SignUtil; import com.gsc4cloud.gsc.gateway.utils.SignUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -42,7 +44,9 @@ import java.util.stream.Collectors; ...@@ -42,7 +44,9 @@ import java.util.stream.Collectors;
@Component @Component
public class WebRequestSignFilter implements GlobalFilter, Ordered { public class WebRequestSignFilter implements GlobalFilter, Ordered {
private final ObjectMapper objectMapper = new ObjectMapper(); private final ObjectMapper objectMapper = new ObjectMapper()
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true)
.setNodeFactory(JsonNodeFactory.withExactBigDecimals(true));;
@Autowired @Autowired
private SignConfigProperties signConfigProperties; private SignConfigProperties signConfigProperties;
...@@ -215,11 +219,23 @@ public class WebRequestSignFilter implements GlobalFilter, Ordered { ...@@ -215,11 +219,23 @@ public class WebRequestSignFilter implements GlobalFilter, Ordered {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
JsonNode root = objectMapper.readTree(bytes); JsonNode root = objectMapper.readTree(bytes);
root.properties().forEach(entry -> { root.properties().forEach(entry -> {
JsonNode value = entry.getValue();
// 排除空值字段 // 排除空值字段
if (entry.getValue().isNull()) { if (value == null || value.isNull()) {
return; return;
} }
result.put(entry.getKey(), entry.getValue()); if (value.isNumber()) {
// 保留小数位(如 12.10),用于验签与日志一致性
String numStr = value.isFloatingPointNumber()
? value.decimalValue().toPlainString()
: value.asText();
result.put(entry.getKey(), numStr);
} else if (value.isTextual()) {
result.put(entry.getKey(), value.asText());
} else {
// 其他类型统一序列化为字符串
result.put(entry.getKey(), value.toString());
}
}); });
return result; return result;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!