From 8b7258c9427882bb1798f1502eaa35184c6e374e Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 09 Aug 2024 14:29:18 +0800
Subject: [PATCH] 短信指定楼栋发送
---
src/main/java/org/springblade/modules/pay/controller/WxPayController.java | 137 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 120 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/springblade/modules/pay/controller/WxPayController.java b/src/main/java/org/springblade/modules/pay/controller/WxPayController.java
index 9a9cece..8ebb8b6 100644
--- a/src/main/java/org/springblade/modules/pay/controller/WxPayController.java
+++ b/src/main/java/org/springblade/modules/pay/controller/WxPayController.java
@@ -1,25 +1,32 @@
package org.springblade.modules.pay.controller;
-import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
-import com.github.binarywang.wxpay.constant.WxPayConstants;
+import com.google.gson.Gson;
import io.swagger.annotations.Api;
-import lombok.AllArgsConstructor;
-import org.springblade.core.boot.ctrl.BladeController;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springblade.common.utils.HttpUtils;
+import org.springblade.common.utils.WechatPay2ValidatorForRequest;
import org.springblade.core.tool.api.R;
import org.springblade.modules.pay.entity.WxPayInfo;
import org.springblade.modules.pay.service.IWxPayService;
-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 org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
+
+@CrossOrigin //跨域
@RestController
-@AllArgsConstructor
-@RequestMapping("/wxpay")
-@Api(value = "微信支付接口", tags = "微信支付接口")
-public class WxPayController extends BladeController {
+@RequestMapping("/wxPay")
+@Api(tags = "网站微信支付APIv3")
+@Slf4j
+public class WxPayController {
+ @Resource
private IWxPayService wxPayService;
+
@PostMapping("/save")
public R save(@RequestBody WxPayInfo wxPayInfo) {
@@ -36,14 +43,110 @@
return R.status(wxPayService.saveOrUpdate(wxPayInfo));
}
+
/**
- * 获取openId
- * @param code
+ * jsapi下单
+ *
+ * @param properChargeRecordId
* @return
+ * @throws Exception
*/
- @PostMapping("getOpenId")
- public R getOpenId(String code){
- return R.data(wxPayService.getOpenId(code));
+ @ApiOperation("调用jsapi统一下单API")
+ @GetMapping("/jsapiPay")
+ public R jsapiPay(@RequestParam("properChargeRecordId") Long properChargeRecordId) throws Exception {
+
+ log.info("发起支付请求 v3");
+
+ //返回支付二维码连接和订单号
+ Map<String, String> map = wxPayService.jsapiPay(properChargeRecordId);
+
+ return R.data(map);
}
+ /**
+ * 支付通知
+ * 微信支付通过支付通知接口将用户支付成功消息通知给商户
+ */
+ @ApiOperation("支付通知")
+ @PostMapping("/native/notify")
+ public String nativeNotify(HttpServletRequest request, HttpServletResponse response) {
+ return wxPayService.nativeNotify(request, response);
+ }
+
+ /**
+ * 用户取消订单
+ *
+ * @param orderNo
+ * @return
+ * @throws Exception
+ */
+ @ApiOperation("用户取消订单")
+ @PostMapping("/cancel/{orderNo}")
+ public R cancel(@PathVariable String orderNo) throws Exception {
+
+ log.info("取消订单");
+
+ wxPayService.cancelOrder(orderNo);
+ return R.data("订单已取消");
+ }
+
+ /**
+ * 查询订单
+ *
+ * @param orderNo
+ * @return
+ * @throws Exception
+ */
+ @ApiOperation("查询订单")
+ @GetMapping("/query/{orderNo}")
+ public R queryOrder(@PathVariable String orderNo) throws Exception {
+
+ log.info("查询订单");
+
+ String result = wxPayService.queryOrder(orderNo);
+ return R.data("result", result);
+
+ }
+
+
+ @ApiOperation("申请退款")
+ @PostMapping("/refunds/{orderNo}/{reason}")
+ public R refunds(@PathVariable String orderNo, @PathVariable String reason) throws Exception {
+
+ log.info("申请退款");
+ wxPayService.refund(orderNo, reason);
+ return R.success("退款申请成功");
+ }
+
+ /**
+ * 查询退款
+ *
+ * @param refundNo
+ * @return
+ * @throws Exception
+ */
+ @ApiOperation("查询退款")
+ @GetMapping("/query-refund/{refundNo}")
+ public R queryRefund(@PathVariable String refundNo) throws Exception {
+
+ log.info("查询退款");
+
+ String result = wxPayService.queryRefund(refundNo);
+ return R.data("result", result);
+ }
+
+
+ /**
+ * 退款结果通知
+ * 退款状态改变后,微信会把相关退款结果发送给商户。
+ */
+ @ApiOperation("退款结果通知")
+ @PostMapping("/refunds/notify")
+ public String refundsNotify(HttpServletRequest request, HttpServletResponse response) {
+
+ log.info("退款通知执行");
+ return wxPayService.refundsNotify(request, response);
+ }
+
+
}
--
Gitblit v1.9.3