Browse Source

fix: openBusinessView 签名编码从 Base64 改为大写 Hex

wx.openBusinessView 签名要求 HMAC-SHA256 输出为大写十六进制字符串,
之前错误使用了 Base64 编码导致微信侧验签失败。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 1 week ago
parent
commit
a3a56c3335

+ 6 - 1
haha-service/src/main/java/com/haha/service/payment/payscore/impl/PayScoreServiceImpl.java

@@ -929,7 +929,12 @@ public class PayScoreServiceImpl implements PayScoreService {
             SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "HmacSHA256");
             mac.init(secretKey);
             byte[] signBytes = mac.doFinal(signMessage.getBytes(StandardCharsets.UTF_8));
-            sign = Base64.getEncoder().encodeToString(signBytes);
+            // openBusinessView 签名要求大写十六进制,不是 Base64
+            StringBuilder sb = new StringBuilder();
+            for (byte b : signBytes) {
+                sb.append(String.format("%02X", b));
+            }
+            sign = sb.toString();
         } catch (Exception e) {
             log.error("[支付分服务] 生成openBusinessView签名失败", e);
             throw new RuntimeException("生成签名失败", e);