|
@@ -2,6 +2,7 @@ package com.zanxiang.game.module.sdk.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.github.sd4324530.jtuple.Tuple2;
|
|
|
import com.zanxiang.game.module.base.pojo.enums.CpStatusEnum;
|
|
|
import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
|
|
|
import com.zanxiang.game.module.base.util.DateUtils;
|
|
@@ -12,6 +13,7 @@ import com.zanxiang.game.module.sdk.pojo.dto.PayMerchantDTO;
|
|
|
import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
|
|
|
import com.zanxiang.game.module.sdk.pojo.result.PushCpResult;
|
|
|
import com.zanxiang.game.module.sdk.service.*;
|
|
|
+import com.zanxiang.game.module.sdk.service.api.CpApiService;
|
|
|
import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
import com.zanxiang.module.util.URIUtil;
|
|
@@ -73,6 +75,9 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
|
|
|
@Autowired
|
|
|
private IGameService gameService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CpApiService cpApiService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = {RuntimeException.class, Exception.class})
|
|
|
public Boolean pushCp(PlatformOrderDTO orderInfo) {
|
|
@@ -90,31 +95,11 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
|
|
|
Game game = gameService.getById(orderInfo.getGameId());
|
|
|
//用户信息
|
|
|
User user = userService.getById(orderInfo.getUserId());
|
|
|
- //回调CP
|
|
|
- Map<String, String> map = new HashMap<>(9);
|
|
|
- //用户存在关联用户id, 且不是微信小程序, 则判定为导量用户, 提交CP原始用户id
|
|
|
- if (user.getRelationUserId() != null && !Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) {
|
|
|
- map.put("userId", String.valueOf(user.getRelationUserId()));
|
|
|
- } else {
|
|
|
- map.put("userId", String.valueOf(orderInfo.getUserId()));
|
|
|
- }
|
|
|
- //判断是否设置充值打折
|
|
|
- if (game.getRechargeRebate() != null) {
|
|
|
- BigDecimal money = orderInfo.getAmount().multiply(game.getRechargeRebate()).setScale(2, RoundingMode.HALF_UP);
|
|
|
- map.put("money", money.stripTrailingZeros().toPlainString());
|
|
|
- } else {
|
|
|
- map.put("money", orderInfo.getAmount().stripTrailingZeros().toPlainString());
|
|
|
- }
|
|
|
- map.put("time", String.valueOf(System.currentTimeMillis()));
|
|
|
- map.put("serverId", orderInfo.getServerId());
|
|
|
- map.put("roleId", orderInfo.getRoleId());
|
|
|
- map.put("roleName", orderInfo.getRoleName());
|
|
|
- map.put("orderId", orderInfo.getCpOrderId());
|
|
|
- map.put("ext", URIUtil.encodeURIComponent(orderInfo.getExt()));
|
|
|
- map.put("sign", this.paySign(orderInfo.getGameId(), map));
|
|
|
- map.put("orderId2", orderInfo.getOrderId());
|
|
|
- //url
|
|
|
- String url = URIUtil.fillUrlParams(cpPaybackUrl, map, false);
|
|
|
+ //回调参数
|
|
|
+ Map<String, String> param = this.payParam(game, user, orderInfo);
|
|
|
+ //拼接请求URI
|
|
|
+ String url = URIUtil.fillUrlParams(cpPaybackUrl, param, false);
|
|
|
+ //调CP充值回调
|
|
|
String resultStr;
|
|
|
try {
|
|
|
resultStr = restTemplate.getForObject(url, String.class);
|
|
@@ -125,6 +110,21 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
|
|
|
PushCpResult pushCpResult = JsonUtil.toObj(resultStr, PushCpResult.class);
|
|
|
boolean pushSuccess = Objects.equals(pushCpResult.getResult(), PushCpResult.SUCCESS_CODE)
|
|
|
|| Objects.equals(pushCpResult.getCode(), PushCpResult.SUCCESS_CODE);
|
|
|
+
|
|
|
+ //CP返回充值失败, 进入重试
|
|
|
+ if (!pushSuccess) {
|
|
|
+ try {
|
|
|
+ Tuple2<Boolean, String> tuple2 = cpApiService.callCpRecharge(url);
|
|
|
+ //重试成功, 修改结果, 重试失败, 则打印日志, 将日志给CP方
|
|
|
+ if (tuple2.first) {
|
|
|
+ pushSuccess = true;
|
|
|
+ resultStr = tuple2.second;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("CP充值回调重试失败, url : {}, e : {}", url, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
log.error("通知CP支付回调结果, url : {}, resultStr : {}, pushSuccess : {}", url, resultStr, pushSuccess);
|
|
|
//更新订单信息
|
|
|
orderService.update(new LambdaUpdateWrapper<Order>()
|
|
@@ -140,7 +140,7 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
|
|
|
.status(orderInfo.getStatus())
|
|
|
.cpStatus(pushSuccess ? CpStatusEnum.SUCCESS.getStatus() : CpStatusEnum.FAIL.getStatus())
|
|
|
.cpPaybackUrl(cpPaybackUrl)
|
|
|
- .params(JsonUtil.toString(map))
|
|
|
+ .params(JsonUtil.toString(param))
|
|
|
.ext(orderInfo.getExt())
|
|
|
.notifyCnt(orderInfo.getCpNotifyCnt() + 1)
|
|
|
.createTime(LocalDateTime.now())
|
|
@@ -150,6 +150,34 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
|
|
|
return pushSuccess;
|
|
|
}
|
|
|
|
|
|
+ private Map<String, String> payParam(Game game, User user, PlatformOrderDTO orderInfo) {
|
|
|
+ Map<String, String> map = new HashMap<>(10);
|
|
|
+ //用户存在关联用户id, 且不是微信小程序, 则判定为导量用户, 提交CP原始用户id
|
|
|
+ if (user.getRelationUserId() != null
|
|
|
+ && !Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getId())) {
|
|
|
+ map.put("userId", String.valueOf(user.getRelationUserId()));
|
|
|
+ } else {
|
|
|
+ map.put("userId", String.valueOf(orderInfo.getUserId()));
|
|
|
+ }
|
|
|
+ //判断是否设置充值打折
|
|
|
+ if (game.getRechargeRebate() != null) {
|
|
|
+ BigDecimal money = orderInfo.getAmount().multiply(game.getRechargeRebate())
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ map.put("money", money.stripTrailingZeros().toPlainString());
|
|
|
+ } else {
|
|
|
+ map.put("money", orderInfo.getAmount().stripTrailingZeros().toPlainString());
|
|
|
+ }
|
|
|
+ map.put("time", String.valueOf(System.currentTimeMillis()));
|
|
|
+ map.put("serverId", orderInfo.getServerId());
|
|
|
+ map.put("roleId", orderInfo.getRoleId());
|
|
|
+ map.put("roleName", orderInfo.getRoleName());
|
|
|
+ map.put("orderId", orderInfo.getCpOrderId());
|
|
|
+ map.put("ext", URIUtil.encodeURIComponent(orderInfo.getExt()));
|
|
|
+ map.put("sign", this.paySign(orderInfo.getGameId(), map));
|
|
|
+ map.put("orderId2", orderInfo.getOrderId());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
private String paySign(Long gameId, Map<String, String> map) {
|
|
|
//查询游戏
|
|
|
GameExt gameExt = gameExtService.getByGameId(gameId);
|