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;
}