feat:功能支付类模块完善
This commit is contained in:
+4
-22
@@ -3,10 +3,8 @@ package com.central.user.controller;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.user.service.PrivateKeyService;
|
||||
import com.central.user.service.WechatConfigService;
|
||||
import com.central.user.service.WechatPayService;
|
||||
import com.central.wechat.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
@@ -30,11 +28,6 @@ public class SysWechatConfigController {
|
||||
@Resource
|
||||
private WechatConfigService wechatConfigService;
|
||||
|
||||
@Resource
|
||||
private WechatPayService wechatPayService;
|
||||
|
||||
@Resource
|
||||
private PrivateKeyService privateKeyService;
|
||||
|
||||
@Operation(summary = "查询列表")
|
||||
@Parameters({
|
||||
@@ -84,21 +77,15 @@ public class SysWechatConfigController {
|
||||
public Result<Boolean> uploadPrivateKey(@RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
String privateKey = new String(file.getBytes());
|
||||
return Result.succeed(wechatPayService.uploadPrivateKey(
|
||||
TenantContextHolder.getTenant(), privateKey));
|
||||
WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",TenantContextHolder.getTenant());
|
||||
wechatConfig.setPrivateKey(privateKey);
|
||||
return Result.succeed(wechatConfigService.updateConfig(wechatConfig));
|
||||
} catch (Exception e) {
|
||||
log.error("上传私钥文件失败", e);
|
||||
return Result.failed("上传私钥文件失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "更新支付配置")
|
||||
@PostMapping("/pay-config")
|
||||
public Result<Boolean> updatePayConfig(@RequestBody Map<String, String> config) {
|
||||
return Result.succeed(wechatPayService.updatePayConfig(
|
||||
TenantContextHolder.getTenant(), config));
|
||||
}
|
||||
|
||||
@Operation(summary = "切换微信配置")
|
||||
@PostMapping("/switch/{type}")
|
||||
public Result<Boolean> switchConfig(@PathVariable String type) {
|
||||
@@ -111,9 +98,4 @@ public class SysWechatConfigController {
|
||||
return Result.succeed(wechatConfigService.getConfig(type, TenantContextHolder.getTenant()));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取租户密钥")
|
||||
@GetMapping("/tenant/private-key")
|
||||
public String getPrivateKey(@RequestParam("tenantId")String tenantId,@RequestParam String type) {
|
||||
return privateKeyService.getPrivateKey(tenantId, type);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package com.central.user.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.wechat.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 私钥文件管理服务
|
||||
*/
|
||||
public interface PrivateKeyService {
|
||||
|
||||
/**
|
||||
* 上传私钥文件
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param type 配置类型
|
||||
* @param inputStream 文件输入流
|
||||
* @return 文件访问路径
|
||||
*/
|
||||
String uploadPrivateKey(String tenantId, String type, InputStream inputStream);
|
||||
|
||||
/**
|
||||
* 获取私钥文件
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param type 配置类型
|
||||
* @return 私钥文件内容
|
||||
*/
|
||||
String getPrivateKey(String tenantId, String type);
|
||||
|
||||
/**
|
||||
* 删除私钥文件
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param type 配置类型
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deletePrivateKey(String tenantId, String type);
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@ package com.central.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.wechat.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import com.wechat.pay.java.service.refund.model.Refund;
|
||||
import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信支付服务
|
||||
*/
|
||||
public interface WechatPayService {
|
||||
|
||||
/**
|
||||
* 创建JSAPI支付订单
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param openId 用户openId
|
||||
* @param amount 支付金额(分)
|
||||
* @param description 商品描述
|
||||
* @param outTradeNo 商户订单号
|
||||
* @return 支付参数
|
||||
*/
|
||||
PrepayWithRequestPaymentResponse createJsapiOrder(String tenantId, String openId, int amount,
|
||||
String description, String outTradeNo);
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param outTradeNo 商户订单号
|
||||
* @return 订单信息
|
||||
*/
|
||||
Transaction queryOrder(String tenantId, String outTradeNo);
|
||||
|
||||
/**
|
||||
* 关闭订单
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param outTradeNo 商户订单号
|
||||
*/
|
||||
void closeOrder(String tenantId, String outTradeNo);
|
||||
|
||||
/**
|
||||
* 申请退款
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param outTradeNo 商户订单号
|
||||
* @param outRefundNo 商户退款单号
|
||||
* @param amount 退款金额(分)
|
||||
* @param reason 退款原因
|
||||
* @return 退款结果
|
||||
*/
|
||||
// RefundResponse refund(String tenantId, String outTradeNo, String outRefundNo,
|
||||
// int amount, String reason);
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param outRefundNo 商户退款单号
|
||||
* @return 退款信息
|
||||
*/
|
||||
Refund queryRefund(String tenantId, String outRefundNo);
|
||||
|
||||
/**
|
||||
* 解析退款通知
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param notifyData 通知数据
|
||||
* @return 退款通知信息
|
||||
*/
|
||||
RefundNotification parseRefundNotify(String tenantId, String notifyData);
|
||||
|
||||
/**
|
||||
* 上传私钥文件
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param privateKey 私钥内容
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean uploadPrivateKey(String tenantId, String privateKey);
|
||||
|
||||
/**
|
||||
* 更新支付配置
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @param config 配置信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updatePayConfig(String tenantId, Map<String, String> config);
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import com.central.user.service.PrivateKeyService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class PrivateKeyServiceImpl implements PrivateKeyService {
|
||||
|
||||
private static final String CACHE_KEY_PATTERN = "wechat:private_key:%s:%s";
|
||||
private static final long CACHE_EXPIRE_DAYS = 30;
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@Override
|
||||
public String uploadPrivateKey(String tenantId, String type, InputStream inputStream) {
|
||||
try {
|
||||
// 读取私钥内容
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder content = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
content.append(line).append("\n");
|
||||
}
|
||||
|
||||
// 缓存私钥内容
|
||||
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
||||
redisTemplate.opsForValue().set(cacheKey, content.toString(), CACHE_EXPIRE_DAYS, TimeUnit.DAYS);
|
||||
|
||||
return cacheKey;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("上传私钥文件失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrivateKey(String tenantId, String type) {
|
||||
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
||||
String privateKey = redisTemplate.opsForValue().get(cacheKey);
|
||||
|
||||
if (!StringUtils.hasText(privateKey)) {
|
||||
throw new RuntimeException("私钥文件不存在");
|
||||
}
|
||||
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePrivateKey(String tenantId, String type) {
|
||||
String cacheKey = String.format(CACHE_KEY_PATTERN, tenantId, type);
|
||||
return redisTemplate.delete(cacheKey);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.user.mapper.WechatConfigMapper;
|
||||
import com.central.user.service.WechatConfigService;
|
||||
import com.central.wechat.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
|
||||
-154
@@ -1,154 +0,0 @@
|
||||
package com.central.user.service.impl;//package com.zlt.wechat.service.impl;
|
||||
|
||||
import com.central.user.service.WechatPayService;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import com.wechat.pay.java.service.refund.model.Refund;
|
||||
import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class WechatPayServiceImpl implements WechatPayService {
|
||||
@Override
|
||||
public PrepayWithRequestPaymentResponse createJsapiOrder(String tenantId, String openId, int amount, String description, String outTradeNo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transaction queryOrder(String tenantId, String outTradeNo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeOrder(String tenantId, String outTradeNo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Refund queryRefund(String tenantId, String outRefundNo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefundNotification parseRefundNotify(String tenantId, String notifyData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean uploadPrivateKey(String tenantId, String privateKey) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePayConfig(String tenantId, Map<String, String> config) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*@Autowired
|
||||
private WechatConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private PrivateKeyService privateKeyService;
|
||||
|
||||
@Autowired
|
||||
private JsapiServiceExtension jsapiService;
|
||||
|
||||
@Autowired
|
||||
private RefundService refundService;
|
||||
|
||||
@Autowired
|
||||
private Config wxPayConfig;
|
||||
|
||||
@Override
|
||||
public PrepayWithRequestPaymentResponse createJsapiOrder(String tenantId, String openId,
|
||||
int amount, String description, String outTradeNo) {
|
||||
// 切换租户配置
|
||||
configService.switchConfig("PAY", tenantId);
|
||||
|
||||
// 创建支付订单
|
||||
*//*return jsapiService.prepayWithRequestPayment(
|
||||
openId,
|
||||
description,
|
||||
outTradeNo,
|
||||
amount,
|
||||
"CNY"
|
||||
);*//*
|
||||
return new PrepayWithRequestPaymentResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transaction queryOrder(String tenantId, String outTradeNo) {
|
||||
configService.switchConfig("PAY", tenantId);
|
||||
return jsapiService.queryOrderByOutTradeNo(outTradeNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeOrder(String tenantId, String outTradeNo) {
|
||||
configService.switchConfig("PAY", tenantId);
|
||||
jsapiService.closeOrder(outTradeNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefundResponse refund(String tenantId, String outTradeNo, String outRefundNo,
|
||||
int amount, String reason) {
|
||||
configService.switchConfig("PAY", tenantId);
|
||||
|
||||
RefundRequest request = new RefundRequest();
|
||||
request.setOutTradeNo(outTradeNo);
|
||||
request.setOutRefundNo(outRefundNo);
|
||||
request.setAmount(new RefundRequest.Amount(amount, "CNY"));
|
||||
request.setReason(reason);
|
||||
|
||||
return refundService.refund(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Refund queryRefund(String tenantId, String outRefundNo) {
|
||||
configService.switchConfig("PAY", tenantId);
|
||||
return refundService.queryByOutRefundNo(outRefundNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefundNotification parseRefundNotify(String tenantId, String notifyData) {
|
||||
configService.switchConfig("PAY", tenantId);
|
||||
return refundService.parseRefundNotification(notifyData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean uploadPrivateKey(String tenantId, String privateKey) {
|
||||
try {
|
||||
privateKeyService.uploadPrivateKey(tenantId, "PAY",
|
||||
new ByteArrayInputStream(privateKey.getBytes()));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePayConfig(String tenantId, Map<String, String> config) {
|
||||
try {
|
||||
WechatConfig wechatConfig = configService.getConfig("PAY", tenantId);
|
||||
if (wechatConfig == null) {
|
||||
wechatConfig = new WechatConfig();
|
||||
wechatConfig.setType("PAY");
|
||||
wechatConfig.setTenantId(tenantId);
|
||||
}
|
||||
|
||||
// 更新配置信息
|
||||
wechatConfig.setMerchantId(config.get("merchantId"));
|
||||
wechatConfig.setAppId(config.get("appId"));
|
||||
wechatConfig.setMchKey(config.get("mchKey"));
|
||||
wechatConfig.setMchSerialNo(config.get("mchSerialNo"));
|
||||
wechatConfig.setApiV3Key(config.get("apiV3Key"));
|
||||
wechatConfig.setNotifyUrl(config.get("notifyUrl"));
|
||||
wechatConfig.setStatus(1);
|
||||
|
||||
return configService.saveOrUpdate(wechatConfig);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
Reference in New Issue
Block a user