参数:
access_token:75_gEaJ6FVh4U0_T4atz5HrDg0cSOQykKIyozZbxK1p2iYTzOKtExG-Fa0OYBophybNCF82wHcqz_PIS96dxmNIuvKS4bML5-t_QxjC5dJj4wbigCNUVAjerrhQzsURHYbAGAVLC
openid:oZeIR0WhrKYK4sUde-ETXObpc-I0
signature:50caaa4f05bba1efae62481513d09c659081c873134711cbc0d5fd40d5e003f7
sig_method:hmac_sha256
执行结果:
{
"errcode": 87009,
"errmsg": "invalid signature rid: 656eed48-7a430bd4-2b0aa80f",
"key_info_list": []
}
我确认access_token、openid都是正确无误的,signature的实现代码如下:
public static void main(String[] args) {
try {
String secretKey = "vTLGsnYI6fqOFqRmTocWlQ=="; // 替换为实际的密钥
String data = ""; // 空串
// 使用HMAC SHA-256算法
Mac sha256Hmac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
sha256Hmac.init(secretKeySpec);
// 计算HMAC值
byte[] hmacBytes = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8));
// 将HMAC值转换为小写的hex字符串
StringBuilder hexStringBuilder = new StringBuilder();
for (byte b : hmacBytes) {
hexStringBuilder.append(String.format("%02x", b));
}
String hexHmac = hexStringBuilder.toString();
System.out.println("HMAC SHA-256: " + hexHmac);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
e.printStackTrace();
}
}
尝试了很多遍,大写小写各种都试过了,就是不行,invalid signature,恳请官方有没有人给看一看,找不到其他问题了,也不知道那从哪开始排查问题了