feat:钱包接口对接
This commit is contained in:
@@ -306,4 +306,42 @@ public class RsaSignUtil {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 针对 /zxjp/open/v1/wallet/** 接口的专用验签方法
|
||||
* @param params 包含签名参数的Map
|
||||
* @param privateKeyPEM 用于生成签名的私钥
|
||||
* @return 验签是否通过
|
||||
*/
|
||||
public static boolean verifyWalletSign(Map<String, Object> params, String privateKeyPEM) {
|
||||
try {
|
||||
// 1. 获取请求中的签名
|
||||
String requestSign = String.valueOf(params.get("sign"));
|
||||
if (requestSign == null || requestSign.isEmpty()) {
|
||||
log.warn("请求中缺少签名参数");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 移除签名参数,生成待签名字符串
|
||||
Map<String, Object> paramsToSign = new HashMap<>(params);
|
||||
paramsToSign.remove("sign");
|
||||
|
||||
// 3. 使用相同的私钥生成签名
|
||||
String generatedSign = generateSign(paramsToSign, privateKeyPEM);
|
||||
|
||||
// 4. 对比签名
|
||||
boolean isVerified = Objects.equals(requestSign, generatedSign);
|
||||
|
||||
if (!isVerified) {
|
||||
log.warn("签名验证失败,请求签名: {}, 生成签名: {}", requestSign, generatedSign);
|
||||
}
|
||||
|
||||
return isVerified;
|
||||
} catch (Exception e) {
|
||||
log.error("验签过程中发生异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user