You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
2 years ago
|
package com.eco.plugin.xx.gesso.utils;
|
||
|
|
||
|
import com.fr.third.springframework.util.CollectionUtils;
|
||
|
import com.fr.third.springframework.util.DigestUtils;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.Map;
|
||
|
|
||
|
public class EncryptUtils {
|
||
|
|
||
|
/**
|
||
|
* 包含body、params 计算签名
|
||
|
* @param params
|
||
|
* @param secret
|
||
|
* @return
|
||
|
*/
|
||
|
public static String getSign(Map<String, Object> params, String secret) {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
// md5加密 参数前加上secret
|
||
|
sb.append(secret);
|
||
|
if (!CollectionUtils.isEmpty(params)) {
|
||
|
// params参数是排序
|
||
|
String[] keys = params.keySet().toArray(new String[0]);
|
||
|
Arrays.sort(keys);
|
||
|
// 把所有参数名和参数值串在⼀起
|
||
|
for (String key : keys) {
|
||
|
String value = String.valueOf(params.get(key));
|
||
|
sb.append(key).append(value);
|
||
|
}
|
||
|
}
|
||
|
// 把body参数串在⼀起
|
||
|
|
||
|
// md5加密 参数后加上secret
|
||
|
sb.append(secret);
|
||
|
// 第三步:计算签名
|
||
|
String sign = DigestUtils.md5DigestAsHex(sb.toString().getBytes());
|
||
|
FRUtils.FRLogInfo("sign:"+sign);
|
||
|
return sign;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|