java 微信扫码支付成功后回调重复

slyan 发布于 2016/12/19 15:02
阅读 1K+
收藏 0

Linux基金会免费官方培训及考试申请即将截止,戳这里申请!>>>

java 微信支付成功后,回调一直重复,下面是源代码

//微信支付
@RequestMapping({"/weixinpay.jsp"})
public void WeixinpayAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();

//得到商户订单号
String ordernum = (String)session.getAttribute("dingdan");
System.out.print("微信支付回调数据开始");
String inputLine;
String notityXml = "";
String resXml = "";

try {
while ((inputLine = request.getReader().readLine()) != null) {
notityXml += inputLine;
}
request.getReader().close();
} catch (Exception e) {
e.printStackTrace();
}

System.out.println("接收到的报文:" + notityXml);
Notify notify = new Notify();
Map m = notify.parseXmlToList2(notityXml);
WxPayResult wpr = new WxPayResult();
wpr.setAppid(m.get("appid").toString());
wpr.setBankType(m.get("bank_type").toString());
wpr.setCashFee(m.get("cash_fee").toString());
wpr.setFeeType(m.get("fee_type").toString());
wpr.setIsSubscribe(m.get("is_subscribe").toString());
wpr.setMchId(m.get("mch_id").toString());
wpr.setNonceStr(m.get("nonce_str").toString());
wpr.setOpenid(m.get("openid").toString());
wpr.setOutTradeNo(m.get("out_trade_no").toString());
wpr.setResultCode(m.get("result_code").toString());
wpr.setReturnCode(m.get("return_code").toString());
wpr.setSign(m.get("sign").toString());
wpr.setTimeEnd(m.get("time_end").toString());
wpr.setTotalFee(m.get("total_fee").toString());
wpr.setTradeType(m.get("trade_type").toString());
wpr.setTransactionId(m.get("transaction_id").toString());

System.out.println("结果---"+wpr.getResultCode());
System.out.println("dingdan="+wpr.getOutTradeNo());
if("SUCCESS".equals(wpr.getResultCode())){
//支付成功
resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>"
+ "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";
//支付成功修改订单状态
Order order = new Order();
order.setOrdernum(wpr.getOutTradeNo());
//2已支付,未确认
order.setOrder_status(2);
//1已付款
order.setPay_status(1);
//当前时间
order.setActtime(Tool.getCurrentDate1());
//修改订单状态
userimpl.UpdateOrderStatus(order);
System.out.println("SUCCESS");
}else{
resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
+ "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";

}
System.out.println("微信支付回调数据结束");
BufferedOutputStream out = new BufferedOutputStream(
response.getOutputStream());
out.write(resXml.getBytes());
out.flush();
out.close();

System.out.println("页面跳转+++++++++++++++++++++++");
//return mapping.findForward("wxgoto");

}


加载中
0
s
slyan
自己顶一下!
0
一只小桃子
一只小桃子
成功了要返回success给微信。而且就算你返回了success,也是有可能回调多次的,需要自己能够处理重复回调。
0
湖水没了
湖水没了

正常情况 至少有两次回掉

一次是发起请求的页面 的回调

一次是来自服务器的回调

0
往事如梦D
往事如梦D
wpr.getOutTradeNo()你用这个值判断下,,未处理就处理,,处理了就不理他
0
夜苍狼
夜苍狼
这情况肯定是你给回调返回的值不对,还有就是代码本来就应该考虑重复的回调
返回顶部
顶部