我遵循文档和示例缩放示例签名在springboot中创建端点以生成签名。我能够用api key&secret成功创建签名。但是,当我尝试使用签名加入时,会显示一个错误“会议号码错误”。node js代码运行良好。
这是我的片段
@PostMapping("/signature")
public ResponseEntity<?> generateSignature(String meetingNumber, Integer role) {
try {
Mac hasher = Mac.getInstance("HmacSHA256");
String ts = Long.toString(System.currentTimeMillis() - 30000);
String msg = String.format("%s%s%s%d", API_KEY, meetingNumber, ts, role);
hasher.init(new SecretKeySpec(API_SECRET.getBytes(), "HmacSHA256"));
String message = Base64.getEncoder().encodeToString(msg.getBytes());
byte[] hash = hasher.doFinal(message.getBytes());
String hashBase64Str = DatatypeConverter.printBase64Binary(hash);
String tmpString = String.format("%s.%s.%s.%d.%s", API_KEY, meetingNumber, ts, role, hashBase64Str);
String encodedString = Base64.getEncoder().encodeToString(tmpString.getBytes());
return ResponseEntity.ok()
.body(ApiResponse.success(encodedString.replaceAll("\\=+$", "")));
}
catch (NoSuchAlgorithmException e) {
return ResponseEntity.badRequest()
.body(ApiResponse.error("Error creating signature"));
}
catch (InvalidKeyException e) {
return ResponseEntity.badRequest()
.body(ApiResponse.error("Error creating signature"));
}
}
暂无答案!
目前还没有任何答案,快来回答吧!