diff --git a/src/main/java/cn/com/tenlion/operator/controller/api/accountrecharge/AccountRechargeController.java b/src/main/java/cn/com/tenlion/operator/controller/api/accountrecharge/AccountRechargeController.java index 828c7f5..0a15aa3 100644 --- a/src/main/java/cn/com/tenlion/operator/controller/api/accountrecharge/AccountRechargeController.java +++ b/src/main/java/cn/com/tenlion/operator/controller/api/accountrecharge/AccountRechargeController.java @@ -3,6 +3,7 @@ package cn.com.tenlion.operator.controller.api.accountrecharge; import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayDTO; import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayResultDTO; import cn.com.tenlion.operator.pojo.vos.accountitem.AccountItemVO; +import cn.com.tenlion.operator.pojo.vos.accountrecharge.AccountRechargeWxPrepayVO; import cn.com.tenlion.operator.util.pay.PayUtil; import ink.wgink.annotation.CheckRequestBodyAnnotation; import ink.wgink.common.base.DefaultBaseController; @@ -57,6 +58,15 @@ public class AccountRechargeController extends DefaultBaseController { return url; } + @ApiOperation(value = "保存微信预支付充值", notes = "保存微信预支付充值接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("save-wx-pay-prepay-id") + @CheckRequestBodyAnnotation + public SuccessResult saveWxPayPrepayId(@RequestBody AccountRechargeWxPrepayVO accountRechargeWxPrepayVO) { + String prepayId = accountRechargeService.saveWxPayPrepayId(accountRechargeWxPrepayVO); + return new SuccessResultData<>(prepayId); + } + // @ApiOperation(value = "账户确认到账", notes = "账户确认到账接口") // @ApiImplicitParams({ // @ApiImplicitParam(name = "ids", value = "ID列表,用下划线分隔", paramType = "path", example = "1_2_3") @@ -80,7 +90,7 @@ public class AccountRechargeController extends DefaultBaseController { @ApiOperation(value = "删除账户充值", notes = "删除账户充值接口") @ApiImplicitParams({ - @ApiImplicitParam(name = "ids", value = "ID列表,用下划线分隔", paramType = "path", example = "1_2_3") + @ApiImplicitParam(name = "ids", value = "ID列表,用下划线分隔", paramType = "path", example = "1_2_3") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @DeleteMapping("remove/{ids}") @@ -91,7 +101,7 @@ public class AccountRechargeController extends DefaultBaseController { @ApiOperation(value = "修改账户充值", notes = "修改账户充值接口") @ApiImplicitParams({ - @ApiImplicitParam(name = "accountRechargeId", value = "账户充值ID", paramType = "path") + @ApiImplicitParam(name = "accountRechargeId", value = "账户充值ID", paramType = "path") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PutMapping("update/{accountRechargeId}") @@ -103,13 +113,13 @@ public class AccountRechargeController extends DefaultBaseController { @ApiOperation(value = "修改账户充值", notes = "修改账户充值接口") @ApiImplicitParams({ - @ApiImplicitParam(name = "accountRechargeId", value = "账户充值ID", paramType = "path") + @ApiImplicitParam(name = "accountRechargeId", value = "账户充值ID", paramType = "path") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PutMapping("update-close") @CheckRequestBodyAnnotation public SuccessResult updateClose(@RequestBody IdsVO idsVO) { - if(idsVO.getIds().isEmpty()) { + if (idsVO.getIds().isEmpty()) { throw new ParamsException("ids不能为空"); } accountRechargeService.updateCloseByIds(idsVO.getIds()); @@ -118,11 +128,11 @@ public class AccountRechargeController extends DefaultBaseController { @ApiOperation(value = "账户充值详情", notes = "账户充值详情接口") @ApiImplicitParams({ - @ApiImplicitParam(name = "accountRechargeId", value = "账户充值ID", paramType = "path") + @ApiImplicitParam(name = "accountRechargeId", value = "账户充值ID", paramType = "path") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get/{accountRechargeId}") - public AccountRechargeDTO get(@PathVariable("accountRechargeId") String accountRechargeId) { + public AccountRechargeDTO get(@PathVariable("accountRechargeId") String accountRechargeId) { return accountRechargeService.get(accountRechargeId); } @@ -136,11 +146,11 @@ public class AccountRechargeController extends DefaultBaseController { @ApiOperation(value = "账户充值分页列表", notes = "账户充值分页列表接口") @ApiImplicitParams({ - @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"), - @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"), - @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"), - @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"), - @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String") + @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"), + @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"), + @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listpage") diff --git a/src/main/java/cn/com/tenlion/operator/pojo/vos/accountrecharge/AccountRechargeWxPrepayVO.java b/src/main/java/cn/com/tenlion/operator/pojo/vos/accountrecharge/AccountRechargeWxPrepayVO.java new file mode 100644 index 0000000..97598f0 --- /dev/null +++ b/src/main/java/cn/com/tenlion/operator/pojo/vos/accountrecharge/AccountRechargeWxPrepayVO.java @@ -0,0 +1,39 @@ +package cn.com.tenlion.operator.pojo.vos.accountrecharge; + +import ink.wgink.annotation.CheckNumberAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * @ClassName: AccountRechargeVO + * @Description: 账户充值 + * @Author: CodeFactory + * @Date: 2024-01-13 14:38:21 + * @Version: 3.0 + **/ +@ApiModel +public class AccountRechargeWxPrepayVO { + + @ApiModelProperty(name = "rechargeMoney", value = "充值金额") + @CheckNumberAnnotation(name = "金额") + private Double rechargeMoney; + @ApiModelProperty(name = "packageInfoId", value = "自定义回调函数/2025年2月28日10:03:44/CBC新增") + private String packageInfoId; + + public String getPackageInfoId() { + return packageInfoId == null ? "" : packageInfoId.trim(); + } + + public void setPackageInfoId(String packageInfoId) { + this.packageInfoId = packageInfoId; + } + + public Double getRechargeMoney() { + return rechargeMoney == null ? 0 : rechargeMoney; + } + + public void setRechargeMoney(Double rechargeMoney) { + this.rechargeMoney = rechargeMoney; + } + +} diff --git a/src/main/java/cn/com/tenlion/operator/service/accountrecharge/IAccountRechargeService.java b/src/main/java/cn/com/tenlion/operator/service/accountrecharge/IAccountRechargeService.java index 3838e2a..225812a 100644 --- a/src/main/java/cn/com/tenlion/operator/service/accountrecharge/IAccountRechargeService.java +++ b/src/main/java/cn/com/tenlion/operator/service/accountrecharge/IAccountRechargeService.java @@ -3,6 +3,7 @@ package cn.com.tenlion.operator.service.accountrecharge; import cn.com.tenlion.operator.enums.RechargeCheckEnum; import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayDTO; import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayResultDTO; +import cn.com.tenlion.operator.pojo.vos.accountrecharge.AccountRechargeWxPrepayVO; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.result.SuccessResultList; import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargeDTO; @@ -191,6 +192,8 @@ public interface IAccountRechargeService { AccountRechargePayDTO saveAccount(String thirdParty, AccountRechargeVO accountRechargeVO); + String saveWxPayPrepayId(AccountRechargeWxPrepayVO accountRechargeWxPrepayVO); + void updateClose(String accountRechargeId); void updateCloseByIds(List accountRechargeIds); diff --git a/src/main/java/cn/com/tenlion/operator/service/accountrecharge/impl/AccountRechargeServiceImpl.java b/src/main/java/cn/com/tenlion/operator/service/accountrecharge/impl/AccountRechargeServiceImpl.java index 982c5d3..264645f 100644 --- a/src/main/java/cn/com/tenlion/operator/service/accountrecharge/impl/AccountRechargeServiceImpl.java +++ b/src/main/java/cn/com/tenlion/operator/service/accountrecharge/impl/AccountRechargeServiceImpl.java @@ -8,17 +8,15 @@ import cn.com.tenlion.operator.pojo.dtos.account.AccountDTO; import cn.com.tenlion.operator.pojo.dtos.accountbank.AccountBankDTO; import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayDTO; import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayResultDTO; -import cn.com.tenlion.operator.pojo.dtos.ic.UsericDTO; import cn.com.tenlion.operator.pojo.vos.accountitem.AccountItemVO; +import cn.com.tenlion.operator.pojo.vos.accountrecharge.AccountRechargeWxPrepayVO; import cn.com.tenlion.operator.properties.SystemApiPathProperties; import cn.com.tenlion.operator.remote.IOperatorPluginRemoteService; -import cn.com.tenlion.operator.remote.PackageInfoDTO; import cn.com.tenlion.operator.remote.PackageOrderAppVO; import cn.com.tenlion.operator.remote.PackageOrderDTO; import cn.com.tenlion.operator.service.account.IAccountService; import cn.com.tenlion.operator.service.accountbank.IAccountBankService; import cn.com.tenlion.operator.service.accountitem.IAccountItemService; -import cn.com.tenlion.operator.service.remote.IRemoteWangGengInvoiceService; import cn.com.tenlion.operator.service.sys.callback.SysCallbackService; import cn.com.tenlion.operator.util.TenlionSMS; import cn.com.tenlion.operator.util.UserUtil; @@ -29,7 +27,6 @@ import cn.com.tenlion.operator.util.pay.WXPay; import cn.com.tenlion.projectconfig.util.ProjectConfigUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson2.JSON; import ink.wgink.common.base.DefaultBaseService; import ink.wgink.exceptions.ParamsException; import ink.wgink.exceptions.SaveException; @@ -38,7 +35,6 @@ import ink.wgink.interfaces.user.IUserBaseService; import ink.wgink.module.oauth2.manager.OAuth2ClientTokenManager; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.dtos.user.UserDTO; -import ink.wgink.pojo.result.SuccessResult; import ink.wgink.pojo.result.SuccessResultData; import ink.wgink.pojo.result.SuccessResultList; import ink.wgink.util.date.DateUtil; @@ -317,7 +313,7 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA accountRechargeDao.updateCheck(params); AccountRechargeDTO dto = get(accountRechargeId); // 创建套餐包关闭支付 - if(!StringUtils.isEmpty(dto.getPackageInfoId())) { + if (!StringUtils.isEmpty(dto.getPackageInfoId())) { String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); SuccessResultData result = operatorPluginRemoteService.updateClose(systemApiPathProperties.getOperatorPlugin(), accountRechargeId, accessToken); if (!result.getData().equals("Success")) { @@ -364,18 +360,18 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA // 2025年2月28日11:12:47 CBC 新增 套餐包 逻辑 AccountRechargeDTO dto = get(accountRechargeId); // 绑定了套餐包 & 已对账 & 已到账 - if(!StringUtils.isEmpty(dto.getPackageInfoId()) && dto.getReconciliationStatus().equals("1") && dto.getRechargeCheck().equals("2")) { + if (!StringUtils.isEmpty(dto.getPackageInfoId()) && dto.getReconciliationStatus().equals("1") && dto.getRechargeCheck().equals("2")) { String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); - PackageOrderDTO packageInfoDTO = operatorPluginRemoteService.getByNo(systemApiPathProperties.getOperatorPlugin(), accountRechargeId , accessToken); + PackageOrderDTO packageInfoDTO = operatorPluginRemoteService.getByNo(systemApiPathProperties.getOperatorPlugin(), accountRechargeId, accessToken); // 远程更改套餐包的付款到账状态 String accountItemId1 = UUIDUtil.getUUID(); // 获取用户余额 , 如果不够 , 则不购买 AccountDTO accountDTO = iAccountService.get(dto.getAccountId()); - if(accountDTO.getAccountMoney() >= packageInfoDTO.getPackageTotalMoney()) { + if (accountDTO.getAccountMoney() >= packageInfoDTO.getPackageTotalMoney()) { SuccessResultData result = operatorPluginRemoteService.updatePay(systemApiPathProperties.getOperatorPlugin(), accountRechargeId, accountItemId1, accessToken); if (result.getData().equals("Success")) { AccountDTO accountDTO2 = iAccountService.get(dto.getAccountId()); - if(accountDTO2.getAccountMoney() >= packageInfoDTO.getPackageTotalMoney()) { + if (accountDTO2.getAccountMoney() >= packageInfoDTO.getPackageTotalMoney()) { /** * 1. 创建流水 */ @@ -389,13 +385,13 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA vo.setDescription("购买" + (packageInfoDTO.getPackageInfoAppDTO().getPackageType().equals("ALL") ? "全托管" : "写材料") + "套餐包 " + packageInfoDTO.getPackageInfoAppDTO().getPackageCount() + " 件:" + packageInfoDTO.getPackageInfoAppDTO().getPackageName()); iAccountItemService.saveReturnId(vo); } - }else{ + } else { System.out.println("调用套餐包到账结果 : " + result); } } } // 绑定了套餐包 & 已对账 & 已关闭 - if(!StringUtils.isEmpty(dto.getPackageInfoId()) && dto.getReconciliationStatus().equals("1") && dto.getRechargeCheck().equals("-1")) { + if (!StringUtils.isEmpty(dto.getPackageInfoId()) && dto.getReconciliationStatus().equals("1") && dto.getRechargeCheck().equals("-1")) { String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); SuccessResultData result = operatorPluginRemoteService.updateClose(systemApiPathProperties.getOperatorPlugin(), accountRechargeId, accessToken); if (!result.getData().equals("Success")) { @@ -409,74 +405,118 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA public AccountRechargePayDTO saveAccount(String thirdParty, AccountRechargeVO accountRechargeVO) { AccountRechargePayDTO payDTO = new AccountRechargePayDTO(); // synchronized (lock) { - String userId = accountRechargeVO.getUserId(); - // 未支付的订单 - Integer count = countByUserIdAndRechargeCheck(userId, RechargeCheckEnum.UN_RECHARGE); + String userId = accountRechargeVO.getUserId(); + // 未支付的订单 +// Integer count = countByUserIdAndRechargeCheck(userId, RechargeCheckEnum.UN_RECHARGE); /* if (count > ProjectConfigUtil.getInt("ToDayMaxRechargeCount")) { throw new SaveException("超过创建订单数量上限"); }*/ - accountRechargeVO.setThirdParty(thirdParty); - accountRechargeVO.setAccountId(userId); - accountRechargeVO.setRechargeCheck(RechargeCheckEnum.UN_RECHARGE.getValue()); - accountRechargeVO.setReconciliationStatus(ReconciliationStatusEnum.UN_RECONCILIATION.getValue()); - Integer totalMoney = PayUtil.buiderMoney(accountRechargeVO.getRechargeMoney()); - String currentDate = DateUtil.getTime(); + accountRechargeVO.setThirdParty(thirdParty); + accountRechargeVO.setAccountId(userId); + accountRechargeVO.setRechargeCheck(RechargeCheckEnum.UN_RECHARGE.getValue()); + accountRechargeVO.setReconciliationStatus(ReconciliationStatusEnum.UN_RECONCILIATION.getValue()); + Integer totalMoney = PayUtil.buiderMoney(accountRechargeVO.getRechargeMoney()); + String currentDate = DateUtil.getTime(); - Map params = HashMapUtil.beanToMap(accountRechargeVO); - if (ThirdPartyEnum.WX.getValue().equals(thirdParty)) { - String accountRechargeId = getUUID("wx"); - params.put("rechargeType", RechargeTypeEnum.ONLINE.getValue()); - params.put("accountRechargeId", accountRechargeId); - params.put("rechargeFinalTime", currentDate); + Map params = HashMapUtil.beanToMap(accountRechargeVO); + if (ThirdPartyEnum.WX.getValue().equals(thirdParty)) { + String accountRechargeId = getUUID("wx"); + params.put("rechargeType", RechargeTypeEnum.ONLINE.getValue()); + params.put("accountRechargeId", accountRechargeId); + params.put("rechargeFinalTime", currentDate); - String brcode = WXPay.createPay(accountRechargeId, totalMoney, ProjectConfigUtil.getText("RechargePayTitle")); - payDTO.setAccountRechargeId(accountRechargeId); - payDTO.setThirdParty(thirdParty); - payDTO.setThirdPartyPayUrl(brcode); - } else if (ThirdPartyEnum.ZFB.getValue().equals(thirdParty)) { - String accountRechargeId = getUUID("zfb"); - params.put("rechargeType", RechargeTypeEnum.ONLINE.getValue()); - params.put("accountRechargeId", accountRechargeId); - params.put("rechargeFinalTime", currentDate); + String brcode = WXPay.createPay(accountRechargeId, totalMoney, ProjectConfigUtil.getText("RechargePayTitle")); + payDTO.setAccountRechargeId(accountRechargeId); + payDTO.setThirdParty(thirdParty); + payDTO.setThirdPartyPayUrl(brcode); + } else if (ThirdPartyEnum.ZFB.getValue().equals(thirdParty)) { + String accountRechargeId = getUUID("zfb"); + params.put("rechargeType", RechargeTypeEnum.ONLINE.getValue()); + params.put("accountRechargeId", accountRechargeId); + params.put("rechargeFinalTime", currentDate); - String brcode = ALiPay.createPay(accountRechargeId, totalMoney, ProjectConfigUtil.getText("RechargePayTitle")); - payDTO.setAccountRechargeId(accountRechargeId); - payDTO.setThirdParty(thirdParty); - payDTO.setThirdPartyPayUrl(brcode); - } else if (ThirdPartyEnum.DGZZ.getValue().equals(thirdParty)) { - String accountRechargeId = getUUID("oto"); - params.put("rechargeType", RechargeTypeEnum.OFFLINE.getValue()); - params.put("accountRechargeId", accountRechargeId); - payDTO.setAccountRechargeId(accountRechargeId); - } else { - throw new ParamsException("充值类型错误"); - } - params.put("creator", userId); - params.put("gmtCreate", currentDate); - params.put("modifier", userId); - params.put("gmtModified", currentDate); - params.put("isDelete", 0); - accountRechargeDao.save(params); - - // 创建套餐包购买记录 - if(!StringUtils.isEmpty(accountRechargeVO.getPackageInfoId())) { - PackageOrderAppVO appVO = new PackageOrderAppVO(); - appVO.setPackageInfoId(accountRechargeVO.getPackageInfoId()); - appVO.setUserId(userId); - appVO.setAccountRechargeId(payDTO.getAccountRechargeId()); - - String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); - SuccessResultData result = operatorPluginRemoteService.saveOrder(systemApiPathProperties.getOperatorPlugin(), appVO, accessToken); - if (!result.getData().equals("Success")) { - System.out.println("调用套餐包创建结果 : " + result); - throw new SaveException(result.getData()); - } - } - - // } + String brcode = ALiPay.createPay(accountRechargeId, totalMoney, ProjectConfigUtil.getText("RechargePayTitle")); + payDTO.setAccountRechargeId(accountRechargeId); + payDTO.setThirdParty(thirdParty); + payDTO.setThirdPartyPayUrl(brcode); + } else if (ThirdPartyEnum.DGZZ.getValue().equals(thirdParty)) { + String accountRechargeId = getUUID("oto"); + params.put("rechargeType", RechargeTypeEnum.OFFLINE.getValue()); + params.put("accountRechargeId", accountRechargeId); + payDTO.setAccountRechargeId(accountRechargeId); + } else { + throw new ParamsException("充值类型错误"); + } + params.put("creator", userId); + params.put("gmtCreate", currentDate); + params.put("modifier", userId); + params.put("gmtModified", currentDate); + params.put("isDelete", 0); + accountRechargeDao.save(params); + savePackageInfo(payDTO.getAccountRechargeId(), accountRechargeVO); return payDTO; } + /** + * 获取预支付ID + * + * @param accountRechargeWxPrepayVO + * @return + */ + @Override + public String saveWxPayPrepayId(AccountRechargeWxPrepayVO accountRechargeWxPrepayVO) { + String userId = securityComponent.getCurrentUser().getUserId(); + + AccountRechargeVO accountRechargeVO = new AccountRechargeVO(); + accountRechargeVO.setUserId(userId); + accountRechargeVO.setThirdParty("微信"); + accountRechargeVO.setAccountId(userId); + accountRechargeVO.setRechargeCheck(RechargeCheckEnum.UN_RECHARGE.getValue()); + accountRechargeVO.setReconciliationStatus(ReconciliationStatusEnum.UN_RECONCILIATION.getValue()); + accountRechargeVO.setRechargeMoney(accountRechargeWxPrepayVO.getRechargeMoney()); + accountRechargeVO.setPackageInfoId(accountRechargeWxPrepayVO.getPackageInfoId()); + String accountRechargeId = getUUID("wx"); + Integer totalMoney = PayUtil.buiderMoney(accountRechargeVO.getRechargeMoney()); + String currentDate = DateUtil.getTime(); + + Map params = HashMapUtil.beanToMap(accountRechargeVO); + params.put("userId", userId); + params.put("rechargeType", RechargeTypeEnum.ONLINE.getValue()); + params.put("accountRechargeId", accountRechargeId); + params.put("rechargeFinalTime", currentDate); + params.put("creator", userId); + params.put("gmtCreate", currentDate); + params.put("modifier", userId); + params.put("gmtModified", currentDate); + params.put("isDelete", 0); + accountRechargeDao.save(params); + savePackageInfo(accountRechargeId, accountRechargeVO); + return WXPay.createPrepayId(accountRechargeId, totalMoney, ProjectConfigUtil.getText("RechargePayTitle")); + } + + /** + * 保存套餐包记录 + * + * @param accountRechargeId + * @param accountRechargeVO + */ + private void savePackageInfo(String accountRechargeId, AccountRechargeVO accountRechargeVO) { + // 创建套餐包购买记录 + if (!StringUtils.isEmpty(accountRechargeVO.getPackageInfoId())) { + PackageOrderAppVO appVO = new PackageOrderAppVO(); + appVO.setPackageInfoId(accountRechargeVO.getPackageInfoId()); + appVO.setUserId(accountRechargeVO.getUserId()); + appVO.setAccountRechargeId(accountRechargeId); + + String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); + SuccessResultData result = operatorPluginRemoteService.saveOrder(systemApiPathProperties.getOperatorPlugin(), appVO, accessToken); + if (!result.getData().equals("Success")) { + System.out.println("调用套餐包创建结果 : " + result); + throw new SaveException(result.getData()); + } + } + } + private Integer countByUserIdAndRechargeCheck(String userId, RechargeCheckEnum rechargeCheck) { Map params = getHashMap(4); params.put("userId", userId); @@ -561,7 +601,7 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA AccountRechargeDTO accountRechargeDTO = get(accountRechargeId); JSONArray phoneArray = new JSONArray(); String[] phones = ProjectConfigUtil.getText("HandleRechargePhones").split(","); - for(String phone : phones) { + for (String phone : phones) { com.alibaba.fastjson.JSONObject obj1 = new JSONObject(); obj1.put("phone", phone); phoneArray.add(obj1); @@ -569,7 +609,7 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA Map templateParams = new HashMap<>(); templateParams.put("count", 1 + ""); templateParams.put("money", accountRechargeDTO.getRechargeMoney() + ""); - TenlionSMS.sendMessage(UUIDUtil.getUUID(), "M00005", templateParams, phoneArray); + TenlionSMS.sendMessage(UUIDUtil.getUUID(), "M00005", templateParams, phoneArray); accountRechargeDao.update(params); } @@ -594,7 +634,7 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA rechargePayResultDTO.setOrderMessage("付款信息已提交, 请等待平台核对"); updateOrgData(accountRechargeId, accountRechargeVO); return rechargePayResultDTO; - } else if(dto.getThirdParty().equals(ThirdPartyEnum.XT.getValue())) { + } else if (dto.getThirdParty().equals(ThirdPartyEnum.XT.getValue())) { /** * 保存充值信息 * 2025年3月24日14:12:44 diff --git a/src/main/java/cn/com/tenlion/operator/util/pay/WXPay.java b/src/main/java/cn/com/tenlion/operator/util/pay/WXPay.java index d3a1965..a05bb1b 100644 --- a/src/main/java/cn/com/tenlion/operator/util/pay/WXPay.java +++ b/src/main/java/cn/com/tenlion/operator/util/pay/WXPay.java @@ -1,13 +1,11 @@ package cn.com.tenlion.operator.util.pay; -import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayResultDTO; -import com.alibaba.fastjson.JSONObject; +import com.wechat.pay.java.service.payments.jsapi.JsapiService; import com.wechat.pay.java.service.payments.model.Transaction; import com.wechat.pay.java.service.payments.model.TransactionAmount; import com.wechat.pay.java.service.payments.nativepay.NativePayService; import com.wechat.pay.java.service.payments.nativepay.model.*; import ink.wgink.exceptions.SaveException; -import ink.wgink.exceptions.SearchException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -122,6 +120,41 @@ public class WXPay { } } + /** + * 创建预支付订单 + * + * @param orderNo + * @param money + * @param orderDescription + * @return + */ + public static String createPrepayId(String orderNo, Integer money, String orderDescription) { + if (PayUtil.buiderMoney(money) > wxPayStaticProperties.getMaxMoney() || PayUtil.buiderMoney(money) < wxPayStaticProperties.getMinMoney()) { + throw new SaveException("支付金额超出范围"); + } + JsapiService service = wxPayStaticProperties.getJsapiService(); + com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest request = new com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest(); + com.wechat.pay.java.service.payments.jsapi.model.Amount amount = new com.wechat.pay.java.service.payments.jsapi.model.Amount(); + amount.setTotal(money); // 金额 + request.setAmount(amount); + request.setAppid(wxPayStaticProperties.getAppId()); + request.setMchid(wxPayStaticProperties.getMchId()); + request.setTimeExpire(getTimeExpire());// 超时时间 + request.setDescription(orderDescription);// 商品描述 + String notifyUrl = wxPayStaticProperties.getNotifyUrl().replaceAll("\\{orderNo}", orderNo); + request.setNotifyUrl(notifyUrl);// 支付成功的回调地址 + request.setOutTradeNo(orderNo); + // 调用下单方法,得到应答 + try { + // 发送请求 + com.wechat.pay.java.service.payments.jsapi.model.PrepayResponse response = service.prepay(request); + return response.getPrepayId(); + } catch (Exception e) { + e.printStackTrace(); + throw new SaveException("生成支付二维码失败"); + } + } + /** * 获取二维码超时时间 * diff --git a/src/main/java/cn/com/tenlion/operator/util/pay/WxPayProperties.java b/src/main/java/cn/com/tenlion/operator/util/pay/WxPayProperties.java index 1acd995..831eca1 100644 --- a/src/main/java/cn/com/tenlion/operator/util/pay/WxPayProperties.java +++ b/src/main/java/cn/com/tenlion/operator/util/pay/WxPayProperties.java @@ -2,6 +2,7 @@ package cn.com.tenlion.operator.util.pay; import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.service.payments.jsapi.JsapiService; import com.wechat.pay.java.service.payments.nativepay.NativePayService; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -12,28 +13,28 @@ import org.springframework.context.annotation.Configuration; public class WxPayProperties { // 商户号 - private String mchId; + private String mchId; // 商户API证书序列号 - private String mchNo; + private String mchNo; // 私钥本地存储路径 - private String privateKeyPath; + private String privateKeyPath; // API v3密钥 - private String apiV3Key; + private String apiV3Key; // 小程序APPID - private String appId; + private String appId; // 超时时间 - private String timeOut; + private String timeOut; // 微信服务器地址 - private String url; + private String url; // 接收结果通知地址 - private String notifyUrl; + private String notifyUrl; // 单笔最大金额 private Double maxMoney; @@ -43,7 +44,7 @@ public class WxPayProperties { @Bean // 使用自动更新平台证书的RSA配置 - public Config getConfig(){ + public Config getConfig() { Config config = new RSAAutoCertificateConfig.Builder() .merchantId(mchId) @@ -55,13 +56,20 @@ public class WxPayProperties { } @Bean - public NativePayService getPayUrlServices(){ + public NativePayService getPayUrlServices() { Config config = getConfig(); // 构建service NativePayService service = new NativePayService.Builder().config(config).build(); return service; } + @Bean + public JsapiService getJsapiService() { + Config config = getConfig(); + JsapiService service = new JsapiService.Builder().config(config).build(); + return service; + } + public String getMchId() { return mchId == null ? "" : mchId.trim(); }