signData去掉currency试试。
b2b支付fail invalid signature 702002?wx.requestCommonPayment signData:{"amount":{"order_amount":1,"currency":"CNY"},"out_trade_no":"DD24101400002-D02","mchid":"1685170799","description":"测试测试","env":1} paySig: 87e4793a1b1b15c658539365f2d8973c30b50c2025c40c6f0a1f6da1a90242cb signature:feaa0aba736ea13a179c7f5f9aae808dec73d2fe822b58a3d432e072f90c7bde mode: 'retail_pay_goods' 报错 index.js:242 requestCommonPayment:fail webapi_wxa_createmidasorder:fail invalid signature 702002
08-05我也是签名错误卡了好久, 1、确保session_key是最新有效的; 2、postBody只传必填的部分,像currency值,去掉;生成签名时,只需要postBody,别带上uri。 [图片]
wx.requestCommonPayment 用户态签名校验失败?public static String calcSignature(String postBody, String sessionKey) { // 输入验证 if (postBody == null || postBody.isEmpty() || sessionKey == null || sessionKey.isEmpty()) { return null; } try { // 准备签名消息 byte[] needSignMsg = postBody.getBytes("UTF-8"); // 创建HMAC-SHA256实例 Mac sha256Hmac = Mac.getInstance("HmacSHA256"); SecretKeySpec secretKey = new SecretKeySpec(sessionKey.getBytes("UTF-8"), "HmacSHA256"); sha256Hmac.init(secretKey); // 生成签名 byte[] hash = sha256Hmac.doFinal(needSignMsg); // 将字节数组转换为十六进制字符串 StringBuilder hexString = new StringBuilder(); for (byte b : hash) { String hex = Integer.toHexString(0xFF & b); if (hex.length() == 1) { hexString.append('0'); } hexString.append(hex); } // 返回签名 return hexString.toString(); } catch (NoSuchAlgorithmException | InvalidKeyException | java.io.UnsupportedEncodingException e) { System.err.println("生成签名时发生错误: " + e.getMessage()); return null; } } String signature = calcSignature(JSON.toJSONString(signData), sessionKey); 为什么还是签名校验失败,返回requestCommonPayment:fail webapi_wxa_createmidasorder:fail invalid signature" 702002。 哪里需要修改呢?
08-05