IbitController.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package com.crm.pay.controller.pay;
  2. import com.crm.pay.controller.base.BasePayCloseFunctionController;
  3. import com.crm.pay.entity.callback.IbitCallbackEntity;
  4. import com.crm.pay.service.IbitService;
  5. import com.crm.rely.backend.core.constant.Constants;
  6. import com.crm.rely.backend.core.constant.FeignClientAnnotation;
  7. import com.crm.rely.backend.model.constant.PayConstants;
  8. import com.crm.rely.backend.core.dto.base.BaseResultDto;
  9. import com.crm.pay.dto.PayDto;
  10. import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
  11. import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositAddEntity;
  12. import com.crm.pay.entity.FinanceDepositParameterEntity;
  13. import com.crm.pay.entity.finance.withdraw.automatic.FinanceWithdrawIbitEntity;
  14. import com.crm.pay.entity.finance.withdraw.automatic.FinanceWithdrawInfoEntity;
  15. import com.crm.rely.backend.core.exception.PayValidatedException;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import javax.servlet.http.HttpServletRequest;
  19. import javax.servlet.http.HttpServletResponse;
  20. import java.io.IOException;
  21. import java.math.BigDecimal;
  22. @RestController
  23. @RequestMapping("/ibit")
  24. public class IbitController extends BasePayCloseFunctionController {
  25. @Autowired
  26. private IbitService service;
  27. /**
  28. * 支付
  29. *
  30. * @param login 入金账号
  31. * @param amount 入金金额
  32. * @return 错误信息
  33. * @throws Exception
  34. */
  35. @RequestMapping("/pay/{login}/{amount}/{bankCode}")
  36. public BaseResultDto pay(@PathVariable("login") Long login,
  37. @PathVariable("amount") BigDecimal amount,
  38. @PathVariable("bankCode") String bankCode,
  39. @RequestBody FinanceDepositParameterEntity entity,
  40. CustomInfoEntity infoEntity, HttpServletRequest request) throws Exception {
  41. return payCall(login, amount, bankCode, 0, entity, infoEntity, request);
  42. }
  43. @RequestMapping("/pay/{login}/{amount}/{bankCode}/{activity}")
  44. public BaseResultDto pay(@PathVariable("login") Long login,
  45. @PathVariable("amount") BigDecimal amount,
  46. @PathVariable("bankCode") String bankCode,
  47. @PathVariable("activity") int activity,
  48. @RequestBody FinanceDepositParameterEntity entity,
  49. CustomInfoEntity infoEntity, HttpServletRequest request) throws Exception {
  50. return payCall(login, amount, bankCode, activity, entity, infoEntity, request);
  51. }
  52. private BaseResultDto payCall(Long login,
  53. BigDecimal amount,
  54. String bankCode,
  55. int activity,
  56. FinanceDepositParameterEntity entity,
  57. CustomInfoEntity infoEntity, HttpServletRequest request) throws Exception {
  58. validated(login, amount);
  59. FinanceDepositAddEntity financeDepositSaveEntity = getFinanceDepositSaveEntity(login, amount, bankCode,
  60. PayConstants.IBIT_PAY_TYPE, activity, entity, request);
  61. String serial = service.pay(financeDepositSaveEntity, infoEntity);
  62. PayDto payDto = new PayDto(1, serial);
  63. return BaseResultDto.success(payDto);
  64. }
  65. /**
  66. * 异步回调
  67. *
  68. * @param callback 用于获取回调数据
  69. * @return 返回成功给第三方系统
  70. * @throws Exception
  71. */
  72. @RequestMapping(value = "/callback", produces = "text/html")
  73. public String callback(@RequestBody IbitCallbackEntity callback, HttpServletRequest request,
  74. HttpServletResponse response) throws Exception {
  75. service.callback(callback);
  76. return Constants.SUCCESS;
  77. }
  78. @RequestMapping(value = "/hc/callback", produces = "text/html")
  79. public String hcCallback(@RequestBody IbitCallbackEntity callback, HttpServletRequest request,
  80. HttpServletResponse response) throws Exception {
  81. service.callback(callback, PayConstants.IBIT_PAY_TYPE_HC);
  82. return Constants.SUCCESS;
  83. }
  84. @PostMapping("/withdraw/info")
  85. @FeignClientAnnotation
  86. public BaseResultDto withdrawInfo(@RequestBody FinanceWithdrawInfoEntity entity) throws Exception {
  87. return BaseResultDto.success(service.withdrawInfo(entity));
  88. }
  89. @PostMapping("/withdraw")
  90. @FeignClientAnnotation
  91. public BaseResultDto withdraw(@RequestBody FinanceWithdrawIbitEntity entity) throws Exception {
  92. service.withdraw(entity);
  93. return BaseResultDto.success();
  94. }
  95. @RequestMapping(value = "/withdraw/callback", produces = "text/html")
  96. public String withdrawCallback(@RequestBody IbitCallbackEntity callbackEntity) throws Exception {
  97. try {
  98. return service.withdrawCallback(1, callbackEntity);
  99. } catch (Exception e) {
  100. return Constants.FAIL;
  101. }
  102. }
  103. @RequestMapping(value = "/agent/withdraw/callback", produces = "text/html")
  104. public String agentWithdrawCallback(@RequestBody IbitCallbackEntity callbackEntity) throws Exception {
  105. try {
  106. return service.withdrawCallback(2, callbackEntity);
  107. } catch (Exception e) {
  108. return Constants.FAIL;
  109. }
  110. }
  111. /**
  112. * 同步页面 成功
  113. *
  114. * @param response 用于重定向页面
  115. * @throws IOException
  116. */
  117. @GetMapping(value = "/pickup")
  118. public void pickup(HttpServletResponse response) throws Exception, PayValidatedException {
  119. sendRedirect(response);
  120. }
  121. @GetMapping(value = "/error")
  122. public void error(HttpServletResponse response) throws Exception {
  123. sendRedirect(response);
  124. }
  125. }