提交 c4c96a41 authored 作者: hzh's avatar hzh

关闭订单功能实现

上级 f4d6c0f5
...@@ -19,11 +19,20 @@ public interface IWxPayService { ...@@ -19,11 +19,20 @@ public interface IWxPayService {
/** /**
* 微信支付查询 * 微信支付查询
*
* @param outTradeNo 【商户订单号】 商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一。 * @param outTradeNo 【商户订单号】 商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一。
* @return 支付结果 * @return 支付结果
*/ */
JsapiNotifyModel query(String outTradeNo); JsapiNotifyModel query(String outTradeNo);
/**
* 关闭订单
*
* @param outTradeNo 关闭订单
* @return 是否成功
*/
Boolean close(String outTradeNo);
/** /**
* 自动获取证书 * 自动获取证书
* *
......
...@@ -258,10 +258,45 @@ public class WxPayServiceImpl implements IWxPayService { ...@@ -258,10 +258,45 @@ public class WxPayServiceImpl implements IWxPayService {
return JSON.parseObject(JSON.toJSONString(result), JsapiNotifyModel.class); return JSON.parseObject(JSON.toJSONString(result), JsapiNotifyModel.class);
} }
} }
throw new RuntimeException("订单" + outTradeNo + "查询失败!"); throw new RuntimeException("订单" + outTradeNo + "查询失败!");
} catch (Exception e) { } catch (Exception e) {
log.error("系统异常", e); log.error("系统异常", e);
throw new RuntimeException("订单" + outTradeNo + "查询失败!"); throw new RuntimeException("订单:" + outTradeNo + "查询失败!");
}
}
@Override
public Boolean close(String outTradeNo) {
try {
Map<String, String> params = new HashMap<>(16);
params.put("mchid", config.getMchId());
log.info("关闭订单,订单编号:{}", outTradeNo);
IJPayHttpResponse response = WxPayApi.v3(
RequestMethodEnum.POST,
WxDomainEnum.CHINA.toString(),
String.format(BasePayApiEnum.CLOSE_ORDER_BY_OUT_TRADE_NO.toString(), outTradeNo),
config.getMchId(),
getSerialNumber(),
null,
config.getKeyPath(),
JSONUtil.toJsonStr(params));
log.info("关闭订单:{} 查询响应 {}", outTradeNo, response);
if (response.getStatus() == IJPayConstants.CODE_200) {
// 根据证书序列号查询对应的证书来验证签名结果
boolean verifySignature = WxPayKit.verifySignature(response, config.getPlatformCertPath());
log.info("verifySignature: {}", verifySignature);
//验签成功
if (verifySignature) {
return true;
} else {
return false;
}
}
throw new RuntimeException("订单:" + outTradeNo + "关闭失败!");
} catch (Exception e) {
log.error("系统异常", e);
throw new RuntimeException("订单:" + outTradeNo + "关闭失败!");
} }
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论