微信回调接口java返回true_java 微信支付异步回调接口

1.微信支付异步回调接口

@SuppressWarnings("static-access")

@RequestMapping("callback")

@ResponseBody

public Object callback(HttpServletRequest request,HttpServletResponse response) throws Exception{

ResultBean result = new ResultBean();

String inputLine="";

String notityXml = "";

try {

while ((inputLine = request.getReader().readLine()) != null) {

notityXml += inputLine;

}

request.getReader().close();

} catch (Exception e) {

e.printStackTrace();

}

System.out.println("异步回调XML信息:"+notityXml);

if(!notityXml.isEmpty()){

//解析并读取统一下单中的参数信息

MapprepayMap = XmlUtil.getPrepayMapInfo(notityXml);

if(!prepayMap.isEmpty()){

String orderId = prepayMap.get("out_trade_no")+"";

String resCode=prepayMap.get("result_code")+"";

String returnCode=prepayMap.get("return_code")+"";

System.out.println("解析并读取统一下单中的参数信息:"+orderId+"==="+resCode+"==="+returnCode);

}

//回调中业务逻辑完毕

}else{

result.fillCode(ResultBeanCodeEnum.OPERA_FAIL);

}

}else{

result.fillCode(ResultBeanCodeEnum.OPERA_FAIL);

}

return result;

}

2.解析并读取统一下单中的参数信息工具类

//解析xml

public static  MapgetPrepayMapInfo(String Str)  {

//解析并读取统一下单中的参数信息

//1.去掉前后的xml标签

String notityXml = Str.replaceAll("?xml>", "");

System.out.println(notityXml);

//2.匹配一段一段这样的数据

Pattern pattern = Pattern.compile("");

Matcher matcher = pattern.matcher(notityXml);

//3.配置是否包含 CDATA 包裹的数据

Pattern pattern2 = Pattern.compile("!.*]");

MapmapInfo = new HashMap<>();

while(matcher.find()) {

//获取键

String key = matcher.group().replaceAll(".*/", "");

key = key.substring(0, key.length() - 1);

Matcher matcher2 = pattern2.matcher(matcher.group());

String value = matcher.group().replaceAll("?.*?>", "");

//获取值

if(matcher2.find() && !value.equals("DATA")) {

value = matcher2.group().replaceAll("!.*\\[", "");

value = value.substring(0, value.length() - 2);

}

mapInfo.put(key, value);

}

return mapInfo;

}

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页