|
|
@@ -82,7 +82,6 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
public static RefundService refundService;
|
|
|
|
|
|
public static Config config;
|
|
|
-
|
|
|
private final WxPayConfig conf;
|
|
|
|
|
|
private final WxFapiaoConfig fapiaoConfig;
|
|
|
@@ -108,6 +107,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
private final UserRechargeRightsService userRechargeRightsService;
|
|
|
|
|
|
private final InvoiceDetailService invoiceDetailService;
|
|
|
+ private final RechargeConfigService rechargeConfigService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -119,7 +119,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
public WxPayServiceImpl(WxPayConfig conf, WxFapiaoConfig fapiaoConfig, WalletDetailService walletDetailService,
|
|
|
PayLogService payLogService, AccountService accountService, ChargeOrderService chargeOrderService,
|
|
|
RefundLogService refundLogService, InvoiceService invoiceService, InvoiceTitleService invoiceTitleService,
|
|
|
- EnPlusService enPlusService, ActivityService activityService, UserRechargeRightsService userRechargeRightsService, InvoiceDetailService invoiceDetailService) {
|
|
|
+ EnPlusService enPlusService, ActivityService activityService, UserRechargeRightsService userRechargeRightsService,
|
|
|
+ InvoiceDetailService invoiceDetailService, RechargeConfigService rechargeConfigService) {
|
|
|
this.conf = conf;
|
|
|
this.fapiaoConfig = fapiaoConfig;
|
|
|
this.walletDetailService = walletDetailService;
|
|
|
@@ -133,6 +134,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
this.activityService = activityService;
|
|
|
this.userRechargeRightsService = userRechargeRightsService;
|
|
|
this.invoiceDetailService = invoiceDetailService;
|
|
|
+ this.rechargeConfigService = rechargeConfigService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -198,7 +200,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
throw new BusinessException("接收到签名探测流量");
|
|
|
}
|
|
|
|
|
|
- LOGGER.info("微信支付回调{}:\n Request参数:\n signature:{},serial:{},nonce:{},timestamp:{},signatureType:{}", no, signature, serial, nonce, timestamp, signatureType);
|
|
|
+ LOGGER.info("微信支付回调{}: Request参数: signature:{},serial:{},nonce:{},timestamp:{},signatureType:{}", no, signature, serial, nonce, timestamp, signatureType);
|
|
|
|
|
|
ServletInputStream inputStream = request.getInputStream();
|
|
|
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
|
|
@@ -230,11 +232,16 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
* JSAPI支付下单
|
|
|
*/
|
|
|
@Override
|
|
|
- public PrepayWithRequestPaymentResponse wxPay(JSONObject params) {
|
|
|
- if (!params.containsKey("amount") || params.getInteger("amount") == null || !(params.get("amount") instanceof Integer)) {
|
|
|
+ @Transactional
|
|
|
+ public PrepayWithRequestPaymentResponse wxPay(Long rechargeConfigId) {
|
|
|
+ // 充值配置
|
|
|
+ var rechargeConfig = rechargeConfigService.getById(rechargeConfigId);
|
|
|
+
|
|
|
+ if ((rechargeConfig == null) || rechargeConfig.getRechargeAmount() <= 0) {
|
|
|
throw new BusinessException(ResponseEnum.WX_PAY_AMOUNT_ERROR);
|
|
|
}
|
|
|
- var rechargeAmount = params.getInteger("amount");
|
|
|
+
|
|
|
+ var rechargeAmount = rechargeConfig.getRechargeAmount();
|
|
|
var openid = StpUtil.getSession().getString("openid");
|
|
|
var userId = StpUtil.getLoginIdAsLong();
|
|
|
// 生成订单号
|
|
|
@@ -251,7 +258,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
// request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
PrepayRequest request = new PrepayRequest();
|
|
|
Amount amount = new Amount();
|
|
|
- amount.setTotal(rechargeAmount); // 传入金额单位为分
|
|
|
+ // 传入金额单位为分
|
|
|
+ amount.setTotal(rechargeAmount);
|
|
|
request.setAmount(amount);
|
|
|
request.setAppid(conf.getAppid());
|
|
|
request.setMchid(conf.getMchid());
|
|
|
@@ -302,12 +310,11 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public ResponseEntity<Object> wxNotify(HttpServletRequest request) {
|
|
|
-
|
|
|
try {
|
|
|
var notifyRes = handleWxNotify(request);
|
|
|
// 以支付通知回调为例,验签、解密并转换成 Transaction
|
|
|
Transaction transaction = ((NotificationParser) notifyRes[1]).parse((RequestParam) notifyRes[0], Transaction.class);
|
|
|
- LOGGER.info("微信支付回调{}:验签解密完毕,数据:\n{}", notifyRes[2], transaction);
|
|
|
+ LOGGER.info("微信支付回调{}:验签解密完毕,数据:{}", notifyRes[2], transaction);
|
|
|
// 判断是否已经接收处理过通知
|
|
|
if (payLogService.lambdaQuery().eq(PayLog::getOutTradeNo, transaction.getOutTradeNo()).one() != null) {
|
|
|
return ResponseEntity.status(HttpStatus.OK).build();
|
|
|
@@ -316,14 +323,13 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
DateTime dt = DateUtil.parse(transaction.getSuccessTime());
|
|
|
LocalDateTime successTime = LocalDateTimeUtil.of(dt);
|
|
|
|
|
|
-
|
|
|
// 钱包流水
|
|
|
var walletDetail = walletDetailService.getWalletDetailByOrderNo(transaction.getOutTradeNo(), WalletDetail.TYPE_充值);
|
|
|
if (walletDetail != null) {
|
|
|
|
|
|
// 更新余额
|
|
|
var account = accountService.getAccountByUserId(walletDetail.getUserId());
|
|
|
- accountService.lambdaUpdate().setSql("balance = (balance+%d)".formatted(transaction.getAmount().getTotal()))
|
|
|
+ accountService.lambdaUpdate().setSql("balance = (balance + %d)".formatted(transaction.getAmount().getTotal()))
|
|
|
.eq(Account::getUserId, walletDetail.getUserId()).update();
|
|
|
|
|
|
walletDetail.setStatus(WalletDetail.STATUS_已确认); //已确认
|
|
|
@@ -334,7 +340,6 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
walletDetail.setTransactionTime(successTime);
|
|
|
walletDetailService.updateById(walletDetail);
|
|
|
|
|
|
-
|
|
|
// 异步处理充值服务费打折权益活动相关逻辑
|
|
|
activityService.handleRechargeActivity(walletDetail.getUserId(), transaction.getAmount().getTotal());
|
|
|
|
|
|
@@ -360,7 +365,6 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
// 如果存在进行中的订单,则向en+更新用户余额
|
|
|
var chargingOrder = chargeOrderService.getChargingOrderByUserId(walletDetail.getUserId());
|
|
|
if (chargingOrder != null) {
|
|
|
- // TODO: 2023-11-30 快充这里考虑过充的金额要提高
|
|
|
var res = enPlusService.updateBalanceByQueryEquipChargeStatus(chargingOrder.getStartChargeSeq(), account.getBalance() - 50);
|
|
|
LOGGER.info("用户:{}充电过程中充值,已更新en+充电金额,en+返回数据:{}", account.getUserId(), res);
|
|
|
}
|