|
@@ -13,18 +13,13 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
|
|
|
import thyyxxk.wxservice_server.dao.WxApiDao;
|
|
|
-import thyyxxk.wxservice_server.pojo.HrgResponse;
|
|
|
import thyyxxk.wxservice_server.pojo.ResultVo;
|
|
|
import thyyxxk.wxservice_server.pojo.wxapi.JsApiSHA1;
|
|
|
import thyyxxk.wxservice_server.pojo.appointment.WeChatPayParam;
|
|
|
-import thyyxxk.wxservice_server.pojo.wxapi.PaymentNotify;
|
|
|
import thyyxxk.wxservice_server.pojo.wxapi.WxPayOrderPojo;
|
|
|
import thyyxxk.wxservice_server.utils.*;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.security.GeneralSecurityException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.TreeMap;
|
|
@@ -62,7 +57,7 @@ public class WxApiService {
|
|
|
String tradeNo = SnowFlakeId.instance().nextId();
|
|
|
String nonceStr = SnowFlakeId.instance().nextId();
|
|
|
String totalFee = DecimalTool.moneyYuanToFen(param.getTotalFee());
|
|
|
- String notifyUrl = "http://staticweb.hnthyy.cn/wxserver/wxApi/paymentNotify2";
|
|
|
+ String notifyUrl = "http://staticweb.hnthyy.cn/wxserver/wxPayNotify/notify2";
|
|
|
TreeMap<String, String> map = new TreeMap<>();
|
|
|
map.put("appid", appId);
|
|
|
map.put("mch_id", merchantId);
|
|
@@ -141,27 +136,22 @@ public class WxApiService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public ResultVo<String> updatePayStatus(String tradeNo, Integer status) {
|
|
|
- String successTime = getDatetime();
|
|
|
- if (status == 1) {
|
|
|
- WxPayOrderPojo order = dao.selectOrderByTradeNo(tradeNo);
|
|
|
- if (null != order && null != order.getHisOrdNum()) {
|
|
|
- HrgResponse hrgResponse = confirmPayStatus(tradeNo, successTime, order);
|
|
|
- if (null == hrgResponse) {
|
|
|
- dao.updatePayStatus(tradeNo, 3, successTime);
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您已支付成功,但是更新订单状态失败。" +
|
|
|
- "请联系管理员手动更新或者退费。");
|
|
|
- }
|
|
|
- if (hrgResponse.getResultCode() == -1) {
|
|
|
- dao.updatePayStatus(tradeNo, 3, successTime);
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您已支付成功,但是更新订单状态失败。" +
|
|
|
- "请联系管理员手动更新或者退费。");
|
|
|
- }
|
|
|
- }
|
|
|
+ public ResultVo<String> autoRefund(String tradeNo, String reason) {
|
|
|
+ WxPayOrderPojo order = dao.selectOrderByTradeNo(tradeNo);
|
|
|
+ if (null == order) {
|
|
|
+ log.info("自动退款失败,未找到订单号为【{}】的订单。", tradeNo);
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR);
|
|
|
}
|
|
|
- dao.updatePayStatus(tradeNo, status, successTime);
|
|
|
- log.info("更新订单状态:{},{}", tradeNo, status);
|
|
|
- return ResultVoUtil.success("更新订单状态成功。");
|
|
|
+ String url = "http://webhis.thyy.cn:8706/wxRefund/refundOrder";
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("id", order.getId());
|
|
|
+ param.put("refundDatetime", DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ param.put("totalFee", order.getTotalFee());
|
|
|
+ param.put("tradeNo", tradeNo);
|
|
|
+ param.put("refundOpCode", "99999");
|
|
|
+ param.put("refundReason", reason);
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ return template.postForObject(url, param, ResultVo.class);
|
|
|
}
|
|
|
|
|
|
private RestTemplate getRestTemplate() {
|
|
@@ -175,60 +165,4 @@ public class WxApiService {
|
|
|
}
|
|
|
return restTemplate;
|
|
|
}
|
|
|
-
|
|
|
- public void paymentNotify(PaymentNotify param) throws GeneralSecurityException, IOException {
|
|
|
- log.info("微信支付通知: {}", param);
|
|
|
- String nonce = param.getResource().getNonce();
|
|
|
- String associatedData = param.getResource().getAssociated_data();
|
|
|
- String ciphertext = param.getResource().getCiphertext();
|
|
|
- ciphertext = WxPaySignUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8),
|
|
|
- nonce.getBytes(StandardCharsets.UTF_8), ciphertext);
|
|
|
- JSONObject cipherObj = JSONObject.parseObject(ciphertext);
|
|
|
- log.info("微信支付通知解密:{}", ciphertext);
|
|
|
- JSONObject payer = cipherObj.getJSONObject("payer");
|
|
|
- String tradeNo = cipherObj.getString("out_trade_no");
|
|
|
- String openId = payer.getString("openid");
|
|
|
- if (cipherObj.getString("trade_state").equalsIgnoreCase("SUCCESS")) {
|
|
|
- String successTime = cipherObj.getString("success_time");
|
|
|
- successTime = successTime.split("\\+")[0].replace("T"," ");
|
|
|
- WxPayOrderPojo order = dao.selectOrderByTradeNo(tradeNo);
|
|
|
- if (null != order && null != order.getHisOrdNum()) {
|
|
|
- HrgResponse hrgResponse = confirmPayStatus(tradeNo, successTime, order);
|
|
|
- if (null == hrgResponse) {
|
|
|
- dao.updatePayStatusAndOpenId(tradeNo, openId, 3, successTime);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (hrgResponse.getResultCode() == -1) {
|
|
|
- dao.updatePayStatusAndOpenId(tradeNo, openId, 3, successTime);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- dao.updatePayStatusAndOpenId(tradeNo, openId, 1, successTime);
|
|
|
- } else {
|
|
|
- dao.updatePayStatusAndOpenId(tradeNo, openId, 3, getDatetime());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private HrgResponse confirmPayStatus(String tradeNo, String successTime, WxPayOrderPojo order) {
|
|
|
- JSONObject hrgParam = new JSONObject();
|
|
|
- hrgParam.put("patCardType", 1);
|
|
|
- hrgParam.put("patCardNo", order.getPatientId());
|
|
|
- hrgParam.put("hisOrdNum", order.getHisOrdNum());
|
|
|
- hrgParam.put("psOrdNum", tradeNo);
|
|
|
- hrgParam.put("payMode", "WX");
|
|
|
- hrgParam.put("payAmt", DecimalTool.moneyYuanToFen(order.getTotalFee()));
|
|
|
- hrgParam.put("agtOrdNum", order.getSerialNo());
|
|
|
- hrgParam.put("payTime", successTime);
|
|
|
- RestTemplate template = new RestTemplate();
|
|
|
- HrgResponse response = template.postForObject(ThmzUrls.PAY_CHARGE_DETAIL_FORM_HAI_CI,
|
|
|
- hrgParam, HrgResponse.class);
|
|
|
- log.info("门诊缴费订单支付:{}", response);
|
|
|
- return response;
|
|
|
- }
|
|
|
-
|
|
|
- private String getDatetime() {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- return sdf.format(new Date());
|
|
|
- }
|
|
|
-
|
|
|
}
|