|
@@ -4,9 +4,12 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import thyyxxk.wxservice_server.constant.OrderType;
|
|
|
import thyyxxk.wxservice_server.constant.QuerySource;
|
|
|
+import thyyxxk.wxservice_server.constant.TradeState;
|
|
|
import thyyxxk.wxservice_server.dao.WxApiDao;
|
|
|
import thyyxxk.wxservice_server.entity.wxapi.PaymentNotify;
|
|
|
+import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
|
|
|
import thyyxxk.wxservice_server.utils.WxPaySignUtil;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
@@ -19,29 +22,44 @@ import java.security.GeneralSecurityException;
|
|
|
@Service
|
|
|
public class WxPayNotifyService {
|
|
|
private final WxApiDao dao;
|
|
|
- private final WxApiService wxApiService;
|
|
|
+ private final SavePayResultService savePayResultService;
|
|
|
|
|
|
@Autowired
|
|
|
- public WxPayNotifyService(WxApiDao dao, WxApiService wxApiService) {
|
|
|
+ public WxPayNotifyService(WxApiDao dao, SavePayResultService savePayResultService) {
|
|
|
this.dao = dao;
|
|
|
- this.wxApiService = wxApiService;
|
|
|
+ this.savePayResultService = savePayResultService;
|
|
|
}
|
|
|
|
|
|
public void paymentNotify(PaymentNotify param) throws Exception {
|
|
|
- log.info("微信支付通知: {}", param);
|
|
|
+ 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);
|
|
|
+ log.info("微信扫码支付通知解密:{}", ciphertext);
|
|
|
JSONObject payer = cipherObj.getJSONObject("payer");
|
|
|
String tradeNo = cipherObj.getString("out_trade_no");
|
|
|
String openId = payer.getString("openid");
|
|
|
- dao.updatePayOpenId(tradeNo, openId);
|
|
|
- log.info("二维码支付查询订单状态:{}", tradeNo);
|
|
|
- wxApiService.queryOrderState(tradeNo, QuerySource.QRCODE);
|
|
|
+ TradeState tradeState = TradeState.get(cipherObj.getString("trade_state"));
|
|
|
+ if (tradeState.equals(TradeState.SUCCESS)) {
|
|
|
+ String successTime = cipherObj.getString("success_time")
|
|
|
+ .split("\\+")[0].replace("T", " ");
|
|
|
+ dao.updatePayStatusAndPayTimeAndOpenId(tradeNo, tradeState.getCode(), successTime, openId);
|
|
|
+ WxPayOrder order = dao.selectOrderByTradeNo(tradeNo);
|
|
|
+ OrderType orderType = OrderType.get(order.getOrderType());
|
|
|
+ switch (orderType) {
|
|
|
+ case OUTPATIENT:
|
|
|
+ savePayResultService.saveMzChargeInfo(order, QuerySource.QRCODE, successTime);
|
|
|
+ break;
|
|
|
+ case INPATIENT_PRE_PAY:
|
|
|
+ savePayResultService.saveZyYjjInfo(order);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ dao.updatePayStatusAndQueryTimesAndOpenId(tradeNo, tradeState.getCode(), openId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void paymentNotify2(PaymentNotify param) throws GeneralSecurityException {
|