栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringMvc微信支付回调示例代码

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringMvc微信支付回调示例代码

介绍

大家都知道微信支付的回调链接要求不能跟参数,但又要接收返回的xml数据。我开始使用@RequestBody注解在参数上,希望能获取xml数据,测试失败。最后使用HttpServletRequest去获取数据成功了。

示例代码

@RequestMapping("/weixinpay/callback")
public String callBack(HttpServletRequest request){
 InputStream is = request.getInputStream();
 String xml = StreamUtil.inputStream2String(is, "UTF-8")
 
}

public static String inputStream2String(InputStream inStream, String encoding){
 String result = null;
 try {
 if(inStream != null){
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  byte[] tempBytes = new byte[_buffer_size];
  int count = -1;
  while((count = inStream.read(tempBytes, 0, _buffer_size)) != -1){
    outStream.write(tempBytes, 0, count);
  }
  tempBytes = null;
  outStream.flush();
  result = new String(outStream.toByteArray(), encoding);
 }
 } catch (Exception e) {
 result = null;
 }
 return result;
}

总结

以上就是这篇文章的全部内容了,希望能对大家的学习或者工作带来一定的帮助,如果有疑问大家可以留言交流。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/149062.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号