mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-15 18:55:13 +08:00
Fix the bug that fails to query order due to sign error.
This commit is contained in:
@@ -897,19 +897,20 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
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()));
|
||||
|
||||
String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey());
|
||||
String xml = "<xml>" +
|
||||
"<appid>" + wxMpConfigStorage.getAppId() + "</appid>" +
|
||||
"<mch_id>" + wxMpConfigStorage.getPartnerId() + "</mch_id>" +
|
||||
"<transaction_id>" + transactionId + "</transaction_id>" +
|
||||
"<out_trade_no>" + outTradeNo + "</out_trade_no>" +
|
||||
"<nonce_str>" + nonce_str + "</nonce_str>" +
|
||||
"<sign>" + sign + "</sign>" +
|
||||
"</xml>";
|
||||
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) {
|
||||
@@ -917,7 +918,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
httpPost.setConfig(config);
|
||||
}
|
||||
|
||||
StringEntity entity = new StringEntity(xml, Consts.UTF_8);
|
||||
StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8);
|
||||
httpPost.setEntity(entity);
|
||||
try {
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
@@ -927,9 +928,8 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent);
|
||||
return wxMpPayResult;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Failed to query order due to IO exception.", e);
|
||||
}
|
||||
return new WxMpPayResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -13,6 +13,11 @@ import java.io.Serializable;
|
||||
* @author ukid
|
||||
*/
|
||||
public class WxMpPayResult implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -570934170727777190L;
|
||||
|
||||
private String return_code;
|
||||
private String return_msg;
|
||||
private String appid;
|
||||
@@ -23,6 +28,7 @@ public class WxMpPayResult implements Serializable {
|
||||
private String err_code;
|
||||
private String err_code_des;
|
||||
private String trade_state;
|
||||
private String trade_state_desc;
|
||||
private String device_info;
|
||||
private String openid;
|
||||
private String is_subscribe;
|
||||
@@ -212,4 +218,40 @@ public class WxMpPayResult implements Serializable {
|
||||
this.time_end = time_end;
|
||||
}
|
||||
|
||||
public String getTrade_state_desc() {
|
||||
return trade_state_desc;
|
||||
}
|
||||
|
||||
public void setTrade_state_desc(String trade_state_desc) {
|
||||
this.trade_state_desc = trade_state_desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WxMpPayResult{" +
|
||||
"return_code=" + return_code +
|
||||
", return_msg='" + return_msg + '\'' +
|
||||
", appid='" + appid + '\'' +
|
||||
", mch_id='" + mch_id + '\'' +
|
||||
", nonce_str='" + nonce_str + '\'' +
|
||||
", sign='" + sign + '\'' +
|
||||
", result_code='" + result_code + '\'' +
|
||||
", err_code='" + err_code + '\'' +
|
||||
", err_code_des='" + err_code_des + '\'' +
|
||||
", trade_state=" + trade_state +
|
||||
", trade_state_desc=" + trade_state_desc +
|
||||
", device_info='" + device_info + '\'' +
|
||||
", openid='" + openid + '\'' +
|
||||
", is_subscribe='" + is_subscribe + '\'' +
|
||||
", trade_type='" + trade_type + '\'' +
|
||||
", bank_type='" + bank_type + '\'' +
|
||||
", total_fee='" + total_fee + '\'' +
|
||||
", coupon_fee='" + coupon_fee + '\'' +
|
||||
", fee_type='" + fee_type + '\'' +
|
||||
", transaction_id='" + transaction_id + '\'' +
|
||||
", out_trade_no='" + out_trade_no + '\'' +
|
||||
", attach='" + attach + '\'' +
|
||||
", time_end='" + time_end + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user