@WebServlet("/ActionServlet")
public class PayWxOrderingReqCBS extends HttpServlet {
public PayWxOrderingReqCBS() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String msg = "success";
response.setContentType("text/xml");
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);
System.out.println("微信支付回调数据结束");
System.out.println("告知服务端订单情况");
String b = Xml2JsonUtil.xml2JSON(notityXml);
System.out.println("=======================>"+b);
try {
JSONObject c = new JSONObject(b);
String d = c.get("xml").toString();
JSONObject e = new JSONObject(d);
String f = e.get("return_code").toString();
if (f.contains("SUCCESS")) {
/** 告知订单状态,修改订单状态 */
具体业务
}
} catch (JSONException e) {
e.printStackTrace();
} catch (SwordBaseCheckedException e) {
e.printStackTrace();
}
resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>"
+ "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";
BufferedOutputStream out = new BufferedOutputStream(
response.getOutputStream());
out.write(resXml.getBytes());
out.flush();
out.close();
response.getWriter().println(msg);
}