| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | |
| | | 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; |
| | |
| | | .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); |
| | |
| | | } |
| | | } |
| | | redisUtil.remove(outTradeNo); // 处理完逻辑删除 |
| | | log.info("司机充值-回调业务处理结束"); |
| | | log.info("司机充值-回调业务-处理结束"); |
| | | return notifyResult(); |
| | | } |
| | | |
| | |
| | | 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"); // 币种 |