PaymentController.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.kym.miniapp.controller;
  2. import cn.dev33.satoken.annotation.SaIgnore;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import com.kym.common.R;
  5. import com.kym.common.annotation.ApiLog;
  6. import com.kym.service.wechat.WxPayService;
  7. import jakarta.servlet.http.HttpServletRequest;
  8. import lombok.SneakyThrows;
  9. import org.springframework.http.ResponseEntity;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.web.bind.annotation.*;
  12. /**
  13. * @author skyline
  14. * @description
  15. * @date 2023-07-22 20:36
  16. */
  17. @Controller
  18. @RequestMapping("/payment")
  19. public class PaymentController {
  20. private final WxPayService wxPayService;
  21. public PaymentController(WxPayService wxPayService) {
  22. this.wxPayService = wxPayService;
  23. }
  24. /**
  25. * 充值
  26. *
  27. * @param rechargeConfigId
  28. * @return
  29. */
  30. @ApiLog("用户充值微信支付")
  31. @GetMapping("/wxPay")
  32. @ResponseBody
  33. R<?> prepay(@RequestParam Long rechargeConfigId, @RequestParam(value = "stationId", required = false) String stationId) {
  34. return R.success(wxPayService.wxPay(rechargeConfigId, stationId));
  35. }
  36. @ApiLog(value = "微信回调", ignoreParams = true)
  37. @SneakyThrows
  38. @SaIgnore
  39. @PostMapping("/notify")
  40. ResponseEntity<Object> notify(HttpServletRequest request) {
  41. return wxPayService.wxNotify(request);
  42. }
  43. /**
  44. * 专属优惠活动充值
  45. */
  46. @ApiLog("用户优惠活动充值微信支付")
  47. @GetMapping("/promotionPay")
  48. @ResponseBody
  49. R<?> promotionPay(@RequestParam String promotionToken,
  50. @RequestParam(value = "stationId", required = false) String stationId) {
  51. return R.success(wxPayService.promotionPay(promotionToken, stationId));
  52. }
  53. @ApiLog("用户申请退款")
  54. @PostMapping("/wxApplyRefund")
  55. @ResponseBody
  56. R<?> wxAppRefund(@RequestParam String reason) {
  57. wxPayService.applyWxRefund(StpUtil.getLoginIdAsLong(), reason);
  58. return R.success();
  59. }
  60. @ApiLog(value = "微信退款回调", ignoreParams = true)
  61. @SaIgnore
  62. @PostMapping("/refundNotify")
  63. ResponseEntity<Object> refundNotify(HttpServletRequest request) {
  64. return wxPayService.wxRefundNotify(request);
  65. }
  66. }