收藏
回答

服务商下的二级商户微信平台退款,退款回调通知是v2版本,请问这种情况如何进行解密处理?

背景:公司是服务商模式,想拦截所有退款回调进行业务处理,在实际测试中发现,当二级商户发起退款时,微信平台推送的是V2版本回调通知。根据官方文档说明,该版本的回调数据中的关键字段req_info需要使用对应二级商户的APIv2密钥进行解密处理,请问这种情况该如何处理?

回答关注问题邀请回答
收藏

5 个回答

  • 支付社区运营
    支付社区运营
    07-10

    微信平台退款回调数据默认是v2版本https://pay.weixin.qq.com/doc/v2/merchant/4011935223按文档要求进行解密即可

    07-10
    有用
    回复 1
    • 民谣吉他
      民谣吉他
      07-10
      现在的情况是我是服务商,有什么办法拿到对应二级商户的密钥吗?
      07-10
      回复
  • 智能回答 智能回答 本次回答由AI生成
    07-10
    有用 1
  • 都安静点
    都安静点
    07-10

    服务商模式用服务商密钥和回调req_info解密就行


    public static String decryptRefundNotification(String reqInfoData, String apiKey) throws Exception {
        // (1)Base64解码,得到加密串B
        byte[] encryptedBytes = Base64.getDecoder().decode(reqInfoData);
    
        // (2)对商户key做MD5,得到32位小写key*
        String md5Key = md5(apiKey);
    
        // (3)用key*对加密串B做AES-256-ECB解密(PKCS7Padding)
        byte[] decryptedBytes = aes256EcbDecrypt(encryptedBytes, md5Key);
    
        return new String(decryptedBytes, StandardCharsets.UTF_8);
    }
    
    /**
     * MD5加密(返回32位小写)
     */
    private static String md5(String input) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digest = md.digest(input.getBytes(StandardCharsets.UTF_8));
    
        StringBuilder hexString = new StringBuilder();
        for (byte b : digest) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    }
    
    /**
     * AES-256-ECB/PKCS7Padding解密
     */
    private static byte[] aes256EcbDecrypt(byte[] encryptedData, String key) throws Exception {
        // 注意:Java默认不支持PKCS7Padding,但PKCS5Padding兼容PKCS7(块大小相同)
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        return cipher.doFinal(encryptedData);
    }
    


    07-10
    有用 1
    回复 1
  • Memory
    Memory
    07-10

    我就好奇二级商户怎么自己发起的退款,默认没有权限的

    07-10
    有用
    回复 4
    • 民谣吉他
      民谣吉他
      07-10
      昨天我登陆这个商户号就可以发起,不是小微商户
      07-10
      回复
    • Memory
      Memory
      07-10回复民谣吉他
      收付通二级商户?
      07-10
      回复
    • 民谣吉他
      民谣吉他
      07-10
      07-10
      回复
    • Memory
      Memory
      07-10回复民谣吉他
      可能是存量商户,解除了自己的权限授权,新申请不会有此类操作入口了
      07-10
      回复
  • 民谣吉他
    民谣吉他
    07-10

    还是说这种属于异常流程,处理不了?


    07-10
    有用
    回复
登录 后发表内容