mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-11-01 11:38:27 +08:00
Merge pull request #242 from videome/pay-result-bug
Fix the bug that fails to query order due to sign error.
This commit is contained in:
@ -921,19 +921,20 @@ public class WxMpServiceImpl implements WxMpService {
|
|||||||
SortedMap<String, String> packageParams = new TreeMap<String, String>();
|
SortedMap<String, String> packageParams = new TreeMap<String, String>();
|
||||||
packageParams.put("appid", wxMpConfigStorage.getAppId());
|
packageParams.put("appid", wxMpConfigStorage.getAppId());
|
||||||
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
|
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
|
||||||
|
if (transactionId != null && !"".equals(transactionId.trim()))
|
||||||
packageParams.put("transaction_id", transactionId);
|
packageParams.put("transaction_id", transactionId);
|
||||||
|
else if (outTradeNo != null && !"".equals(outTradeNo.trim()))
|
||||||
packageParams.put("out_trade_no", outTradeNo);
|
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("nonce_str", nonce_str);
|
||||||
|
packageParams.put("sign", WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey()));
|
||||||
|
|
||||||
String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey());
|
StringBuilder request = new StringBuilder("<xml>");
|
||||||
String xml = "<xml>" +
|
for (Entry<String, String> para : packageParams.entrySet()) {
|
||||||
"<appid>" + wxMpConfigStorage.getAppId() + "</appid>" +
|
request.append(String.format("<%s>%s</%s>", para.getKey(), para.getValue(), para.getKey()));
|
||||||
"<mch_id>" + wxMpConfigStorage.getPartnerId() + "</mch_id>" +
|
}
|
||||||
"<transaction_id>" + transactionId + "</transaction_id>" +
|
request.append("</xml>");
|
||||||
"<out_trade_no>" + outTradeNo + "</out_trade_no>" +
|
|
||||||
"<nonce_str>" + nonce_str + "</nonce_str>" +
|
|
||||||
"<sign>" + sign + "</sign>" +
|
|
||||||
"</xml>";
|
|
||||||
|
|
||||||
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery");
|
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery");
|
||||||
if (httpProxy != null) {
|
if (httpProxy != null) {
|
||||||
@ -941,7 +942,7 @@ public class WxMpServiceImpl implements WxMpService {
|
|||||||
httpPost.setConfig(config);
|
httpPost.setConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringEntity entity = new StringEntity(xml, Consts.UTF_8);
|
StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8);
|
||||||
httpPost.setEntity(entity);
|
httpPost.setEntity(entity);
|
||||||
try {
|
try {
|
||||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||||
@ -951,9 +952,8 @@ public class WxMpServiceImpl implements WxMpService {
|
|||||||
WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent);
|
WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent);
|
||||||
return wxMpPayResult;
|
return wxMpPayResult;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException("Failed to query order due to IO exception.", e);
|
||||||
}
|
}
|
||||||
return new WxMpPayResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -13,6 +13,11 @@ import java.io.Serializable;
|
|||||||
* @author ukid
|
* @author ukid
|
||||||
*/
|
*/
|
||||||
public class WxMpPayResult implements Serializable {
|
public class WxMpPayResult implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -570934170727777190L;
|
||||||
|
|
||||||
private String return_code;
|
private String return_code;
|
||||||
private String return_msg;
|
private String return_msg;
|
||||||
private String appid;
|
private String appid;
|
||||||
@ -23,6 +28,7 @@ public class WxMpPayResult implements Serializable {
|
|||||||
private String err_code;
|
private String err_code;
|
||||||
private String err_code_des;
|
private String err_code_des;
|
||||||
private String trade_state;
|
private String trade_state;
|
||||||
|
private String trade_state_desc;
|
||||||
private String device_info;
|
private String device_info;
|
||||||
private String openid;
|
private String openid;
|
||||||
private String is_subscribe;
|
private String is_subscribe;
|
||||||
@ -212,4 +218,40 @@ public class WxMpPayResult implements Serializable {
|
|||||||
this.time_end = time_end;
|
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