{
"countryId": "COL",
"currency": "COP",
"customerAccount": "3720000264",
"merId": "8301000002750275",
"merOrderNo": "merOrderNo",
"nonceStr": "string",
"orderAmount": "30000",
"payProduct": "08",
"nonceStr": "4cKcL83FIsDgjAi"
}
countryId=COL¤cy=COP&customerAccount=3720000264&merId=8301000002750275&merOrderNo=merOrderNo&nonceStr=4cKcL83FIsDgjAi&orderAmount=30000&payProduct=08&key=11111111111111111111111111111111
1DD2448C750D92B3AE512F2E493F5665
{
"countryId": "COL",
"currency": "COP",
"customerAccount": "3720000264",
"merId": "8301000002750275",
"merOrderNo": "merOrderNo",
"nonceStr": "string",
"orderAmount": "30000",
"payProduct": "08",
"nonceStr": "4cKcL83FIsDgjAi",
"sign": "1DD2448C750D92B3AE512F2E493F5665"
}
public static String sign(Object data, String key) {
return sign(JSON.parseObject(JSONObject.toJSONString(data)), key);
}
public static String sign(Map<String, Object> data, String key) {
data.remove("sign");
String signedValue = getSignedValue(data);
signedValue += "key=" + key;
log.info("signedValue:{}", signedValue);
return md5(signedValue, "UTF-8").toUpperCase();
}
private static String getSignedValue(Map<String, Object> reqMap) {
Map<String, String> copy = new TreeMap<>();
reqMap.forEach((k, v) -> {
if (v != null && !"".equals(v)) {
copy.put(k, v.toString());
}
});
StringBuilder sb = new StringBuilder();
copy.forEach((k, v) -> {
if (v != null) {
sb.append(k).append("=").append(v).append("&");
}
});
return sb.toString();
}
String callbackData = "{\n" + " \"countryId\": \"COL\",\n" + " \"currency\": \"COP\",\n"
+ " \"customerAccount\": \"3720000264\",\n" + " \"merId\": \"8301000002750275\",\n"
+ " \"merOrderNo\": \"merOrderNo\",\n" + " \"nonceStr\": \"string\",\n"
+ " \"orderAmount\": \"30000\",\n" + " \"payProduct\": \"08\",\n"
+ " \"nonceStr\": \"4cKcL83FIsDgjAi\",\n" + " \"sign\": \"1DD2448C750D92B3AE512F2E493F5665\"\n" + "}";
JSONObject data = JSON.parseObject(callbackData);
String sign = data.get("sign").toString();
data.remove("sign");
String signValue = SupefinaSignUtils.sign(data, "商户key");
if (Objects.equals(sign, signValue)) {
// 验证签名通过
} else {
// 失败
}