yanderong
2026-06-09 b19474186df25762866bd9323c3f3ac8be4de9b9
DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/PayServiceImpl.java
@@ -1,5 +1,6 @@
package com.stylefeng.guns.modular.system.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.config.properties.WxPayProperties;
import com.stylefeng.guns.modular.system.model.Driver;
@@ -23,6 +24,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -58,18 +60,23 @@
    private final RedisUtil redisUtil;
    @Value("${callbackPath}")
    private String callbackPath;  //支付回调网关地址
    /**
     * 微信充值
     *
     * @param userId 充值用户
     * @param money 充值金额
     * @param money 充值金额,单位为元
     */
    @Transactional
    public WxPayAppVO wechatRecharge(Integer userId, BigDecimal money) throws Exception {
        PrepayRequest prepayRequest = buildPrepayRequest(money);
        log.info("司机充值-微信支付下单-请求数据为:{}", JSON.toJSONString(prepayRequest));
        // 1. 调用微信API下单
        PrepayResponse response = appService.prepay(prepayRequest);
        log.info("司机充值-微信支付下单-返回数据为:{}", JSON.toJSONString(response));
        String prepayId = response.getPrepayId();
        if(StringUtils.isEmpty(prepayId)) {
            return null;
@@ -103,7 +110,7 @@
                        .timestamp(request.getHeader("Wechatpay-Timestamp"))
                        .body(body)
                        .build();
        log.info("司机充值-回调业务处理开始-回调参数为:{}, body为:{}", requestParam, body);
        log.info("司机充值-收到回调请求-回调业务处理开始-回调参数为:{}, body为:{}", requestParam, body);
        NotificationConfig notificationConfig = (NotificationConfig) wxPayConfig;
        NotificationParser notificationParser = new NotificationParser(notificationConfig);
        Transaction transaction = notificationParser.parse(requestParam, Transaction.class);
@@ -133,7 +140,7 @@
            }
        }
        redisUtil.remove(outTradeNo); // 处理完逻辑删除
        log.info("司机充值-回调业务处理结束");
        log.info("司机充值-回调业务-处理结束");
        return notifyResult();
    }
@@ -197,7 +204,7 @@
        prepayRequest.setMchid(properties.getMchId());
        prepayRequest.setDescription("用户充值");          // 商品描述,不超过127个字符
        prepayRequest.setOutTradeNo(outTradeNo);          // 商户订单号
        prepayRequest.setNotifyUrl(properties.getNotifyUrl());            // 回调地址
        prepayRequest.setNotifyUrl(callbackPath+properties.getNotifyUrl());            // 回调地址
        Amount amount = new Amount();
        amount.setTotal(payAmount); // 金额:单位分(整数)
        amount.setCurrency("CNY"); // 币种