Compare commits
No commits in common. "562d80c102da3bbe335136c904af9a445922a0b5" and "4fe0ba321ca1216555b11a56791ff616a0c2d3ea" have entirely different histories.
562d80c102
...
4fe0ba321c
|
|
@ -1,34 +0,0 @@
|
|||
package com.njzscloud.supervisory.biz.controller;
|
||||
|
||||
import com.njzscloud.common.core.utils.R;
|
||||
import com.njzscloud.supervisory.biz.pojo.param.QRCodeParam;
|
||||
import com.njzscloud.supervisory.biz.service.QRCodeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 获取二维码
|
||||
*
|
||||
* @author ljw
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/qr")
|
||||
@RequiredArgsConstructor
|
||||
public class QRCodeController {
|
||||
|
||||
private final QRCodeService qrCodeService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取二维码
|
||||
*/
|
||||
@GetMapping("/getCode")
|
||||
public R<?> getCode(QRCodeParam codeParam) {
|
||||
return R.success(qrCodeService.getCode(codeParam));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package com.njzscloud.supervisory.biz.pojo.param;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author ljw
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class QRCodeParam {
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 二维码宽度
|
||||
*/
|
||||
private Integer width;
|
||||
|
||||
/**
|
||||
* 二维码高度
|
||||
*/
|
||||
private Integer height;
|
||||
|
||||
/**
|
||||
* 二维码图片类型,jpg 或 png
|
||||
*/
|
||||
private String imgType;
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package com.njzscloud.supervisory.biz.service;
|
||||
|
||||
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import cn.hutool.extra.qrcode.QrConfig;
|
||||
import com.njzscloud.supervisory.biz.pojo.param.QRCodeParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 获取二维码
|
||||
* @author ljw
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class QRCodeService {
|
||||
|
||||
public String getCode(QRCodeParam codeParam) {
|
||||
Integer width = codeParam.getWidth();
|
||||
Integer height = codeParam.getHeight();
|
||||
if (width == null) {
|
||||
width = 300;
|
||||
}
|
||||
if (height == null) {
|
||||
height = 300;
|
||||
}
|
||||
String imgType = codeParam.getImgType();
|
||||
if (imgType == null) {
|
||||
imgType = ImgUtil.IMAGE_TYPE_JPG;
|
||||
}
|
||||
|
||||
return QrCodeUtil.generateAsBase64(codeParam.getContent(), new QrConfig(width, height), imgType);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -48,7 +48,6 @@ import java.time.LocalDateTime;
|
|||
/**
|
||||
* 支付相关接口
|
||||
* 使用微信支付官方SDK的生产级实现
|
||||
* @author ljw
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
|
@ -121,13 +120,11 @@ public class PaymentController {
|
|||
WxPayUnifiedOrderRequest wxRequest = new WxPayUnifiedOrderRequest();
|
||||
wxRequest.setOutTradeNo(outTradeNo);
|
||||
wxRequest.setBody("订单支付-" + ctx.getSn());
|
||||
// 转换为分
|
||||
wxRequest.setTotalFee(ctx.getSettleMoney().multiply(new BigDecimal("100")).intValue());
|
||||
wxRequest.setTotalFee(ctx.getSettleMoney().multiply(new BigDecimal("100")).intValue()); // 转换为分
|
||||
wxRequest.setOpenid(getCurrentUserOpenid(paymentParam.getWxCode()));
|
||||
wxRequest.setTradeType("JSAPI");
|
||||
wxRequest.setSpbillCreateIp(RequestHolder.getClientIP());
|
||||
// 需要配置实际的回调地址
|
||||
wxRequest.setNotifyUrl(properties.getNotifyUrl());
|
||||
wxRequest.setNotifyUrl(properties.getNotifyUrl()); // 需要配置实际的回调地址
|
||||
|
||||
// 调用微信支付服务
|
||||
WxPayMpOrderResult result = (WxPayMpOrderResult) wechatPayService.createJsapiOrder(wxRequest);
|
||||
|
|
@ -171,8 +168,7 @@ public class PaymentController {
|
|||
*/
|
||||
private String generateOutTradeNo(String sn) {
|
||||
String safeSn = sn == null ? "" : sn.replaceAll("[^0-9A-Za-z_-]", "");
|
||||
// 8位以内
|
||||
String suffix = String.valueOf(System.currentTimeMillis() % 100000000L);
|
||||
String suffix = String.valueOf(System.currentTimeMillis() % 100000000L); // 8位以内
|
||||
String base = "ORDER_" + safeSn + "_" + suffix;
|
||||
if (base.length() <= 32) {
|
||||
return base;
|
||||
|
|
@ -294,16 +290,9 @@ public class PaymentController {
|
|||
@PostMapping("/wechat/refundNotify")
|
||||
public String parseRefundNotifyResult(@RequestBody String xmlData) {
|
||||
try {
|
||||
log.info("收到微信退款回调:{}", xmlData);
|
||||
WxPayRefundNotifyResult result = wxPayService.parseRefundNotifyResult(xmlData);
|
||||
log.info("退款回调解析结果:{}", result);
|
||||
String orderSn = extractOrderIdFromOutTradeNo(result.getReqInfo().getOutTradeNo());
|
||||
log.info("从退款回调中提取订单号:{}", orderSn);
|
||||
OrderInfoEntity entity = orderInfoService.getOne(Wrappers.<OrderInfoEntity>lambdaQuery().eq(OrderInfoEntity::getSn, orderSn));
|
||||
if (entity == null) {
|
||||
log.warn("退款回调订单不存在:{}", orderSn);
|
||||
return WxPayNotifyResponse.fail("订单不存在");
|
||||
}
|
||||
// 更新订单状态为已退款
|
||||
orderInfoService.lambdaUpdate()
|
||||
.eq(OrderInfoEntity::getId, entity.getId())
|
||||
|
|
@ -311,10 +300,9 @@ public class PaymentController {
|
|||
.set(OrderInfoEntity::getRefundMoney, entity.getSettleMoney())
|
||||
.set(OrderInfoEntity::getRefundTime, LocalDateTime.now())
|
||||
.update();
|
||||
log.info("退款回调处理成功,订单号:{}", orderSn);
|
||||
return WxPayNotifyResponse.success("退款成功!");
|
||||
} catch (WxPayException e) {
|
||||
log.error("退款回调处理异常:{}", e.getMessage(), e);
|
||||
log.error(e.getMessage());
|
||||
return WxPayNotifyResponse.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@ import lombok.Setter;
|
|||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author ljw
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import com.njzscloud.supervisory.wxPay.dto.RefundRequestDto;
|
|||
|
||||
/**
|
||||
* 退款服务接口
|
||||
* @author ljw
|
||||
*/
|
||||
public interface PaymentService {
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import java.math.BigDecimal;
|
|||
|
||||
/**
|
||||
* 退款服务实现类
|
||||
* @author ljw
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
|
|
@ -36,11 +35,8 @@ public class PaymentServiceImpl implements PaymentService {
|
|||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
@Override
|
||||
public void refund(RefundRequestDto refundRequest, PaymentContextResult ctx, Boolean isChange) {
|
||||
try {
|
||||
log.info("开始处理退款申请,订单ID:{},支付方式:{},是否改价:{}",
|
||||
refundRequest.getOrderId(), ctx.getOiPayWay(), isChange);
|
||||
// 根据支付方式处理退款
|
||||
if (SettlementWay.CASH.getVal().equals(ctx.getOiPayWay())) {
|
||||
//微信退款 生成退款单号
|
||||
|
|
@ -52,10 +48,7 @@ public class PaymentServiceImpl implements PaymentService {
|
|||
money = refundRequest.getRefundAmount().multiply(new BigDecimal("100")).intValue();
|
||||
}
|
||||
String notifyUrl = properties.getRefundNotifyUrl();
|
||||
log.info("发起微信退款,订单ID:{},商户订单号:{},退款单号:{},退款金额:{}分,退款回调地址:{}",
|
||||
refundRequest.getOrderId(), refundRequest.getOutTradeNo(), orderSn, money, notifyUrl);
|
||||
String refundId = wechatPayService.refund(refundRequest.getOutTradeNo(), orderSn, money, money, notifyUrl);
|
||||
log.info("微信退款申请成功,退款ID:{}", refundId);
|
||||
wechatPayService.refund(refundRequest.getOutTradeNo(), orderSn, money, money, notifyUrl);
|
||||
} else if (SettlementWay.MONTH.getVal().equals(ctx.getOiPayWay()) || SettlementWay.BALANCE.getVal().equals(ctx.getOiPayWay())) {
|
||||
// 公司退款
|
||||
processCompanyRefund(refundRequest, ctx);
|
||||
|
|
|
|||
Loading…
Reference in New Issue