From 8a0a6bb05752d08153ac9cffb09a5760ca1c10b6 Mon Sep 17 00:00:00 2001
From: Hentua <wangdoubleone@gmail.com>
Date: Fri, 21 Apr 2023 01:33:37 +0800
Subject: [PATCH] 分红设置
---
src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java | 66 ++++++++++++++++++++++++++++-----
1 files changed, 56 insertions(+), 10 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java b/src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java
index b9655e0..57abbe5 100644
--- a/src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java
+++ b/src/main/java/cc/mrbird/febs/pay/controller/PayCallBackController.java
@@ -1,14 +1,23 @@
package cc.mrbird.febs.pay.controller;
import cc.mrbird.febs.common.entity.FebsResponse;
+import cc.mrbird.febs.pay.properties.AliPayProperties;
+import cc.mrbird.febs.pay.service.IAliPayService;
+import cc.mrbird.febs.pay.service.IPayService;
import com.alibaba.fastjson.JSONObject;
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.internal.util.AlipaySignature;
+import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
+import com.github.binarywang.wxpay.exception.WxPayException;
+import com.github.binarywang.wxpay.service.WxPayService;
import com.ijpay.alipay.AliPayApi;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import me.chanjar.weixin.common.service.WxService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@@ -21,14 +30,51 @@
@RequestMapping(value = "/api/pay")
public class PayCallBackController {
+ @Autowired
+ private IAliPayService payService;
+
+ @Autowired
+ private IPayService wechatPayService;
+
+ @Resource
+ private AliPayProperties aliPayProperties;
+
+ @Autowired
+ private WxPayService wxPayService;
+
@RequestMapping("/aliCallBack")
- public FebsResponse aliPayCallBack(HttpServletRequest request) {
- log.info("进入回调");
+ public String aliPayCallBack(HttpServletRequest request){
+ log.info("进入支付宝回调");
Map<String, String> params = AliPayApi.toMap(request);
- log.info("回调参数:{}", JSONObject.toJSONString(params));
- for (Map.Entry<String, String> entry : params.entrySet()) {
- log.info("支付宝回调:{}===={}", entry.getKey(), entry.getValue());
+
+ boolean verifyResult = false;
+ try {
+ verifyResult = AlipaySignature.verifyV1(params, aliPayProperties.getPublicKey(), "UTF-8", "RSA2");
+ } catch (AlipayApiException e) {
+ log.info("=验证失败=:{}", params);
+ return "failure";
}
- return new FebsResponse().success();
+
+ if (verifyResult) {
+ if ("TRADE_SUCCESS".equals(params.get("trade_status")) || "TRADE_FINISHED".equals(params.get("trade_status"))) {
+ payService.aliCallback(params);
+ return "success";
+ } else {
+ log.info("支付失败:{}", params);
+ return "failure";
+ }
+ } else {
+ log.info("验证失败:{}", params);
+ return "failure";
+ }
+ }
+
+ @PostMapping(value = "/wxPayCallBack")
+ public String wxPayCallBack(@RequestBody String xmlData) throws WxPayException {
+ log.info("=======微信回调:{}========", xmlData);
+ WxPayOrderNotifyResult notifyResult = this.wxPayService.parseOrderNotifyResult(xmlData);
+
+ wechatPayService.payCallback(notifyResult.toMap());
+ return WxPayNotifyResponse.success("成功");
}
}
--
Gitblit v1.9.1