package cn.autoform.web.client.util;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
import java.util.Random;
|
import java.util.TreeMap;
|
|
import cn.autoform.util.tool.JSONTool;
|
import lombok.extern.slf4j.Slf4j;
|
|
/**
|
* 参数生成类
|
* @author liush
|
*
|
*/
|
@Slf4j
|
public class CscUtils {
|
|
public static Map<String, Object> getParam(Map<String, Object> p){
|
Map<String, Object> param = new TreeMap<>(p);
|
|
// param.put("id", "1000000" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%09d", new Random().nextInt(999999999)));
|
param.put("id", "1000000" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%09d", new Random().nextInt(999999999)));
|
param.put("sign", countSign(param));
|
System.out.println("param:\n{}"+param);
|
return param;
|
}
|
|
|
protected static String countSign(Map<String, Object> param) {
|
StringBuilder sb = new StringBuilder();
|
for (Map.Entry<String, Object> map : param.entrySet()) {
|
/* 拼接条件 */
|
sb.append(map.getKey())
|
.append('=')
|
.append(map.getValue())
|
.append('&');
|
}
|
sb.append("key=").append("fa5e4cca8dc79ad8aa333e867b2ecb10");
|
System.out.println("加密参数为:\n{}"+sb);
|
System.out.println("sign:\n{}"+ MD5.GetMD5Code(sb.toString()));
|
return MD5.GetMD5Code(sb.toString());
|
}
|
public static void main(String[] args) {
|
// System.out.println(MD5.GetMD5Code("dataType=1&filePaths=12&id=100000020180507710525390&token=e06b3e54e4e95fe4d1578df184f198f3&key=fa5e4cca8dc79ad8aa333e867b2ecb10"));
|
Map<String,Object> map = new HashMap<>();
|
map.put("token", "e06b3e54e4e95fe4d1578df184f198f3");
|
map.put("filePaths", "12");
|
map.put("dataType", "1");
|
System.out.println("sign:"+CscUtils.countSign(map));
|
System.out.println("---------"+JSONTool.toJson(CscUtils.getParam(map)));
|
}
|
|
}
|