feat: 微信支付获取预支付ID

This commit is contained in:
wanggeng 2025-04-07 21:39:22 +08:00
parent 8b3302f518
commit d5ee5cb3be
6 changed files with 231 additions and 98 deletions

View File

@ -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.AccountRechargePayDTO;
import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayResultDTO; 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.accountitem.AccountItemVO;
import cn.com.tenlion.operator.pojo.vos.accountrecharge.AccountRechargeWxPrepayVO;
import cn.com.tenlion.operator.util.pay.PayUtil; import cn.com.tenlion.operator.util.pay.PayUtil;
import ink.wgink.annotation.CheckRequestBodyAnnotation; import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController; import ink.wgink.common.base.DefaultBaseController;
@ -57,6 +58,15 @@ public class AccountRechargeController extends DefaultBaseController {
return url; 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 = "账户确认到账接口") // @ApiOperation(value = "账户确认到账", notes = "账户确认到账接口")
// @ApiImplicitParams({ // @ApiImplicitParams({
// @ApiImplicitParam(name = "ids", value = "ID列表用下划线分隔", paramType = "path", example = "1_2_3") // @ApiImplicitParam(name = "ids", value = "ID列表用下划线分隔", paramType = "path", example = "1_2_3")

View File

@ -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;
}
}

View File

