递归火山软件开发平台
标题:
模拟JAVA算法不成功求帮忙
[打印本页]
作者:
CPUCN
时间:
昨天 22:29
标题:
模拟JAVA算法不成功求帮忙
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
public class JavaCode17 {
public static void main(String []args){
// 请求的接口地址
List<String> list = new ArrayList<>();
String api_secret = "01KKZYZBXK83GQMSHR4D200TA5";
//String param ="{\"widgetId\": \"625091800040434\",\"userInputs\": {\"taskYear\": \"2025\"}}";
String param ="{\"widgetid\":\"626031800084554\",\"userInputs\":{\"sfz\":{\"idCard\":\"123\"}}}";
//平台apiSecret参数
list.add(api_secret);
//接口入参json字符串
list.add(param);
//签名生成方式
String signatrue = hash(list);
System.out.println(signatrue);
}
public static String sha256Hash(String text) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] bytes = digest.digest(text.getBytes(StandardCharsets.UTF_8));
StringBuilder hexString = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("SHA-256 algorithm not found", e);
}
}
public static String hash(List<String> arr) {
String joinString = String.join("", arr);
System.out.println(joinString);
return sha256Hash(joinString);
}
}
就是把api_secret 和param 连接到一起,在取sha256摘要
01KKZYZBXK83GQMSHR4D200TA5{"widgetid":"626031800084554","userInputs":{"sfz":{"idCard":"123"}}}
JAVA代码计算的结果
1dbed0bc4bf26e01781cddee13f2323d51ec89b5767dbafe82e81ca7a1e3af92
用火山取数据SHA256没有得到这个值,哪个大神给看看怎么个事?
作者:
CPUCN
时间:
昨天 22:57
编辑框_签名.内容 = 到小写 (加密.取数据SHA256 (文本到UTF8 (编辑框_APISecret.内容 + 编辑框_提交内容.内容, 假)))
解决了,之前没有假,加上就好了。
欢迎光临 递归火山软件开发平台 (https://bbs.voldp.com/)
Powered by Discuz! X3.4