第三方调用(认证方式时效限制5分钟)该 postman 调用 url 为样例 url
请求头: Authorization
Basic
MTIzOmRjOTg0ZDY4NzJjNWZkYWFkZDllZDg4ZGE5ZmU5ZDYwZDc40TkxMzA0NWFmNjhkMjNiMzE4NzUzZTRhYTIWMDU=
请求头: Timestamp
20251014155614169
请求头加密方式:时间戳
String timestamp = new SimpleDateFormat("yyyyMMddHHmmssSsS").format(new Date());
认证加密:(其中 123 是待定,请可配置分别对应 appCode 和 secretkey)String basicAuth = getBasicAuth("123",getSignature("123",timestamp));
public static String getSignature(String secretKey,String timestamp){
try {
Mac mac = Mac.getlnstance("HmacSHA256");
mac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"),"HmacSHA256"));bytell bytes =mac.doFinal(timestamp.getBytes("UTF-8"));String SHA256= byteToHex(bytes);
StringBASE64
Base64.getEncoder().encodeToString(SHA256.getBytes("UTF-8"));String encodeStr=URLEncoder.encode(BASE64,"utf-8");
return SHA256;
}catch(Exception e){
e.printStackTrace(),
}
return "";
}
private static String getBasicAuth(String appCode, String signature)
{StringuserAndPass = appCode + ":"+ signature,
try {
"BasicreturnBase64.getEncoder().encodeToString(userAndPass.getBytes("UTF-8"));
}catch(Exception e)
{
e.printStackTrace();
return "",
}
对端传过来加密串和时间戳,根据base64解密,得到appcode,查询表里,找到appcode对应的secretkey,根据传过来的时间戳,进行加密,然后跟传过来的密文进行比对,如果一致且在有效时间范围内,则验证通过。