use of me.chanjar.weixin.mp.bean.result.WxMpPayResult in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method getJSSDKPayResult.
@Override
public WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo) {
String nonce_str = System.currentTimeMillis() + "";
SortedMap<String, String> packageParams = new TreeMap<String, String>();
packageParams.put("appid", wxMpConfigStorage.getAppId());
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
if (transactionId != null && !"".equals(transactionId.trim()))
packageParams.put("transaction_id", transactionId);
else if (outTradeNo != null && !"".equals(outTradeNo.trim()))
packageParams.put("out_trade_no", outTradeNo);
else
throw new IllegalArgumentException("Either 'transactionId' or 'outTradeNo' must be given.");
packageParams.put("nonce_str", nonce_str);
packageParams.put("sign", WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey()));
StringBuilder request = new StringBuilder("<xml>");
for (Entry<String, String> para : packageParams.entrySet()) {
request.append(String.format("<%s>%s</%s>", para.getKey(), para.getValue(), para.getKey()));
}
request.append("</xml>");
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery");
if (httpProxy != null) {
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
httpPost.setConfig(config);
}
StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8);
httpPost.setEntity(entity);
try {
CloseableHttpResponse response = httpClient.execute(httpPost);
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
XStream xstream = XStreamInitializer.getInstance();
xstream.alias("xml", WxMpPayResult.class);
WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent);
return wxMpPayResult;
} catch (IOException e) {
throw new RuntimeException("Failed to query order due to IO exception.", e);
}
}
Aggregations