|
8 | 8 | import me.chanjar.weixin.mp.api.WxMpPayService; |
9 | 9 | import me.chanjar.weixin.mp.api.WxMpService; |
10 | 10 | import me.chanjar.weixin.mp.bean.pay.WxPayJsSDKCallback; |
| 11 | +import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderCloseResult; |
11 | 12 | import me.chanjar.weixin.mp.bean.pay.request.*; |
12 | 13 | import me.chanjar.weixin.mp.bean.pay.result.*; |
13 | 14 | import org.apache.commons.codec.digest.DigestUtils; |
@@ -210,6 +211,39 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) |
210 | 211 | return result; |
211 | 212 | } |
212 | 213 |
|
| 214 | + @Override |
| 215 | + public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException { |
| 216 | + if (StringUtils.isBlank(outTradeNo)) { |
| 217 | + throw new IllegalArgumentException("out_trade_no 不能为空"); |
| 218 | + } |
| 219 | + |
| 220 | + XStream xstream = XStreamInitializer.getInstance(); |
| 221 | + xstream.processAnnotations(WxPayOrderCloseRequest.class); |
| 222 | + xstream.processAnnotations(WxPayOrderCloseResult.class); |
| 223 | + |
| 224 | + WxPayOrderCloseRequest request = new WxPayOrderCloseRequest(); |
| 225 | + request.setOutTradeNo(StringUtils.trimToNull(outTradeNo)); |
| 226 | + request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId()); |
| 227 | + request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId()); |
| 228 | + request.setNonceStr(System.currentTimeMillis() + ""); |
| 229 | + |
| 230 | + String sign = this.createSign(BeanUtils.xmlBean2Map(request), |
| 231 | + this.wxMpService.getWxMpConfigStorage().getPartnerKey()); |
| 232 | + request.setSign(sign); |
| 233 | + |
| 234 | + String url = PAY_BASE_URL + "/pay/closeorder"; |
| 235 | + |
| 236 | + String responseContent = this.wxMpService.post(url, xstream.toXML(request)); |
| 237 | + WxPayOrderCloseResult result = (WxPayOrderCloseResult) xstream.fromXML(responseContent); |
| 238 | + if ("FAIL".equals(result.getResultCode())) { |
| 239 | + throw new WxErrorException(WxError.newBuilder() |
| 240 | + .setErrorMsg(result.getErrCode() + ":" + result.getErrCodeDes()) |
| 241 | + .build()); |
| 242 | + } |
| 243 | + |
| 244 | + return result; |
| 245 | + } |
| 246 | + |
213 | 247 | @Override |
214 | 248 | public WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) |
215 | 249 | throws WxErrorException { |
|
0 commit comments