微信公众号支付 (四、支付结果通知)

5.1 微信支付完会返回微信支付结果。返回频率为:15/15/30/180/1800/1800/1800/1800/3600,单位:秒。

API连接:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7

当return_code为SUCCESS的时候有返回参数。接收后作出判断。

商户处理后同步返回给微信参数: 




代码如下:

HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
request = ServletActionContext.getRequest();
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String resString = XmlUtils.parseRequst(request);
String resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
if (resString != null && !"".equals(resString)) {
	resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>" + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";
}
BufferedOutputStream out = new BufferedOutputStream(Struts2Utils.getResponse().getOutputStream());
out.write(resXml.getBytes());
out.flush();
out.close();

方法parseRequst() 为request转字符串

代码如下:


public static String parseRequst(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("utf-8");
		String body = "";
		try {
			ServletInputStream inputStream = request.getInputStream();

			BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "utf-8")); // 设置编码格式“utf-8”否则获取中文为乱码
			while (true) {
				String info = br.readLine();
				if (info == null) {
					break;
				}
				if (body == null || "".equals(body)) {
					body = info;
				} else {
					body += info;
				}
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return body;
	}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值