mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-01 04:28:02 +08:00
停车平台计算sign
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
package com.jsowell.common.core.domain.parking;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停车场公告参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ParkingCommonParam {
|
||||||
|
/**
|
||||||
|
* 服务名称
|
||||||
|
*/
|
||||||
|
private String service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本
|
||||||
|
*/
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息ID(唯一)
|
||||||
|
*/
|
||||||
|
private String msgId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机构ID(分配)
|
||||||
|
*/
|
||||||
|
private String orgId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 具体业务接口json对象
|
||||||
|
*/
|
||||||
|
private Map<String, String> data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求签名
|
||||||
|
*/
|
||||||
|
private String sign;
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.jsowell.common.util;
|
||||||
|
|
||||||
|
import com.jsowell.common.util.sign.MD5Util;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停车平台工具类
|
||||||
|
*/
|
||||||
|
public class ParkingUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算sign
|
||||||
|
*/
|
||||||
|
public static String generateSign(Map<String, String> publicParams, Map<String, String> businessParams, String secretKey) {
|
||||||
|
// Step 1: 过滤空值并按照ASCII码排序公共参数
|
||||||
|
StringBuilder stringA = new StringBuilder();
|
||||||
|
publicParams.entrySet().stream()
|
||||||
|
.filter(entry -> entry.getValue() != null && !entry.getValue().isEmpty())
|
||||||
|
.sorted(Map.Entry.comparingByKey())
|
||||||
|
.forEach(entry -> stringA.append(entry.getKey()).append("=").append(entry.getValue()).append("|"));
|
||||||
|
|
||||||
|
// 去除最后的“|”符号
|
||||||
|
// if (stringA.length() > 0) {
|
||||||
|
// stringA.deleteCharAt(stringA.length() - 1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Step 2: 过滤空值并按照ASCII码排序业务参数
|
||||||
|
StringBuilder stringB = new StringBuilder();
|
||||||
|
businessParams.entrySet().stream()
|
||||||
|
.filter(entry -> entry.getValue() != null && !entry.getValue().isEmpty())
|
||||||
|
.sorted(Map.Entry.comparingByKey())
|
||||||
|
.forEach(entry -> stringB.append(entry.getKey()).append("=").append(entry.getValue()).append("|"));
|
||||||
|
|
||||||
|
// 去除最后的“|”符号
|
||||||
|
// if (stringB.length() > 0) {
|
||||||
|
// stringB.deleteCharAt(stringB.length() - 1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Step 3: 拼接字符串A、B和机构密钥
|
||||||
|
String stringC = stringA.toString() + stringB.toString() + secretKey;
|
||||||
|
|
||||||
|
// Step 4: 对字符串C进行MD5加密并返回小写的签名
|
||||||
|
return MD5Util.MD5Encode(stringC).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 模拟公共请求参数
|
||||||
|
Map<String, String> publicParams = new HashMap<>();
|
||||||
|
publicParams.put("service", "getOwner");
|
||||||
|
publicParams.put("version", "01");
|
||||||
|
publicParams.put("msgId", "f719b06d-210b-4989-9c7f-02e85f22fe01");
|
||||||
|
publicParams.put("orgId", "BTTEST01");
|
||||||
|
|
||||||
|
// 模拟业务请求参数
|
||||||
|
Map<String, String> businessParams = new HashMap<>();
|
||||||
|
businessParams.put("parkId", "11609");
|
||||||
|
businessParams.put("phone", "13148762240");
|
||||||
|
businessParams.put("name", "pasika");
|
||||||
|
businessParams.put("address", "测试");
|
||||||
|
|
||||||
|
// 机构密钥
|
||||||
|
String secretKey = "K9OGNA7CIY8N5GXD8HF3WVDMEZNFKL3F";
|
||||||
|
|
||||||
|
// 计算签名
|
||||||
|
String sign = generateSign(publicParams, businessParams, secretKey);
|
||||||
|
System.out.println("Generated Sign: " + sign);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user