feat:正元支付退款
This commit is contained in:
1 parent
6195ca447d
commit
96208fd4d0
16 files changed
+299
-35
No files matched your search
+16
@@ -0,0 +1,16 @@
|
||||
package com.bsd.pjcloud.hard.api.constant.third;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum HardCallbackRefundStatus {
|
||||
SUCCESS("0", "省平台认为流水交易完成,扣费成功"),
|
||||
REPETITION("0001", "省平台则会每天定时重新发起扣费流程"),
|
||||
ERROR("0002", "省平台则不再扣费,认为是坏账"),
|
||||
;
|
||||
private final String type;
|
||||
|
||||
private final String description;
|
||||
}
|
||||
+8
@@ -4,4 +4,12 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HardCallbackRefundDto {
|
||||
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 智慧园区通刷服务平台冲正所产生的平台记录流水号
|
||||
*/
|
||||
private String serialNum;
|
||||
|
||||
}
|
||||
+6
@@ -31,6 +31,12 @@ public class HardOrderEntity extends Model<HardOrderEntity> {
|
||||
@Schema(description="编号")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
@Schema(description="订单编号 目前正元正在使用")
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackPayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackPayVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackRefundVo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -19,6 +20,6 @@ public interface RemoteHardThirdSelfZyService {
|
||||
|
||||
@NoToken
|
||||
@PostMapping("/hard-third-callback/refund")
|
||||
String refund(@RequestBody HardCallbackRefundDto dto);
|
||||
R<HardCallbackRefundVo> refund(@RequestBody HardCallbackRefundDto dto);
|
||||
|
||||
}
|
||||
+2
-2
@@ -10,11 +10,11 @@ public class HardCallbackPayVo {
|
||||
|
||||
private Long orderId;
|
||||
|
||||
private HardCallbackPayStatus code;
|
||||
|
||||
private LocalDateTime payTime;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String username;
|
||||
|
||||
private HardCallbackPayStatus code;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.third;
|
||||
|
||||
import com.bsd.pjcloud.hard.api.constant.third.HardCallbackRefundStatus;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class HardCallbackRefundVo {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 退款id
|
||||
*/
|
||||
private String refundId;
|
||||
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 退款时间
|
||||
*/
|
||||
private LocalDateTime refundTime;
|
||||
|
||||
private HardCallbackRefundStatus code;
|
||||
|
||||
}
|
||||
+6
-2
@@ -2,9 +2,11 @@ package com.bsd.pjcloud.hard.controller.third;
|
||||
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackPayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackPayVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackRefundVo;
|
||||
import com.bsd.pjcloud.hard.service.HardThirdSelfZyService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
@@ -24,6 +26,7 @@ public class HardThirdSelfZyController {
|
||||
|
||||
/* ************************************* start 远程调用 start ************************************* */
|
||||
|
||||
@Inner
|
||||
@PostMapping("/pay")
|
||||
@SysLog("正元支付")
|
||||
@Operation(summary = "正元支付")
|
||||
@@ -31,11 +34,12 @@ public class HardThirdSelfZyController {
|
||||
return R.ok(hardThirdSelfZyService.pay(dto));
|
||||
}
|
||||
|
||||
@Inner
|
||||
@PostMapping("/refund")
|
||||
@SysLog("正元退款")
|
||||
@Operation(summary = "正元退款")
|
||||
public String refund(@RequestBody HardCallbackRefundDto dto) {
|
||||
return hardThirdSelfZyService.refund(dto);
|
||||
public R<HardCallbackRefundVo> refund(@RequestBody HardCallbackRefundDto dto) {
|
||||
return R.ok(hardThirdSelfZyService.refund(dto));
|
||||
}
|
||||
|
||||
/* ************************************* end 远程调用 end ************************************* */
|
||||
|
||||
+6
@@ -9,6 +9,7 @@ import com.bsd.pjcloud.hard.api.dto.order.HardDisagreeDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleLogEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -68,6 +69,11 @@ public interface HardAfterSaleService extends IService<HardAfterSaleEntity> {
|
||||
*/
|
||||
Boolean disagreeRefund(Long userId, HardDisagreeDto dto);
|
||||
|
||||
/**
|
||||
* 校验订单是否可以退款
|
||||
*/
|
||||
HardOrderVo validateOrderCanRefund(Long orderId);
|
||||
|
||||
/**
|
||||
* 后台退款
|
||||
*
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackPayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackPayVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackRefundVo;
|
||||
|
||||
public interface HardThirdSelfZyService {
|
||||
|
||||
@@ -15,5 +16,5 @@ public interface HardThirdSelfZyService {
|
||||
/**
|
||||
* 正元退款
|
||||
*/
|
||||
String refund(HardCallbackRefundDto dto);
|
||||
HardCallbackRefundVo refund(HardCallbackRefundDto dto);
|
||||
}
|
||||
+73
-5
@@ -2,14 +2,27 @@ package com.bsd.pjcloud.hard.service.impl.hard;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.refund.HardAfterSaleOperateTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleStatusEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.third.HardCallbackPayStatus;
|
||||
import com.bsd.pjcloud.hard.api.constant.third.HardCallbackRefundStatus;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackPayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleLogEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackPayVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackRefundVo;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleLogMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardAfterSaleService;
|
||||
import com.bsd.pjcloud.hard.service.HardOrderService;
|
||||
import com.bsd.pjcloud.hard.service.HardThirdSelfZyService;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
|
||||
@@ -33,8 +46,11 @@ public class HardThirdSelfZyServiceImpl implements HardThirdSelfZyService {
|
||||
private static final String TAG = "硬件正元回调";
|
||||
|
||||
private final RemoteWalletService remoteWalletService;
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
private final HardOrderService hardOrderService;
|
||||
private final HardAfterSaleLogMapper hardAfterSaleLogMapper;
|
||||
private final HardAfterSaleService hardAfterSaleService;
|
||||
|
||||
/**
|
||||
* 正元支付
|
||||
@@ -42,10 +58,13 @@ public class HardThirdSelfZyServiceImpl implements HardThirdSelfZyService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public HardCallbackPayVo pay(HardCallbackPayDto dto) {
|
||||
// 钱包
|
||||
try {
|
||||
// 钱包
|
||||
WalletManageEntity wallet = remoteWalletService.getWallet(dto.getUserId(), WalletTypeEnum.EAT).getData();
|
||||
if (ObjectUtil.isEmpty(wallet)) throw new RuntimeException("用户钱包不存在");
|
||||
// 用户
|
||||
UserInfo user = remoteUserService.getByUserId(wallet.getUserId()).getData();
|
||||
if (ObjectUtil.isEmpty(user)) throw new RuntimeException("用户不存在");
|
||||
Integer balance = wallet.getBalance();
|
||||
int totalPrice = dto.getPayPrice();
|
||||
if (balance < totalPrice) {
|
||||
@@ -53,9 +72,10 @@ public class HardThirdSelfZyServiceImpl implements HardThirdSelfZyService {
|
||||
res.setCode(HardCallbackPayStatus.NOT_SUFFICIENT_FUNDS);
|
||||
return res;
|
||||
}
|
||||
String subject = "正元公务餐扣款";
|
||||
String subject = "正元公务餐物品 * ?";
|
||||
// 添加硬件订单
|
||||
HardOrderEntity orderObj = HardOrderEntity.builder()
|
||||
.orderNo(dto.getOrderNo())
|
||||
.userId(dto.getUserId())
|
||||
.parentCarId(null)
|
||||
.sysType(null)
|
||||
@@ -77,10 +97,12 @@ public class HardThirdSelfZyServiceImpl implements HardThirdSelfZyService {
|
||||
HardCallbackPayVo result = new HardCallbackPayVo();
|
||||
result.setCode(HardCallbackPayStatus.SUCCESS);
|
||||
result.setOrderId(orderObj.getId());
|
||||
result.setUserId(user.getSysUser().getUserId());
|
||||
result.setUsername(user.getSysUser().getName());
|
||||
result.setPayTime(LocalDateTime.now());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|意外得错误dto:|{}|", TAG, JSONUtil.toJsonStr(dto), e);
|
||||
log.error("|{}| pay 意外的错误dto:|{}|", TAG, JSONUtil.toJsonStr(dto), e);
|
||||
HardCallbackPayVo result = new HardCallbackPayVo();
|
||||
result.setCode(HardCallbackPayStatus.REPETITION);
|
||||
return result;
|
||||
@@ -92,8 +114,54 @@ public class HardThirdSelfZyServiceImpl implements HardThirdSelfZyService {
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String refund(HardCallbackRefundDto dto) {
|
||||
return "-1";
|
||||
public HardCallbackRefundVo refund(HardCallbackRefundDto dto) {
|
||||
try {
|
||||
// 校验订单是否可以退款
|
||||
HardOrderVo order = hardAfterSaleService.validateOrderCanRefund(dto.getOrderId());
|
||||
// 用户
|
||||
UserInfo user = remoteUserService.getByUserId(order.getUserId()).getData();
|
||||
if (ObjectUtil.isEmpty(user)) throw new RuntimeException("用户不存在");
|
||||
// 添加售后订单
|
||||
HardAfterSaleEntity saveObj = BeanUtils.toBean(dto, HardAfterSaleEntity.class);
|
||||
String refundCode = "hard_" + order.getId();
|
||||
saveObj.setType(HardSaleTypeEnum.AFTER_SALE.getType());
|
||||
saveObj.setStatus(HardSaleStatusEnum.COMPLETE.getStatus());
|
||||
saveObj.setNo(refundCode);
|
||||
saveObj.setOrderId(order.getId());
|
||||
saveObj.setRefundPrice(order.getPayPrice());
|
||||
saveObj.setUserId(order.getUserId());
|
||||
saveObj.setAuditUserId(null);
|
||||
saveObj.setAuditTime(LocalDateTime.now());
|
||||
saveObj.setAuditReason("后台退款");
|
||||
hardAfterSaleService.save(saveObj);
|
||||
// 添加售后进度
|
||||
HardAfterSaleLogEntity saveLogObj = HardAfterSaleLogEntity.builder()
|
||||
.afterSaleId(saveObj.getId())
|
||||
.userId(order.getUserId())
|
||||
.operateType(HardAfterSaleOperateTypeEnum.ADMIN_REFUND.getType())
|
||||
.beforeStatus(order.getOrderStatus())
|
||||
.afterStatus(HardSaleStatusEnum.COMPLETE.getStatus())
|
||||
.content(HardSaleStatusEnum.COMPLETE.getContent())
|
||||
.build();
|
||||
hardAfterSaleLogMapper.insert(saveLogObj);
|
||||
// 执行退款
|
||||
hardAfterSaleService.refund(saveObj.getId());
|
||||
// 退库存
|
||||
hardOrderService.fastenerInventory(order, YesNoEnum.NO);
|
||||
HardCallbackRefundVo result = new HardCallbackRefundVo();
|
||||
result.setCode(HardCallbackRefundStatus.SUCCESS);
|
||||
result.setRefundId(String.valueOf(saveObj.getId()));
|
||||
result.setOrderNo(order.getOrderNo());
|
||||
result.setUserId(user.getSysUser().getUserId());
|
||||
result.setUsername(user.getSysUser().getName());
|
||||
result.setRefundTime(LocalDateTime.now());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("|{}| pay 意外的错误dto:|{}|", TAG, JSONUtil.toJsonStr(dto), e);
|
||||
HardCallbackRefundVo result = new HardCallbackRefundVo();
|
||||
result.setCode(HardCallbackRefundStatus.REPETITION);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -297,7 +297,7 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
}
|
||||
|
||||
// 校验订单是否可以退款
|
||||
private HardOrderVo validateOrderCanRefund(Long orderId) {
|
||||
public HardOrderVo validateOrderCanRefund(Long orderId) {
|
||||
HardOrderEntity order = hardOrderService.getById(orderId);
|
||||
if (ObjectUtil.isEmpty(order)) throw new RuntimeException("订单不存在");
|
||||
HardOrderVo orderVo = BeanUtils.toBean(order, HardOrderVo.class);
|
||||
|
||||
+1
@@ -41,6 +41,7 @@ public class ThirdZyLogController {
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdZyLog_view')")
|
||||
public R getThirdZyLogPage(@ParameterObject Page page, @ParameterObject ThirdZyLogEntity thirdZyLog) {
|
||||
LambdaQueryWrapper<ThirdZyLogEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.orderByDesc(ThirdZyLogEntity::getCreateTime);
|
||||
return R.ok(thirdZyLogService.page(page, wrapper));
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -20,6 +20,14 @@ public interface ThirdZyIdDictMapper extends PjcloudBaseMapper<ThirdZyIdDictEnti
|
||||
return selectList(wrapper);
|
||||
}
|
||||
|
||||
default ThirdZyIdDictEntity getBySelfId(ThirdZyBizEnumType type, String selfId) {
|
||||
if (ObjectUtil.isEmpty(type)) return null;
|
||||
LambdaQueryWrapper<ThirdZyIdDictEntity> wrapper = new LambdaQueryWrapper<ThirdZyIdDictEntity>()
|
||||
.eq(ObjectUtil.isNotEmpty(selfId), ThirdZyIdDictEntity::getSelfId, selfId)
|
||||
.eq(ThirdZyIdDictEntity::getBizType, type.getType());
|
||||
return selectOne(wrapper);
|
||||
}
|
||||
|
||||
default List<ThirdZyIdDictEntity> getByZyIds(ThirdZyBizEnumType type, List<String> zyIds) {
|
||||
if (ObjectUtil.isEmpty(type)) return null;
|
||||
LambdaQueryWrapper<ThirdZyIdDictEntity> wrapper = new LambdaQueryWrapper<ThirdZyIdDictEntity>()
|
||||
|
||||
+57
-10
@@ -8,12 +8,16 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.common.core.constant.CacheConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.hard.api.constant.third.HardCallbackRefundStatus;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackPayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.third.HardCallbackRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.feign.RemoteHardThirdSelfZyService;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackPayVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackRefundVo;
|
||||
import com.bsd.pjcloud.thirdparty.config.ZyConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.ThirdZyBizEnumType;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfCorrectDto;
|
||||
@@ -98,6 +102,7 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService {
|
||||
ThirdZyBizEnumType bizType = ThirdZyBizEnumType.SELF_CORRECT;
|
||||
ThirdZyLogEntity entity = new ThirdZyLogEntity();
|
||||
entity.setBizType(bizType.getType());
|
||||
entity.setApiUrl(ZyApi.Self.CORRECT);
|
||||
long startTime = System.currentTimeMillis();
|
||||
ZySelfCorrectVo result = new ZySelfCorrectVo();
|
||||
try {
|
||||
@@ -111,14 +116,45 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService {
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
// 校验加密参数
|
||||
String resJson = checkSign(params);
|
||||
if (ObjectUtil.isEmpty(resJson)) {
|
||||
String jsonRes = checkSign(params);
|
||||
if (ObjectUtil.isEmpty(jsonRes)) {
|
||||
String msg = "数据加密认证失败!sign值验证失败";
|
||||
result.setCode(ZyBaseVo.signError);
|
||||
result.setMsg(msg);
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
return BeanUtil.beanToMap(result);
|
||||
result.setCode(ZyBaseVo.errorCode);
|
||||
result.setMsg(ZyBaseVo.defaultErrorMsg);
|
||||
ZySelfCorrectDto dto = JSONUtil.toBean(jsonRes, ZySelfCorrectDto.class);
|
||||
entity.setEncipherReq(JSONUtil.toJsonStr(dto));
|
||||
// 获取参数
|
||||
String correctSerialNum = dto.getCorrectSerialNum();
|
||||
Long orderId = Long.parseLong(correctSerialNum);
|
||||
// 调用硬件接口
|
||||
HardCallbackRefundDto refundDto = new HardCallbackRefundDto();
|
||||
refundDto.setOrderId(orderId);
|
||||
refundDto.setSerialNum(dto.getSerialNum());
|
||||
HardCallbackRefundVo refundRes = hardCallback.refund(refundDto).getData();
|
||||
result.setCode(refundRes.getCode().getType());
|
||||
switch (refundRes.getCode()) {
|
||||
case SUCCESS -> {
|
||||
ThirdZyIdDictEntity userIdDict = thirdZyIdDictMapper.getBySelfId(ThirdZyBizEnumType.SYNC_ACCOUNT_INFO, String.valueOf(refundRes.getUserId()));
|
||||
String userZyId = userIdDict.getZyId();
|
||||
result.setAccNum(userZyId);
|
||||
result.setAccName(refundRes.getUsername());
|
||||
result.setPerCode(userZyId);
|
||||
result.setPlatformSerialNum(String.valueOf(refundRes.getRefundId()));
|
||||
result.setSerialNum(refundRes.getOrderNo());
|
||||
result.setRecDate(LocalDateTimeUtil.format(refundRes.getRefundTime(), DatePattern.NORM_DATETIME_PATTERN));
|
||||
result.setAmount(dto.getAmount());
|
||||
result.setMsg(ZyBaseVo.selfSuccessMsg);
|
||||
entity.setOrgReq(JSONUtil.toJsonStr(result));
|
||||
Map<String, Object> encryptionRes = zyApiTool.getSelfEncryptionMap(BeanUtil.beanToMap(result));
|
||||
entity.setEncipherReq(JSONUtil.toJsonStr(encryptionRes));
|
||||
return encryptionRes;
|
||||
}
|
||||
default -> throw new RuntimeException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String error = String.format("|%s||correct|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
|
||||
log.error(error);
|
||||
@@ -138,7 +174,9 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService {
|
||||
public Map<String, Object> pay(ZySelfPayDto params, String accessToken) {
|
||||
ThirdZyBizEnumType bizType = ThirdZyBizEnumType.SELF_PAY;
|
||||
ThirdZyLogEntity entity = new ThirdZyLogEntity();
|
||||
entity.setApiUrl(ZyApi.Self.PAY);
|
||||
entity.setBizType(bizType.getType());
|
||||
entity.setEncipherReq(JSONUtil.toJsonStr(params));
|
||||
long startTime = System.currentTimeMillis();
|
||||
ZySelfPayVo result = new ZySelfPayVo();
|
||||
try {
|
||||
@@ -162,8 +200,10 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService {
|
||||
result.setCode(ZyBaseVo.errorCode);
|
||||
result.setMsg(ZyBaseVo.defaultErrorMsg);
|
||||
ZySelfPayDto dto = JSONUtil.toBean(jsonRes, ZySelfPayDto.class);
|
||||
entity.setEncipherReq(JSONUtil.toJsonStr(dto));
|
||||
// 获取参数
|
||||
String accNum = dto.getAccNum();
|
||||
ThirdZyIdDictEntity userIdDict = thirdZyIdDictMapper.getByZyIds(bizType, accNum);
|
||||
ThirdZyIdDictEntity userIdDict = thirdZyIdDictMapper.getByZyIds(ThirdZyBizEnumType.SYNC_ACCOUNT_INFO, accNum);
|
||||
if (ObjectUtil.isEmpty(userIdDict)) {
|
||||
throw new RuntimeException("用户id不存在");
|
||||
}
|
||||
@@ -184,7 +224,6 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService {
|
||||
result.setCode(payRes.getCode().getType());
|
||||
switch (payRes.getCode()) {
|
||||
case SUCCESS -> {
|
||||
result.setMsg(ZyBaseVo.selfSuccessMsg);
|
||||
result.setAccNum(payRes.getUserId().toString());
|
||||
result.setAccName(payRes.getUsername());
|
||||
result.setPerCode(payRes.getUserId().toString());
|
||||
@@ -192,11 +231,13 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService {
|
||||
result.setSerialNum(dto.getSerialNum());
|
||||
result.setAmount(amount);
|
||||
result.setRecDate(LocalDateTimeUtil.format(payRes.getPayTime(), DatePattern.NORM_DATETIME_PATTERN));
|
||||
return zyApiTool.getSelfEncryptionMap(BeanUtil.beanToMap(result));
|
||||
}
|
||||
default -> {
|
||||
return result.getErrorMap();
|
||||
result.setMsg(ZyBaseVo.selfSuccessMsg);
|
||||
entity.setOrgReq(JSONUtil.toJsonStr(result));
|
||||
Map<String, Object> encryptionRes = zyApiTool.getSelfEncryptionMap(BeanUtil.beanToMap(result));
|
||||
entity.setEncipherReq(JSONUtil.toJsonStr(encryptionRes));
|
||||
return encryptionRes;
|
||||
}
|
||||
default -> throw new RuntimeException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String error = String.format("|%s||pay|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
|
||||
@@ -310,8 +351,14 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService {
|
||||
entry.setValue(Base64.decodeStr(value.toString()));
|
||||
}
|
||||
}
|
||||
String string = zyApiTool.getResultSign(paramsMap);
|
||||
String string = zyApiTool.generateSign(paramsMap, false);
|
||||
if (ObjectUtil.equals(sign, string)) {
|
||||
for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof String) {
|
||||
entry.setValue(URLUtil.decode((String) value));
|
||||
}
|
||||
}
|
||||
return JSONUtil.toJsonStr(paramsMap);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+1
-13
@@ -170,18 +170,6 @@ public class ZyApiTool {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getResultSign(Map<String, Object> params) {
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof String) {
|
||||
entry.setValue(Base64.encode((String) value));
|
||||
} else {
|
||||
entry.setValue(Base64.encode(value.toString()));
|
||||
}
|
||||
}
|
||||
return generateSign(params, false);
|
||||
}
|
||||
|
||||
private void prePost(Map<String, Object> params, boolean isZy) {
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
@@ -204,7 +192,7 @@ public class ZyApiTool {
|
||||
params.put("sign", sign);
|
||||
}
|
||||
|
||||
private String generateSign(Map<String, Object> params, boolean isZy) {
|
||||
public String generateSign(Map<String, Object> params, boolean isZy) {
|
||||
// 将参数以参数名的字典升序排序
|
||||
Map<String, Object> sortParams = new TreeMap<String, Object>(params);
|
||||
Set<Map.Entry<String, Object>> entrys = sortParams.entrySet();
|
||||
|
||||
+78
@@ -1,39 +1,56 @@
|
||||
package com.bsd.pjcloud.admin;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.thirdparty.ThirdPartyApp;
|
||||
import com.bsd.pjcloud.thirdparty.config.ZyConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.ThirdZyBizEnumType;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.foreign.ZyForeignSyncNativeCardTradeInfoDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncAccClassInfoDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncAccountInfoDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncDealerInfoDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncEnterpriseInfoDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfCorrectDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfGetTokenDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.self.ZySelfPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.stride.ZyStrideAuthenticationDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.stride.ZyStrideConsumptionDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.zy.stride.ZyStrideCorrectDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.zy.ThirdZyIdDictEntity;
|
||||
import com.bsd.pjcloud.thirdparty.mapper.zy.ThirdZyIdDictMapper;
|
||||
import com.bsd.pjcloud.thirdparty.service.impl.ThirdZyForeignService;
|
||||
import com.bsd.pjcloud.thirdparty.service.impl.ThirdZyMerService;
|
||||
import com.bsd.pjcloud.thirdparty.service.impl.ThirdZySelfService;
|
||||
import com.bsd.pjcloud.thirdparty.service.impl.ThirdZyStrideService;
|
||||
import com.bsd.pjcloud.thirdparty.utils.zy.api.ZyApiTool;
|
||||
import com.bsd.pjcloud.thirdparty.vo.zy.foreign.ZyForeignGetRegionIdByTokenVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.zy.foreign.ZyForeignSyncNativeCardTradeInfoVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.zy.mer.*;
|
||||
import com.bsd.pjcloud.thirdparty.vo.zy.self.ZySelfGetTokenVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.zy.stride.ZyStrideAuthenticationVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.zy.stride.ZyStrideConsumptionVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.zy.stride.ZyStrideCorrectVo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SpringBootTest(classes = ThirdPartyApp.class)
|
||||
public class ZyTest {
|
||||
|
||||
@Resource
|
||||
private ZyApiTool zyApiTool;
|
||||
@Autowired
|
||||
private ZyConfig zyConfig;
|
||||
|
||||
@Resource
|
||||
private ThirdZyMerService zyMerService;
|
||||
@@ -41,9 +58,70 @@ public class ZyTest {
|
||||
private ThirdZyForeignService zyForeignService;
|
||||
@Resource
|
||||
private ThirdZyStrideService zyStrideService;
|
||||
@Resource
|
||||
private ThirdZySelfService zySelfService;
|
||||
|
||||
@Resource
|
||||
private ThirdZyIdDictMapper zyIdDictMapper;
|
||||
|
||||
/************************** start mer start **************************/
|
||||
|
||||
|
||||
@Test
|
||||
public void selfPay() throws Exception {
|
||||
String dzcUserId = "1875049673022279681";
|
||||
String dzcWalletId = "1877309001545244673";
|
||||
String date = LocalDateTimeUtil.format(LocalDateTimeUtil.now(), DatePattern.NORM_DATETIME_PATTERN);
|
||||
ThirdZyIdDictEntity dzcUserDict = zyIdDictMapper.getBySelfId(ThirdZyBizEnumType.SYNC_ACCOUNT_INFO, dzcUserId);
|
||||
|
||||
ZySelfGetTokenDto tokenParams = new ZySelfGetTokenDto();
|
||||
tokenParams.setAppid(zyConfig.getSelfAppId());
|
||||
tokenParams.setAppsecret(zyConfig.getSelfAppSecret());
|
||||
ZySelfGetTokenVo token = zySelfService.getToken(tokenParams);
|
||||
String accessToken = token.getAccess_token();
|
||||
|
||||
ZySelfPayDto params = ZySelfPayDto
|
||||
.builder()
|
||||
.accNum(dzcUserDict.getZyId())
|
||||
.cardAccNum(dzcWalletId)
|
||||
.amount("10")
|
||||
.serialNum("01234567890123456789")
|
||||
.dealTime(date)
|
||||
.opId("0123456789")
|
||||
.build();
|
||||
Map<String, Object> paramsMap = BeanUtil.beanToMap(params);
|
||||
Map<String, Object> body = zyApiTool.getSelfEncryptionMap(paramsMap, "accNum", "cardAccNum", "amount", "serialNum", "dealTime", "opId");
|
||||
ZySelfPayDto bodyObj = JSONUtil.toBean(JSONUtil.toJsonStr(body), ZySelfPayDto.class);
|
||||
Map<String, Object> pay = zySelfService.pay(bodyObj, accessToken);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selfRefund() throws Exception {
|
||||
|
||||
String orderId = "1";
|
||||
String orderNo = "1";
|
||||
|
||||
ZySelfGetTokenDto tokenParams = new ZySelfGetTokenDto();
|
||||
tokenParams.setAppid(zyConfig.getSelfAppId());
|
||||
tokenParams.setAppsecret(zyConfig.getSelfAppSecret());
|
||||
ZySelfGetTokenVo token = zySelfService.getToken(tokenParams);
|
||||
String accessToken = token.getAccess_token();
|
||||
|
||||
ZySelfCorrectDto params = ZySelfCorrectDto
|
||||
.builder()
|
||||
.serialNum(orderNo)
|
||||
.correctSerialNum(orderId)
|
||||
.amount("10")
|
||||
.opId("01234567890123456789")
|
||||
.build();
|
||||
|
||||
Map<String, Object> paramsMap = BeanUtil.beanToMap(params);
|
||||
Map<String, Object> body = zyApiTool.getSelfEncryptionMap(paramsMap, "serialNum", "correctSerialNum", "amount", "opId");
|
||||
|
||||
ZySelfCorrectDto bodyObj = JSONUtil.toBean(JSONUtil.toJsonStr(body), ZySelfCorrectDto.class);
|
||||
Map<String, Object> pay = zySelfService.correct(bodyObj, accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user