SandPayTestController.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.izouma.nineth.web;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.izouma.nineth.service.SandPayService;
  5. import com.izouma.nineth.utils.SnowflakeIdWorker;
  6. import lombok.AllArgsConstructor;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestParam;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import java.math.BigDecimal;
  12. import java.time.LocalDateTime;
  13. @RestController
  14. @RequestMapping("/sandPayTest")
  15. @AllArgsConstructor
  16. public class SandPayTestController {
  17. private final SandPayService sandPayService;
  18. private final SnowflakeIdWorker snowflakeIdWorker;
  19. @GetMapping(value = "/pay", produces = "text/html")
  20. private String testpay() {
  21. JSONObject extend = new JSONObject();
  22. extend.put("type", "test");
  23. extend.put("id", 1);
  24. JSONObject res = sandPayService.requestAlipay(snowflakeIdWorker.nextId() + "", new BigDecimal("0.01"),
  25. "话费充值", "话费充值", 180, extend.toJSONString());
  26. String qrCode = res.getJSONObject("body").getString("qrCode");
  27. return "<html><body><a style=\"font-size:28px;\" href=\"" + qrCode + "\">" + qrCode + "</a></body></html>";
  28. }
  29. @GetMapping(value = "/transfer")
  30. private String testTransfer(@RequestParam String name, @RequestParam String bank, @RequestParam BigDecimal amount) {
  31. return JSON.toJSONString(sandPayService.transfer(snowflakeIdWorker.nextId() + "", name, bank, amount), true);
  32. }
  33. @GetMapping(value = "/refund")
  34. public String refund(@RequestParam String orderId, @RequestParam BigDecimal amount) {
  35. return JSON.toJSONString(sandPayService.refund(orderId, amount), true);
  36. }
  37. }