| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package com.crm.pay.controller.pay;
- import com.crm.pay.controller.base.BasePayCloseFunctionController;
- import com.crm.pay.entity.callback.IbitCallbackEntity;
- import com.crm.pay.service.IbitService;
- import com.crm.rely.backend.core.constant.Constants;
- import com.crm.rely.backend.core.constant.FeignClientAnnotation;
- import com.crm.rely.backend.model.constant.PayConstants;
- import com.crm.rely.backend.core.dto.base.BaseResultDto;
- import com.crm.pay.dto.PayDto;
- import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
- import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositAddEntity;
- import com.crm.pay.entity.FinanceDepositParameterEntity;
- import com.crm.pay.entity.finance.withdraw.automatic.FinanceWithdrawIbitEntity;
- import com.crm.pay.entity.finance.withdraw.automatic.FinanceWithdrawInfoEntity;
- import com.crm.rely.backend.core.exception.PayValidatedException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.math.BigDecimal;
- @RestController
- @RequestMapping("/ibit")
- public class IbitController extends BasePayCloseFunctionController {
- @Autowired
- private IbitService service;
- /**
- * 支付
- *
- * @param login 入金账号
- * @param amount 入金金额
- * @return 错误信息
- * @throws Exception
- */
- @RequestMapping("/pay/{login}/{amount}/{bankCode}")
- public BaseResultDto pay(@PathVariable("login") Long login,
- @PathVariable("amount") BigDecimal amount,
- @PathVariable("bankCode") String bankCode,
- @RequestBody FinanceDepositParameterEntity entity,
- CustomInfoEntity infoEntity, HttpServletRequest request) throws Exception {
- return payCall(login, amount, bankCode, 0, entity, infoEntity, request);
- }
- @RequestMapping("/pay/{login}/{amount}/{bankCode}/{activity}")
- public BaseResultDto pay(@PathVariable("login") Long login,
- @PathVariable("amount") BigDecimal amount,
- @PathVariable("bankCode") String bankCode,
- @PathVariable("activity") int activity,
- @RequestBody FinanceDepositParameterEntity entity,
- CustomInfoEntity infoEntity, HttpServletRequest request) throws Exception {
- return payCall(login, amount, bankCode, activity, entity, infoEntity, request);
- }
- private BaseResultDto payCall(Long login,
- BigDecimal amount,
- String bankCode,
- int activity,
- FinanceDepositParameterEntity entity,
- CustomInfoEntity infoEntity, HttpServletRequest request) throws Exception {
- validated(login, amount);
- FinanceDepositAddEntity financeDepositSaveEntity = getFinanceDepositSaveEntity(login, amount, bankCode,
- PayConstants.IBIT_PAY_TYPE, activity, entity, request);
- String serial = service.pay(financeDepositSaveEntity, infoEntity);
- PayDto payDto = new PayDto(1, serial);
- return BaseResultDto.success(payDto);
- }
- /**
- * 异步回调
- *
- * @param callback 用于获取回调数据
- * @return 返回成功给第三方系统
- * @throws Exception
- */
- @RequestMapping(value = "/callback", produces = "text/html")
- public String callback(@RequestBody IbitCallbackEntity callback, HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- service.callback(callback);
- return Constants.SUCCESS;
- }
- @RequestMapping(value = "/hc/callback", produces = "text/html")
- public String hcCallback(@RequestBody IbitCallbackEntity callback, HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- service.callback(callback, PayConstants.IBIT_PAY_TYPE_HC);
- return Constants.SUCCESS;
- }
- @PostMapping("/withdraw/info")
- @FeignClientAnnotation
- public BaseResultDto withdrawInfo(@RequestBody FinanceWithdrawInfoEntity entity) throws Exception {
- return BaseResultDto.success(service.withdrawInfo(entity));
- }
- @PostMapping("/withdraw")
- @FeignClientAnnotation
- public BaseResultDto withdraw(@RequestBody FinanceWithdrawIbitEntity entity) throws Exception {
- service.withdraw(entity);
- return BaseResultDto.success();
- }
- @RequestMapping(value = "/withdraw/callback", produces = "text/html")
- public String withdrawCallback(@RequestBody IbitCallbackEntity callbackEntity) throws Exception {
- try {
- return service.withdrawCallback(1, callbackEntity);
- } catch (Exception e) {
- return Constants.FAIL;
- }
- }
- @RequestMapping(value = "/agent/withdraw/callback", produces = "text/html")
- public String agentWithdrawCallback(@RequestBody IbitCallbackEntity callbackEntity) throws Exception {
- try {
- return service.withdrawCallback(2, callbackEntity);
- } catch (Exception e) {
- return Constants.FAIL;
- }
- }
- /**
- * 同步页面 成功
- *
- * @param response 用于重定向页面
- * @throws IOException
- */
- @GetMapping(value = "/pickup")
- public void pickup(HttpServletResponse response) throws Exception, PayValidatedException {
- sendRedirect(response);
- }
- @GetMapping(value = "/error")
- public void error(HttpServletResponse response) throws Exception {
- sendRedirect(response);
- }
- }
|