| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package com.num.controller;
- import com.num.common.Result;
- import com.num.service.OrderService;
- import com.num.service.UserService;
- import javax.servlet.http.HttpServletRequest;
- 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 java.util.Map;
- @RestController
- @RequestMapping("/api/pay")
- public class PayController {
- private final OrderService orderService;
- private final UserService userService;
- public PayController(OrderService orderService, UserService userService) {
- this.orderService = orderService;
- this.userService = userService;
- }
- @PostMapping("/create")
- public Result<?> createOrder(HttpServletRequest request, @RequestBody Map<String, Object> body) {
- Long userId = (Long) request.getAttribute("userId");
- int totalFee = ((Number) body.get("totalFee")).intValue();
- String payType = (String) body.get("payType");
- return Result.success(orderService.createOrder(userId, totalFee, payType));
- }
- @PostMapping("/notify")
- public Result<?> payNotify(@RequestBody Map<String, String> body) {
- String outTradeNo = body.get("outTradeNo");
- orderService.paySuccess(outTradeNo);
- return Result.success(null);
- }
- }
|