//异步请求回应微信支付是否成功 @Transactional public String weixinNotify(String resultStr) { log.info("=========weixinPaynotify start===="); String resXml = ""; String return_code=null; String result_code=null; try { //字节流 Map<String, String> resultMap = XMLUtil.doXMLParse(resultStr); log.info("resultMap:" + JSON.toJSONString(resultMap)); String transaction_id = resultMap.get("transaction_id"); //微信交易流水号 result_code = resultMap.get("result_code"); String out_trade_no = resultMap.get("out_trade_no"); return_code = resultMap.get("return_code"); log.info("===========================微信异步回调 来了========================"+out_trade_no); // 签名验证(在网上复制而来,不知其用处故先注释) //GenericValue userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", "admin"), false); //支付成功 修改订单状态和子订单状态 添加充电结束时间 if ("SUCCESS".equals(return_code)&&"SUCCESS".equals(result_code)) { log.info("小程序订单列表支付回调接收到了out_trade_no=========="+out_trade_no); //获取主订单 WxRechargeOrderExample wxRechargeOrderExample = new WxRechargeOrderExample(); wxRechargeOrderExample.createCriteria().andOrderNumberEqualTo(out_trade_no); WxRechargeOrder wxRechargeOrder = wxRechargeOrderMapper.selectByExample(wxRechargeOrderExample).get(0); wxRechargeOrder.setStatus(1); wxRechargeOrder.setUpdateDate(new Date()); int i = wxRechargeOrderMapper.updateByPrimaryKey(wxRechargeOrder); if( 1 == i){ //修改用户账户 WxMember wxMember = wxMemberMapper.selectByPrimaryKey(wxRechargeOrder.getMemberId()); BigDecimal addFudou = wxRechargeOrder.getFudou(); wxMember.setFudou(wxMember.getFudou().add(addFudou)); wxMember.setAmount(wxMember.getAmount().add(wxRechargeOrder.getAmount())); wxMember.setUpdateDate(new Date()); wxMemberMapper.updateByPrimaryKey(wxMember); resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>" + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> "; } }else{ resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> "; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } catch (Exception e){ e.printStackTrace(); throw new RuntimeException("微信异步回调失败!"); } return resXml; //return return_code; }
备注:有的直接返回SUCCESS就可以,有的要返回xml,具体按项目