商管系统联调说明
一、通信方式
商管系统接口调用统一使用HTTP方式通信。
二、协议规则
💡
2.1 报文格式
代理商与易生间的报文采用key/value的表单方式通过HTTP Post提交。
报文后续可能会新增字段,服务商应对新增的字段不敏感,若服务商不关心该字段,可直 接丢弃。
💡
2.2 字符编码
统一采用 UTF-8 格式编码:单个中文字符长度为两个字节、英文或数字字符为一个字节。
📌
2.3 报文签名与验签
- 代理商对应的秘钥由易生生成,和机构号(clientCode)一起下发;
- 对于报文的签名处理机制如下:
首先,对报文出现的签名域(MAC)之外的所有数据元按照key(忽略大小写)的ascii顺序排序,并 以&作为连接符拼接成待签名串(即key1=value1&key2=value2…),最后将自己的私钥拼接在报文待签名字符串最后(key=md5)。然后对待签名串使用MD5做签名操作(签名字符串都是大写)。 - 对于报文的验签处理机制:
首先,对报文出现的签名域(MAC)之外的所有数据元按照key的ascii顺序排序,并 以&作为连接符拼接成待签名串(即key1=value1&key2=value2…),最后将代理商的私钥拼接在报文待签名字符串最后(key=md5)。然后对待签名串使用MD5加密与报文中的签名信息做比较,验证报文的一致性; - 签名代码
鉴权签名
/**
- 鉴权签名
/
public static String getSign(String key, Map<String, String> map, String encode) {
ArrayList list = new ArrayList();
for (Map.Entry<String, String>entry : map.entrySet()) {
if (StringUtils.isNotBlank(entry.getValue())) {//空值不参与加密
list.add(entry.getKey() + "=" + entry.getValue() + "&");// key=value+
}
}
int size = list.size();
String[] arrayToSort = list.toArray(new String[size]);
Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < size; i++) {
sb.append(arrayToSort[i]);
}
String result = sb.toString();
result += "key=" + key;
try {
logger.info("md5之前:\n"+result);
result = MD5Util.crypt(result, encode);
logger.info(result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/* - Encodes a string 2 MD5
- @param str String to encode
- @return Encoded String
- @throws NoSuchAlgorithmException
- @throws UnsupportedEncodingException
*/
public static String crypt(String str, String encode) throws NoSuchAlgorithmException, UnsupportedEncodingException {
if (str == null || str.length() == 0) {
throw new IllegalArgumentException("String to encript cannot be null or zero length");
}
StringBuffer hexString = new StringBuffer();
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes(encode));
byte[] hash = md.digest();
for (int i = 0; i < hash.length; i++) {
if ((0xff & hash[i]) < 0x10) {
hexString.append("0" + Integer.toHexString((0xFF & hash[i])));
} else {
hexString.append(Integer.toHexString(0xFF & hash[i]));
}
}
return hexString.toString().toUpperCase();
}
修改于 2023-05-19 02:24:21