小程序
小游戏
企业微信
微信支付
扫描小程序码分享
背景:公司是服务商模式,想拦截所有退款回调进行业务处理,在实际测试中发现,当二级商户发起退款时,微信平台推送的是V2版本回调通知。根据官方文档说明,该版本的回调数据中的关键字段req_info需要使用对应二级商户的APIv2密钥进行解密处理,请问这种情况该如何处理?
5 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
微信平台退款回调数据默认是v2版本https://pay.weixin.qq.com/doc/v2/merchant/4011935223按文档要求进行解密即可
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
本回答由AI生成,可能已过期、失效或不适用于当前情形,请谨慎参考
服务商模式用服务商密钥和回调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); }
我就好奇二级商户怎么自己发起的退款,默认没有权限的
还是说这种属于异常流程,处理不了?
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
微信平台退款回调数据默认是v2版本https://pay.weixin.qq.com/doc/v2/merchant/4011935223按文档要求进行解密即可
服务商模式用服务商密钥和回调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); }
我就好奇二级商户怎么自己发起的退款,默认没有权限的
还是说这种属于异常流程,处理不了?