|
@@ -1,28 +1,38 @@
|
|
package com.txz.cif.web;
|
|
package com.txz.cif.web;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
-import com.txz.cif.core.Result;
|
|
|
|
-import com.txz.cif.core.ResultGenerator;
|
|
|
|
-import com.txz.cif.model.*;
|
|
|
|
-import com.txz.cif.service.*;
|
|
|
|
-
|
|
|
|
-import com.txz.cif.core.ResultCode;
|
|
|
|
-
|
|
|
|
|
|
+import com.baomidou.lock.LockInfo;
|
|
|
|
+import com.baomidou.lock.LockTemplate;
|
|
|
|
+import com.baomidou.lock.executor.RedisTemplateLockExecutor;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
-import com.txz.cif.core.AuthService;
|
|
|
|
|
|
+import com.txz.cif.constants.MyConstants;
|
|
|
|
+import com.txz.cif.core.*;
|
|
|
|
+import com.txz.cif.dto.BizLogDTO;
|
|
|
|
+import com.txz.cif.dto.tfpay.CheckSignDTO;
|
|
|
|
+import com.txz.cif.dto.tfpay.TFCreateOrderDTO;
|
|
|
|
+import com.txz.cif.model.*;
|
|
|
|
+import com.txz.cif.service.*;
|
|
|
|
+import com.txz.cif.util.IpUtils;
|
|
|
|
+import com.txz.cif.util.TFPayUtil;
|
|
import com.txz.cif.web.para.RecordParam;
|
|
import com.txz.cif.web.para.RecordParam;
|
|
|
|
+import com.txz.cif.web.ro.TFPayNotifyDTO;
|
|
|
|
+import com.txz.cif.web.vo.CreatePayVO;
|
|
import com.txz.cif.web.vo.PaymentPriceVO;
|
|
import com.txz.cif.web.vo.PaymentPriceVO;
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
-
|
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
|
+import tk.mybatis.mapper.entity.Example;
|
|
import tk.mybatis.mapper.entity.Example.Criteria;
|
|
import tk.mybatis.mapper.entity.Example.Criteria;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -64,6 +74,12 @@ public class RechargeRecordApiController {
|
|
@Resource
|
|
@Resource
|
|
private PaymentMethodService paymentMethodService;
|
|
private PaymentMethodService paymentMethodService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private TFPayService tfPayService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private LockTemplate lockTemplate;
|
|
|
|
+
|
|
@GetMapping("/goodsList/{methodId:^\\d+$}")
|
|
@GetMapping("/goodsList/{methodId:^\\d+$}")
|
|
@ApiOperation(value = "充值商品", httpMethod = "GET")
|
|
@ApiOperation(value = "充值商品", httpMethod = "GET")
|
|
public Result<PaymentPriceVO> goodsList(@PathVariable("methodId") Long methodId) {
|
|
public Result<PaymentPriceVO> goodsList(@PathVariable("methodId") Long methodId) {
|
|
@@ -85,11 +101,12 @@ public class RechargeRecordApiController {
|
|
|
|
|
|
@GetMapping("/add")
|
|
@GetMapping("/add")
|
|
@ApiOperation(value = "创建充值订单", httpMethod = "GET")
|
|
@ApiOperation(value = "创建充值订单", httpMethod = "GET")
|
|
- public Result add(@RequestParam BigDecimal amount, @RequestParam Long methodId, HttpServletRequest request) {
|
|
|
|
|
|
+ public Result<CreatePayVO> add(@RequestParam BigDecimal amount, @RequestParam Long methodId, HttpServletRequest request) {
|
|
Long userId = authService.getTokenUserId(request);
|
|
Long userId = authService.getTokenUserId(request);
|
|
// if (goodsId == null) {
|
|
// if (goodsId == null) {
|
|
// return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
// return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
// }
|
|
// }
|
|
|
|
+ DateTime now = DateUtil.date();
|
|
try {
|
|
try {
|
|
// Goods goods = goodsService.findById(goodsId);
|
|
// Goods goods = goodsService.findById(goodsId);
|
|
// if (goods == null) {
|
|
// if (goods == null) {
|
|
@@ -109,8 +126,10 @@ public class RechargeRecordApiController {
|
|
RechargeRecord rechargeRecord = RechargeRecord.builder()
|
|
RechargeRecord rechargeRecord = RechargeRecord.builder()
|
|
.discount(BigDecimal.ZERO)
|
|
.discount(BigDecimal.ZERO)
|
|
.amount(amount)
|
|
.amount(amount)
|
|
- .currency("BDT").userId(userId)
|
|
|
|
- .userName(user.getName()).userPhone(user.getPhoneNo())
|
|
|
|
|
|
+ .currency("BDT")
|
|
|
|
+ .userId(userId)
|
|
|
|
+ .userName(user.getName())
|
|
|
|
+ .userPhone(user.getPhoneNo())
|
|
.bank(user.getBank())
|
|
.bank(user.getBank())
|
|
.methodId(methodId)
|
|
.methodId(methodId)
|
|
.channelId(paymentChannel == null ? null : paymentChannel.getId())
|
|
.channelId(paymentChannel == null ? null : paymentChannel.getId())
|
|
@@ -119,21 +138,67 @@ public class RechargeRecordApiController {
|
|
.orderNo(orderNo)
|
|
.orderNo(orderNo)
|
|
.goodsId(-1)
|
|
.goodsId(-1)
|
|
.createUser(user.getName())
|
|
.createUser(user.getName())
|
|
- .status(1).createTime(DateUtil.date())
|
|
|
|
|
|
+ .status(1)
|
|
|
|
+ .createTime(now)
|
|
.build();
|
|
.build();
|
|
rechargeRecordService.save(rechargeRecord);
|
|
rechargeRecordService.save(rechargeRecord);
|
|
// TODO 发起第三方支付
|
|
// TODO 发起第三方支付
|
|
-
|
|
|
|
|
|
+ // 获取渠道编码
|
|
|
|
+ String channelCode;
|
|
|
|
+ if (methodId == 1) {
|
|
|
|
+ channelCode = paymentChannel.getBkashPayCode();
|
|
|
|
+ } else if (methodId == 2) {
|
|
|
|
+ channelCode = paymentChannel.getNagadPayCode();
|
|
|
|
+ } else {
|
|
|
|
+ channelCode = paymentChannel.getRocketPayCode();
|
|
|
|
+ }
|
|
|
|
+ BizLogDTO bizLog;
|
|
|
|
+ String payUrl = "";
|
|
|
|
+ boolean issuccess = false;
|
|
|
|
+ switch (paymentChannel.getChannelName()) {
|
|
|
|
+ case "TFPAY":
|
|
|
|
+ bizLog = tfPayService.createTFPayOrder(
|
|
|
|
+ TFCreateOrderDTO.builder()
|
|
|
|
+ .payMemberid(paymentChannel.getMerchantNum())
|
|
|
|
+ .payOrderid(orderNo)
|
|
|
|
+ .payApplydate(now.toString())
|
|
|
|
+ .payChannelcode(channelCode)
|
|
|
|
+ .payNotifyurl(paymentChannel.getNotifyUrl())
|
|
|
|
+ .payAmount(amount.toString())
|
|
|
|
+ .ip(IpUtils.getIPAddress(request))
|
|
|
|
+ .build()
|
|
|
|
+ , paymentChannel.getSecretKey());
|
|
|
|
+
|
|
|
|
+ JSONObject resultJson = JSONUtil.parseObj(bizLog.getReceiveMessage());
|
|
|
|
+ if (resultJson.getStr("status").equals("200")) {
|
|
|
|
+ payUrl = resultJson.getStr("data");
|
|
|
|
+ issuccess = Boolean.TRUE;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ throw new ServiceException("暂不支持此渠道");
|
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
try {
|
|
// 新增日志
|
|
// 新增日志
|
|
- bizLogService.save(BizLog.builder().bizType(1).bizNo(orderNo)
|
|
|
|
- .type(1).createTime(DateUtil.date()).createUser(user.getName())
|
|
|
|
|
|
+ bizLogService.save(BizLog.builder()
|
|
|
|
+ .bizType(1)
|
|
|
|
+ .bizNo(orderNo)
|
|
|
|
+ .type(1)
|
|
|
|
+ .receiveMessage(bizLog.getReceiveMessage())
|
|
|
|
+ .sendMessage(bizLog.getSendMessage())
|
|
|
|
+ .createTime(now)
|
|
|
|
+ .createUser(user.getName())
|
|
.memo("提交充值订单").build());
|
|
.memo("提交充值订单").build());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("新增充值提交订单日志失败", e);
|
|
log.error("新增充值提交订单日志失败", e);
|
|
}
|
|
}
|
|
- return ResultGenerator.genSuccessResult(rechargeRecord);
|
|
|
|
|
|
+
|
|
|
|
+ if (!issuccess) {
|
|
|
|
+ throw new ServiceException("创建支付单失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Result.success(CreatePayVO.builder().orderNo("orderNo").payUrl(payUrl).build());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("新增对象操作异常e:{}", e);
|
|
log.error("新增对象操作异常e:{}", e);
|
|
return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
@@ -141,30 +206,68 @@ public class RechargeRecordApiController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- @GetMapping("/callback")
|
|
|
|
- @ApiOperation(value = "三方回调", httpMethod = "GET")
|
|
|
|
- public Result<RechargeRecord> detail(@RequestParam String data) {
|
|
|
|
- // TODO 回调成功
|
|
|
|
- JSONObject json = JSONUtil.parseObj(data);
|
|
|
|
- String orderNo = json.getStr("orderNo");
|
|
|
|
- RechargeRecord record = rechargeRecordService.findBy("orderNo", orderNo);
|
|
|
|
- if (record == null) {
|
|
|
|
- return ResultGenerator.genFailResult("订单未找到");
|
|
|
|
- }
|
|
|
|
- if (StrUtil.equals("1", json.getStr("status"))) {
|
|
|
|
- rechargeRecordService.success(record);
|
|
|
|
- } else {
|
|
|
|
- rechargeRecordService.fail(record);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 回调通知
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/callback/tfpay")
|
|
|
|
+ public Object callback(@ModelAttribute TFPayNotifyDTO dto) {
|
|
|
|
+ LockInfo lockInfo = lockTemplate.lock(String.format(MyConstants.TF_PAY_NOTIFY_LOCK, dto.getOrderid()), Long.valueOf(1000 * 60 * 2), Long.valueOf(1000 * 1), RedisTemplateLockExecutor.class);
|
|
|
|
+ if (null == lockInfo) {
|
|
|
|
+ return "WAIT";
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- // 新增充值回调日志
|
|
|
|
- bizLogService.save(BizLog.builder().bizType(1).bizNo(orderNo)
|
|
|
|
- .type(3).createTime(DateUtil.date()).createUser("第三方")
|
|
|
|
- .memo("充值回调").build());
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("新增充值回调日志失败", e);
|
|
|
|
|
|
+ log.info("支付渠道--->tfpay,回调通知--->" + dto);
|
|
|
|
+ Condition condition = new Condition(PaymentChannel.class);
|
|
|
|
+ Example.Criteria criteria = condition.createCriteria();
|
|
|
|
+ criteria.andEqualTo("channelName", "TFPAY");
|
|
|
|
+ criteria.andEqualTo("isValid", 1);
|
|
|
|
+ List<PaymentChannel> paymentChannels = paymentChannelService.findByCondition(condition);
|
|
|
|
+ if (CollectionUtil.isEmpty(paymentChannels)) {
|
|
|
|
+ log.info("支付渠道不存在");
|
|
|
|
+ return "FAIL";
|
|
|
|
+ }
|
|
|
|
+ boolean checkSignResult = TFPayUtil.verifySignature(BeanUtil.copyProperties(dto, CheckSignDTO.class), paymentChannels.get(0).getSecretKey(), dto.getSign());
|
|
|
|
+ if (!checkSignResult) {
|
|
|
|
+ log.info("签名校验失败");
|
|
|
|
+ return "FAIL";
|
|
|
|
+ }
|
|
|
|
+ RechargeRecord record = rechargeRecordService.findBy("orderNo", dto.getOrderid());
|
|
|
|
+ if (ObjectUtil.isEmpty(record)) {
|
|
|
|
+ return "FAIL";
|
|
|
|
+ }
|
|
|
|
+ if (record.getStatus() != 1) {
|
|
|
|
+ return "FAIL";
|
|
|
|
+ }
|
|
|
|
+ record.setRealAmount(new BigDecimal(dto.getAmount()));
|
|
|
|
+ rechargeRecordService.success(record);
|
|
|
|
+
|
|
|
|
+ // String orderNo = dto.getOrderid();
|
|
|
|
+ // RechargeRecord record = rechargeRecordService.findBy("orderNo", orderNo);
|
|
|
|
+ // if (record == null) {
|
|
|
|
+ // return ResultGenerator.genFailResult("订单未找到");
|
|
|
|
+ // }
|
|
|
|
+ // if (StrUtil.equals("1", json.getStr("status"))) {
|
|
|
|
+ // rechargeRecordService.success(record);
|
|
|
|
+ // } else {
|
|
|
|
+ // rechargeRecordService.fail(record);
|
|
|
|
+ // }
|
|
|
|
+ try {
|
|
|
|
+ // 新增充值回调日志
|
|
|
|
+ bizLogService.save(BizLog.builder()
|
|
|
|
+ .bizType(1)
|
|
|
|
+ .bizNo(dto.getOrderid())
|
|
|
|
+ .type(3)
|
|
|
|
+ .receiveMessage(dto.toString())
|
|
|
|
+ .createTime(DateUtil.date())
|
|
|
|
+ .createUser("TFPAY")
|
|
|
|
+ .memo("充值回调").build());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("新增充值回调日志失败", e);
|
|
|
|
+ }
|
|
|
|
+ return "OK";
|
|
|
|
+ } finally {
|
|
|
|
+ this.lockTemplate.releaseLock(lockInfo);
|
|
}
|
|
}
|
|
- return ResultGenerator.genSuccessResult();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|