PayController.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.num.controller;
  2. import com.num.common.Result;
  3. import com.num.service.OrderService;
  4. import com.num.service.UserService;
  5. import javax.servlet.http.HttpServletRequest;
  6. import org.springframework.web.bind.annotation.PostMapping;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import java.util.Map;
  11. @RestController
  12. @RequestMapping("/api/pay")
  13. public class PayController {
  14. private final OrderService orderService;
  15. private final UserService userService;
  16. public PayController(OrderService orderService, UserService userService) {
  17. this.orderService = orderService;
  18. this.userService = userService;
  19. }
  20. @PostMapping("/create")
  21. public Result<?> createOrder(HttpServletRequest request, @RequestBody Map<String, Object> body) {
  22. Long userId = (Long) request.getAttribute("userId");
  23. int totalFee = ((Number) body.get("totalFee")).intValue();
  24. String payType = (String) body.get("payType");
  25. return Result.success(orderService.createOrder(userId, totalFee, payType));
  26. }
  27. @PostMapping("/notify")
  28. public Result<?> payNotify(@RequestBody Map<String, String> body) {
  29. String outTradeNo = body.get("outTradeNo");
  30. orderService.paySuccess(outTradeNo);
  31. return Result.success(null);
  32. }
  33. }