@ -3,6 +3,7 @@ package cn.com.tenlion.operator.service.accountrecharge;
import cn.com.tenlion.operator.enums.RechargeCheckEnum; import cn.com.tenlion.operator.enums.RechargeCheckEnum;
import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayDTO; 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.accountrecharge.AccountRechargePayResultDTO;
import cn.com.tenlion.operator.pojo.vos.accountrecharge.AccountRechargeWxPrepayVO;
import ink.wgink.pojo.ListPage; import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResultList; import ink.wgink.pojo.result.SuccessResultList;
import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargeDTO; import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargeDTO;
@ -191,6 +192,8 @@ public interface IAccountRechargeService {
AccountRechargePayDTO saveAccount(String thirdParty, AccountRechargeVO accountRechargeVO); AccountRechargePayDTO saveAccount(String thirdParty, AccountRechargeVO accountRechargeVO);
String saveWxPayPrepayId(AccountRechargeWxPrepayVO accountRechargeWxPrepayVO);
void updateClose(String accountRechargeId); void updateClose(String accountRechargeId);
void updateCloseByIds(List<String> accountRechargeIds); void updateCloseByIds(List<String> accountRechargeIds);

View File

@ -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.accountbank.AccountBankDTO;
import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayDTO; 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.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.accountitem.AccountItemVO;
import cn.com.tenlion.operator.pojo.vos.accountrecharge.AccountRechargeWxPrepayVO;
import cn.com.tenlion.operator.properties.SystemApiPathProperties; import cn.com.tenlion.operator.properties.SystemApiPathProperties;
import cn.com.tenlion.operator.remote.IOperatorPluginRemoteService; 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.PackageOrderAppVO;
import cn.com.tenlion.operator.remote.PackageOrderDTO; import cn.com.tenlion.operator.remote.PackageOrderDTO;
import cn.com.tenlion.operator.service.account.IAccountService; import cn.com.tenlion.operator.service.account.IAccountService;
import cn.com.tenlion.operator.service.accountbank.IAccountBankService; import cn.com.tenlion.operator.service.accountbank.IAccountBankService;
import cn.com.tenlion.operator.service.accountitem.IAccountItemService; 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.service.sys.callback.SysCallbackService;
import cn.com.tenlion.operator.util.TenlionSMS; import cn.com.tenlion.operator.util.TenlionSMS;
import cn.com.tenlion.operator.util.UserUtil; 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 cn.com.tenlion.projectconfig.util.ProjectConfigUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import ink.wgink.common.base.DefaultBaseService; import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.exceptions.ParamsException; import ink.wgink.exceptions.ParamsException;
import ink.wgink.exceptions.SaveException; 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.module.oauth2.manager.OAuth2ClientTokenManager;
import ink.wgink.pojo.ListPage; import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.user.UserDTO; import ink.wgink.pojo.dtos.user.UserDTO;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData; import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList; import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.util.date.DateUtil; import ink.wgink.util.date.DateUtil;
@ -411,7 +407,7 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA
// synchronized (lock) { // synchronized (lock) {
String userId = accountRechargeVO.getUserId(); String userId = accountRechargeVO.getUserId();
// 未支付的订单 // 未支付的订单
Integer count = countByUserIdAndRechargeCheck(userId, RechargeCheckEnum.UN_RECHARGE); // Integer count = countByUserIdAndRechargeCheck(userId, RechargeCheckEnum.UN_RECHARGE);
/* if (count > ProjectConfigUtil.getInt("ToDayMaxRechargeCount")) { /* if (count > ProjectConfigUtil.getInt("ToDayMaxRechargeCount")) {
throw new SaveException("超过创建订单数量上限"); throw new SaveException("超过创建订单数量上限");
}*/ }*/
@ -457,13 +453,60 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA
params.put("gmtModified", currentDate); params.put("gmtModified", currentDate);
params.put("isDelete", 0); params.put("isDelete", 0);
accountRechargeDao.save(params); 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<String, Object> 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())) { if (!StringUtils.isEmpty(accountRechargeVO.getPackageInfoId())) {
PackageOrderAppVO appVO = new PackageOrderAppVO(); PackageOrderAppVO appVO = new PackageOrderAppVO();
appVO.setPackageInfoId(accountRechargeVO.getPackageInfoId()); appVO.setPackageInfoId(accountRechargeVO.getPackageInfoId());
appVO.setUserId(userId); appVO.setUserId(accountRechargeVO.getUserId());
appVO.setAccountRechargeId(payDTO.getAccountRechargeId()); appVO.setAccountRechargeId(accountRechargeId);
String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken();
SuccessResultData<String> result = operatorPluginRemoteService.saveOrder(systemApiPathProperties.getOperatorPlugin(), appVO, accessToken); SuccessResultData<String> result = operatorPluginRemoteService.saveOrder(systemApiPathProperties.getOperatorPlugin(), appVO, accessToken);
@ -472,9 +515,6 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA
throw new SaveException(result.getData()); throw new SaveException(result.getData());
} }
} }
// }
return payDTO;
} }
private Integer countByUserIdAndRechargeCheck(String userId, RechargeCheckEnum rechargeCheck) { private Integer countByUserIdAndRechargeCheck(String userId, RechargeCheckEnum rechargeCheck) {

View File

@ -1,13 +1,11 @@
package cn.com.tenlion.operator.util.pay; package cn.com.tenlion.operator.util.pay;
import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayResultDTO; import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.alibaba.fastjson.JSONObject;
import com.wechat.pay.java.service.payments.model.Transaction; 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.model.TransactionAmount;
import com.wechat.pay.java.service.payments.nativepay.NativePayService; import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import com.wechat.pay.java.service.payments.nativepay.model.*; import com.wechat.pay.java.service.payments.nativepay.model.*;
import ink.wgink.exceptions.SaveException; import ink.wgink.exceptions.SaveException;
import ink.wgink.exceptions.SearchException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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("生成支付二维码失败");
}
}
/** /**
* 获取二维码超时时间 * 获取二维码超时时间
* *

View File

@ -2,6 +2,7 @@ package cn.com.tenlion.operator.util.pay;
import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; 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 com.wechat.pay.java.service.payments.nativepay.NativePayService;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -62,6 +63,13 @@ public class WxPayProperties {
return service; return service;
} }
@Bean
public JsapiService getJsapiService() {
Config config = getConfig();
JsapiService service = new JsapiService.Builder().config(config).build();
return service;
}
public String getMchId() { public String getMchId() {
return mchId == null ? "" : mchId.trim(); return mchId == null ? "" : mchId.trim();
} }