微信退款结果通知

先理清思路

一  首先在微信商户平台配置,退款结果通知回调路径,这个和支付结果通知一样。微信返回的消息也是流信息,需要解析。

二 接下来按照微信开发文档进行解析流,得到返回数据

三 根据返回数据进行操作,推送模板消息之类的

下面代码,注意编码格式

第一步:解析微信返回的流

InputStream inStream;
inStream = request.getInputStream();
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
    outSteam.write(buffer, 0, len);
}

outSteam.close();
inStream.close();
String result = new String(outSteam.toByteArray(), "utf-8");// 获取微信调用我们notify_url的返回信息
Map<Object, Object> m = null;
try {
//将xml格式转换为map格式
    m = XmlUtil.xml2map(result, false);
} catch (DocumentException e) {
    e.printStackTrace();
}
//获取加密信息
String a = m.get("req_info").toString();
第二部 接下来解码加密信息

(1)对加密串A做base64解码,得到加密串B

public static byte[] decode(String key) throws Exception { System.out.println(new BASE64Decoder().decodeBuffer(key)); return new BASE64Decoder().decodeBuffer(key); }

(2)对商户key做md5,得到32位小写key* ( key设置路径:微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置 )

 
 
private static SecretKeySpec key = new SecretKeySpec(MD5Util.MD5Encode(password, "UTF-8").toLowerCase().getBytes(), ALGORITHM);

 
 
public static String decryptData(String base64Data) throws Exception {
    Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
    cipher.init(Cipher.DECRYPT_MODE, key);
    return new String(cipher.doFinal(decode(base64Data)),"UTF-8");
}
这样得到String B = decryptData(a);B就是解密后的信息,是xml格式,需要再次转化成map。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值