|
@@ -1,70 +1,34 @@
|
|
|
package thyyxxk.wxservice_server.controller;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
-import thyyxxk.wxservice_server.dao.WxApiDao;
|
|
|
import thyyxxk.wxservice_server.pojo.wxapi.PaymentNotify;
|
|
|
-import thyyxxk.wxservice_server.service.PayMzFeeService;
|
|
|
-import thyyxxk.wxservice_server.service.WxApiService;
|
|
|
-import thyyxxk.wxservice_server.utils.WxPaySignUtil;
|
|
|
+import thyyxxk.wxservice_server.service.WxPayNotifyService;
|
|
|
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.security.GeneralSecurityException;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/wxPayNotify")
|
|
|
public class WxPayNotifyController {
|
|
|
- private final WxApiDao dao;
|
|
|
- private final PayMzFeeService payMzFeeService;
|
|
|
- private final WxApiService wxApiService;
|
|
|
+ private final WxPayNotifyService service;
|
|
|
|
|
|
- public WxPayNotifyController(WxApiDao dao, PayMzFeeService payMzFeeService, WxApiService wxApiService) {
|
|
|
- this.dao = dao;
|
|
|
- this.payMzFeeService = payMzFeeService;
|
|
|
- this.wxApiService = wxApiService;
|
|
|
+ @Autowired
|
|
|
+ public WxPayNotifyController(WxPayNotifyService service) {
|
|
|
+ this.service = service;
|
|
|
}
|
|
|
|
|
|
@PostMapping("/notify")
|
|
|
public void paymentNotify(@RequestBody PaymentNotify param) throws Exception {
|
|
|
- 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");
|
|
|
- dao.updatePayOpenId(tradeNo, openId);
|
|
|
- String tradeState = cipherObj.getString("trade_state");
|
|
|
- if (null == tradeState) {
|
|
|
- wxApiService.queryOrderState(tradeNo);
|
|
|
- } else {
|
|
|
- if (tradeState.equals("SUCCESS")) {
|
|
|
- String successTime = cipherObj.getString("success_time");
|
|
|
- successTime = successTime.split("\\+")[0].replace("T", " ");
|
|
|
- dao.updatePayStatusAndPayTime(tradeNo, 1, successTime);
|
|
|
- if (!payMzFeeService.isTradeNoBetweenQuery(tradeNo)) {
|
|
|
- payMzFeeService.saveMzChargeInfo(tradeNo);
|
|
|
- }
|
|
|
- } else {
|
|
|
- wxApiService.updatePayStatusByTradeState(tradeState, tradeNo);
|
|
|
- }
|
|
|
- }
|
|
|
+ service.paymentNotify(param);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/notify2")
|
|
|
public void paymentNotify2(@RequestBody PaymentNotify param) throws GeneralSecurityException {
|
|
|
- log.info("微信支付回调2:{}", param);
|
|
|
- String ciphertext = WxPaySignUtil.decryptToString(param.getResource().getAssociated_data().getBytes(StandardCharsets.UTF_8),
|
|
|
- param.getResource().getNonce().getBytes(StandardCharsets.UTF_8), param.getResource().getCiphertext());
|
|
|
- log.info("微信支付回调解密2:{}", ciphertext);
|
|
|
+ service.paymentNotify2(param);
|
|
|
}
|
|
|
}
|