|
@@ -63,37 +63,29 @@ public class WxApiService {
|
|
|
map.put("totalSize", 1);
|
|
|
return ResultVoUtil.success(map);
|
|
|
}
|
|
|
-
|
|
|
String patientId = "%" + param.getPatientId() + "%";
|
|
|
String patientName = "%" + param.getPatientName() + "%";
|
|
|
String orderType = param.getOrderType() == -1 ? "%%" : "%" + param.getOrderType() + "%";
|
|
|
-
|
|
|
if (param.getPayStatus().equals("-1")) {
|
|
|
param.setPayStatus("99,0,1,2,3,4,5,6,7");
|
|
|
}
|
|
|
-
|
|
|
String[] statuses = param.getPayStatus().split(",");
|
|
|
-
|
|
|
String start = param.getStart() + " 00:00:00";
|
|
|
String end = param.getEnd() + " 23:59:59";
|
|
|
-
|
|
|
if (null != param.getFrom() && param.getFrom() == 1) {
|
|
|
List<WxOrderForExportExcel> list = dao.selectOrdersByConditionsForMeSelf(patientId, patientName, orderType, statuses, start, end);
|
|
|
map.put("list", list);
|
|
|
map.put("totalSize", list.size());
|
|
|
return ResultVoUtil.success(map);
|
|
|
}
|
|
|
-
|
|
|
List<WxPayOrder> list = dao.selectOrdersByConditions(patientId, patientName, orderType, statuses, start, end);
|
|
|
if (null == list || list.isEmpty()) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
|
|
|
}
|
|
|
-
|
|
|
int startSize = (param.getCurrentPage() - 1) * param.getPageSize();
|
|
|
if (startSize > list.size()) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "数据起始位大于数据总数量");
|
|
|
}
|
|
|
-
|
|
|
int endSize = param.getCurrentPage() * param.getPageSize();
|
|
|
if (endSize > list.size()) {
|
|
|
endSize = list.size();
|
|
@@ -132,28 +124,26 @@ public class WxApiService {
|
|
|
"<sign>" + refundSign + "</sign>" +
|
|
|
"</xml>";
|
|
|
String str = requestWithSsl(xml);
|
|
|
- try {
|
|
|
- assert str != null;
|
|
|
- Document document = DocumentHelper.parseText(str);
|
|
|
- Element root = document.getRootElement();
|
|
|
- if (root.element("return_code").getStringValue().equals("SUCCESS")) {
|
|
|
- Element refundIdEle = root.element("refund_id");
|
|
|
- if (null == refundIdEle) {
|
|
|
- return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, root.element("err_code_des").getStringValue()));
|
|
|
+ Document document = DocumentHelper.parseText(str);
|
|
|
+ Element root = document.getRootElement();
|
|
|
+ if (root.element("return_code").getStringValue().equals("SUCCESS")) {
|
|
|
+ Element refundIdEle = root.element("refund_id");
|
|
|
+ if (null == refundIdEle) {
|
|
|
+ String msg = root.element("err_code_des").getStringValue();
|
|
|
+ log.info("微信退款失败:{}", msg);
|
|
|
+ if (msg.equals("订单已全额退款")) {
|
|
|
+ dao.alreadyRefund(param.getId(), msg);
|
|
|
}
|
|
|
- param.setRefundId(refundIdEle.getStringValue());
|
|
|
- dao.updateRefundId(param);
|
|
|
- log.info("微信退款成功:{}", param);
|
|
|
- return CompletableFuture.completedFuture(ResultVoUtil.success(param.getRefundId()));
|
|
|
- } else {
|
|
|
- final String message = root.element("return_msg").getStringValue();
|
|
|
- log.info("微信退款失败:{}", message);
|
|
|
- return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, message));
|
|
|
+ return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, msg));
|
|
|
}
|
|
|
- } catch (DocumentException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage()));
|
|
|
+ param.setRefundId(refundIdEle.getStringValue());
|
|
|
+ dao.updateRefundId(param);
|
|
|
+ log.info("微信退款成功:{}", param);
|
|
|
+ return CompletableFuture.completedFuture(ResultVoUtil.success(param.getRefundId()));
|
|
|
}
|
|
|
+ final String message = root.element("return_msg").getStringValue();
|
|
|
+ log.info("微信退款失败:{}", message);
|
|
|
+ return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, message));
|
|
|
}
|
|
|
|
|
|
private String requestWithSsl(String xml) throws Exception {
|
|
@@ -163,31 +153,25 @@ public class WxApiService {
|
|
|
InputStream certStream = wxPayUtil.getCertStream();
|
|
|
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
|
|
keyStore.load(certStream, password);
|
|
|
-
|
|
|
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
|
|
kmf.init(keyStore, password);
|
|
|
SSLContext sslContext = SSLContext.getInstance("TLS");
|
|
|
sslContext.init(kmf.getKeyManagers(), null, new SecureRandom());
|
|
|
-
|
|
|
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
|
|
|
sslContext, new String[]{"TLSv1"}, null, new DefaultHostnameVerifier());
|
|
|
-
|
|
|
connManager = new BasicHttpClientConnectionManager(
|
|
|
RegistryBuilder.<ConnectionSocketFactory>create()
|
|
|
.register("http", PlainConnectionSocketFactory.getSocketFactory())
|
|
|
.register("https", sslConnectionSocketFactory).build(),
|
|
|
null, null, null);
|
|
|
-
|
|
|
CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build();
|
|
|
String url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(6000).build();
|
|
|
httpPost.setConfig(requestConfig);
|
|
|
-
|
|
|
StringEntity postEntity = new StringEntity(xml, "UTF-8");
|
|
|
httpPost.addHeader("Content-Type", "text/xml");
|
|
|
httpPost.setEntity(postEntity);
|
|
|
-
|
|
|
HttpResponse httpResponse = httpClient.execute(httpPost);
|
|
|
HttpEntity httpEntity = httpResponse.getEntity();
|
|
|
return EntityUtils.toString(httpEntity, "UTF-8");
|