calcSignature(JSON.toJSONString(signData), sessionKey); 这里的signData就是传给小程序接口的signData字段
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。 哪里需要修改呢?
2024-10-21楼主 你的signature怎么计算的 用的java嘛
调用B2B支付方法 wx.requestCommonPayment 没有任何反应?B2B支付调用requestCommonPayment方法,传入官方示例参数,调用后没有任何反应,success/fail 没有输出任何信息呢? 当前微信已经完成了b2b认证。 wx.requestCommonPayment({ signData: JSON.stringify({ mchid: '1234567890', out_trade_no: 'test1244', description: '测试测试', amount: { order_amount: 1, currency: 'CNY' }, attach: 'test_attach', product_info: { product_list: [{ spu_id: 'spu123456', sku_id: 'sku123', title: 'QQ长鹅', path: 'pages/index', head_img: 'https://mp.weixin.qq.com/123', category: '玩偶', sku_attr: '50cm', org_price: 5000, sale_price: 4000, quantity: 5 }] }, delivery_type: 2, env: 0 }), paySig: 'd0b8bbccbe109b11549bcfd6602b08711f46600965253a949cd6a2b895152f9d', signature: 'd0b8bbccbe109b11549bcfd6602b08711f46600965253a949cd6a2b895152f9d', mode: 'retail_pay_goods', success(res) { console.log('requestCommonPayment success', res) }, fail({ errMsg, errno }) { console.error(errMsg, errno) }, })
2024-10-21