PayChannelMgmtController.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.izouma.nineth.web;
  2. import com.alibaba.fastjson.JSON;
  3. import com.izouma.nineth.service.HMPayService;
  4. import com.izouma.nineth.service.SandPayService;
  5. import com.izouma.nineth.utils.SnowflakeIdWorker;
  6. import lombok.AllArgsConstructor;
  7. import lombok.NoArgsConstructor;
  8. import org.springframework.security.access.prepost.PreAuthorize;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestParam;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import java.math.BigDecimal;
  14. @RestController
  15. @RequestMapping("/payChannelMgmt")
  16. @AllArgsConstructor
  17. public class PayChannelMgmtController {
  18. private final SandPayService sandPayService;
  19. private final HMPayService hmPayService;
  20. private final SnowflakeIdWorker snowflakeIdWorker;
  21. @GetMapping(value = "/pay")
  22. @PreAuthorize("hasRole('ADMIN')")
  23. private String pay(@RequestParam String channel) {
  24. switch (channel) {
  25. case "sandPay":
  26. return sandPayService.requestAlipay(snowflakeIdWorker.nextId() + "",
  27. new BigDecimal("0.01"), "话费充值", "话费充值",
  28. SandPayService.getTimeout(180), "{\"type\":\"test\",\"id\":1}");
  29. case "hmPay":
  30. return hmPayService.requestAlipay(snowflakeIdWorker.nextId() + "",
  31. new BigDecimal("0.01"), "话费充值",
  32. HMPayService.getTimeout(180), "test", "https://www.baidu.com");
  33. }
  34. return null;
  35. }
  36. @GetMapping(value = "/transfer")
  37. @PreAuthorize("hasRole('ADMIN')")
  38. private String testTransfer(@RequestParam String name, @RequestParam String bank, @RequestParam BigDecimal amount) {
  39. return JSON.toJSONString(sandPayService.transfer(snowflakeIdWorker.nextId() + "", name, bank, amount), true);
  40. }
  41. @GetMapping(value = "/refund")
  42. @PreAuthorize("hasRole('ADMIN')")
  43. public String refund(@RequestParam String channel, @RequestParam String orderId, @RequestParam BigDecimal amount) {
  44. switch (channel) {
  45. case "sandPay":
  46. return JSON.toJSONString(sandPayService.refund(orderId, amount), true);
  47. case "hmPay":
  48. return JSON.toJSONString(hmPayService.refund(orderId, amount), true);
  49. }
  50. return null;
  51. }
  52. @GetMapping(value = "/query")
  53. @PreAuthorize("hasRole('ADMIN')")
  54. public String refund(@RequestParam String channel, @RequestParam String id) {
  55. switch (channel) {
  56. case "sandPay":
  57. return JSON.toJSONString(sandPayService.query(id), true);
  58. case "hmPay":
  59. return JSON.toJSONString(hmPayService.query(id), true);
  60. }
  61. return null;
  62. }
  63. @GetMapping("/queryTransfer")
  64. @PreAuthorize("hasRole('ADMIN')")
  65. public String queryTransfer(@RequestParam String tranTime, @RequestParam String orderId) {
  66. return JSON.toJSONString(sandPayService.queryTransfer(tranTime, orderId), true);
  67. }
  68. }