feat:功能支付类模块完善

This commit is contained in:
2025-06-03 15:56:31 +08:00
parent ee840a2df1
commit 1dec9d2035
31 changed files with 433 additions and 798 deletions
@@ -1,4 +1,4 @@
package com.central.wechat.wechat.config;
package com.central.wechat.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -1,4 +1,4 @@
package com.central.wechat.wechat.entity;
package com.central.wechat.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
@@ -54,6 +54,11 @@ public class WechatConfig {
*/
private String privateKeyPath;
/**
* 商户私钥
*/
private String privateKey;
/**
* APIv3密钥
*/
@@ -1,11 +1,12 @@
package com.central.wechat.wechat.feign;
package com.central.wechat.feign;
import com.central.common.constant.ServiceNameConstants;
import com.central.wechat.wechat.entity.WechatConfig;
import com.central.wechat.wechat.feign.fallback.WechatConfigServiceFallbackFactory;
import com.central.wechat.entity.WechatConfig;
import com.central.wechat.feign.fallback.WechatConfigServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author zlt
@@ -25,5 +26,14 @@ public interface WechatConfigService {
@GetMapping(value = "/wechat/config/app/{id}")
WechatConfig getConfigByAppId(@PathVariable("id") String appId);
/**
* feign rpc访问远程/wechat/config/{type}接口
* 查询微信配置对象WechatConfig
*
* @param type
* @return
*/
@GetMapping(value = "/wechat/config/{type}")
String getPrivateKey(@PathVariable("type") String type, @RequestParam("tenantId") String tenantId);
}
@@ -1,7 +1,7 @@
package com.central.wechat.wechat.feign.fallback;
package com.central.wechat.feign.fallback;
import com.central.wechat.wechat.entity.WechatConfig;
import com.central.wechat.wechat.feign.WechatConfigService;
import com.central.wechat.entity.WechatConfig;
import com.central.wechat.feign.WechatConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
@@ -27,6 +27,11 @@ public class WechatConfigServiceFallbackFactory implements FallbackFactory<Wecha
return null;
}
@Override
public String getPrivateKey(String type, String tenantId) {
return "";
}
};
}
@@ -1,39 +0,0 @@
package com.central.wechat.wechat.config;
import com.central.wechat.wechat.entity.WechatConfig;
import com.central.wechat.wechat.feign.PrivateKeyService;
import com.central.wechat.wechat.feign.WechatConfigService;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class WxPayConfigFactory {
private final WechatConfigService configService;
private final PrivateKeyService privateKeyService;
public WxPayConfigFactory(WechatConfigService configService, PrivateKeyService privateKeyService) {
this.configService = configService;
this.privateKeyService = privateKeyService;
}
public Config createConfig(String tenantId) {
log.info("创建微信支付配置,tenantId:{}", tenantId);
WechatConfig config = configService.getConfig("PAY", tenantId);
String privateKey = privateKeyService.getPrivateKey(tenantId, "PAY");
return new RSAAutoCertificateConfig.Builder()
.merchantId(config.getMerchantId())
.privateKey(privateKey)
.merchantSerialNumber(config.getMchSerialNo())
.apiV3Key(config.getApiV3Key())
.build();
}
public JsapiServiceExtension createJsapiService(String tenantId) {
Config config = createConfig(tenantId);
return new JsapiServiceExtension.Builder().config(config).build();
}
}
@@ -1,25 +0,0 @@
package com.central.wechat.wechat.feign;
import com.central.common.constant.ServiceNameConstants;
import com.central.wechat.wechat.feign.fallback.PrivateKeyServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author zlt
*/
@FeignClient(name = ServiceNameConstants.USER_SERVICE, fallbackFactory = PrivateKeyServiceFallbackFactory.class, dismiss404 = true)
public interface PrivateKeyService {
/**
* feign rpc访问远程/wechat/config/{type}接口
* 查询微信配置对象WechatConfig
*
* @param type
* @return
*/
@GetMapping(value = "/wechat/config/{type}")
String getPrivateKey(@PathVariable("type") String type, @RequestParam("tenantId") String tenantId);
}
@@ -1,25 +0,0 @@
package com.central.wechat.wechat.feign.fallback;
import com.central.wechat.wechat.feign.PrivateKeyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
/**
* userService降级工场
*
* @author zlt
* @date 2019/1/18
*/
@Slf4j
public class PrivateKeyServiceFallbackFactory implements FallbackFactory<PrivateKeyService> {
@Override
public PrivateKeyService create(Throwable throwable) {
return new PrivateKeyService() {
@Override
public String getPrivateKey(String tenantId,String type) {
return "";
}
};
}
}
@@ -1,4 +1,3 @@
com.central.wechat.wechat.feign.fallback.PrivateKeyServiceFallbackFactory
com.central.wechat.wechat.feign.fallback.WechatConfigServiceFallbackFactory
com.central.wechat.feign.fallback.WechatConfigServiceFallbackFactory