|
@@ -378,12 +378,48 @@ public class WxApiService {
|
|
|
JSONObject retObj = JSONObject.parseObject(ret);
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("qrcodeUrl", retObj.getString("code_url"));
|
|
|
- map.put("tradeNo", outTradeNo);
|
|
|
+ map.put("tradeNo", order.getTradeNo());
|
|
|
+ map.put("serialNo", order.getSerialNo());
|
|
|
return ResultVoUtil.success(map);
|
|
|
}
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请求微信支付二维码失败,请联系管理员。");
|
|
|
}
|
|
|
|
|
|
+ public ResultVo<String> closeWxOrder(WxPayOrder order) throws Exception {
|
|
|
+ Integer payStatus = dao.selectOrderStatus(order.getTradeNo());
|
|
|
+ if (null == payStatus) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "订单不存在,请检查订单号是否正确。");
|
|
|
+ }
|
|
|
+ if (2 == payStatus) {
|
|
|
+ return ResultVoUtil.success("订单已是关闭状态,请勿重复关闭订单。");
|
|
|
+ }
|
|
|
+ String url = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/" + order.getTradeNo() + "/close";
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ body.put("mchid", PropertiesUtil.getProperty("mchId"));
|
|
|
+ String reqdata = JSONObject.toJSONString(body);
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ StringEntity entity = new StringEntity(reqdata, StandardCharsets.UTF_8);
|
|
|
+ entity.setContentEncoding("UTF-8");
|
|
|
+ entity.setContentType("application/json");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ httpPost.addHeader("Accept", "application/json");
|
|
|
+ CloseableHttpClient httpClient = WxHttpUtil.getClosableHttpClient();
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+ log.info("关闭微信订单:{},结果:{}", order.getTradeNo(), statusCode);
|
|
|
+ if (statusCode == 204) {
|
|
|
+ httpClient.close();
|
|
|
+ dao.updatePayStatusOnly(order.getTradeNo(), 2);
|
|
|
+ return ResultVoUtil.success("关闭订单成功。");
|
|
|
+ }
|
|
|
+ if (null != response.getEntity()) {
|
|
|
+ String ret = EntityUtils.toString(response.getEntity());
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, ret);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "关闭订单失败。");
|
|
|
+ }
|
|
|
+
|
|
|
public ResultVo<DoctorInfo> getDoctorInfo(String doctorCode) {
|
|
|
DoctorInfo doctorInfo = dao.selectDoctorInfo(doctorCode);
|
|
|
if (null == doctorInfo) {
|