public WeChatPayResponseData placeOrder(final WeChatPayRequestData request) { OneLevelOnlyXML xml = new OneLevelOnlyXML(); xml.createRootElement("xml"); for (StringPair param : sign(request.getSortedParameters())) { xml.createChild(param.getFirst(), param.getSecond()); } String str = xml.toXMLString(); LOG.info("Order request: {}", str); String ret = http.post("api.mch.weixin.qq.com", 443, "https", "/pay/unifiedorder", str); LOG.info("Order response: {}", ret); try { WeChatPayResponseData response = WeChatPayResponseData.parse(ret); String sign = signMD5(response.getAllData().getSorted("sign")); if (!sign.equalsIgnoreCase(response.getString("sign"))) { LOG.warn("Failed to verify sign"); return null; } if (!"SUCCESS".equalsIgnoreCase(response.getString("return_code")) || !"SUCCESS".equalsIgnoreCase(response.getString("result_code"))) { LOG.warn("Error returned {}", response.getString("return_msg")); return null; } // return response.getString("prepay_id"); response.setXml(ret); return response; } catch (UnsupportedEncodingException e) { LOG.warn("Cannot parse result", e); return null; } catch (ParserConfigurationException e) { LOG.warn("Cannot parse result", e); return null; } catch (SAXException e) { LOG.warn("Cannot parse result", e); return null; } catch (IOException e) { LOG.warn("Cannot parse result", e); return null; } }