diff --git a/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java b/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java index 5bce7ffa..da073f27 100644 --- a/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java +++ b/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java @@ -1,17 +1,13 @@ package com.czg.controller.user; import com.czg.market.dto.MkDistributionWithdrawFlowDTO; -import com.czg.market.entity.MkDistributionFlow; -import com.czg.market.entity.MkDistributionWithdrawFlow; -import com.czg.market.service.MkDistributionFlowService; import com.czg.market.service.MkDistributionUserService; import com.czg.market.service.MkDistributionWithdrawFlowService; import com.czg.market.vo.DistributionCenterShopVO; import com.czg.order.dto.MkDistributionPayDTO; import com.czg.resp.CzgResult; import com.czg.sa.StpKit; -import com.czg.service.Impl.AppWxServiceImpl; -import com.czg.utils.AssertUtil; +import com.czg.service.market.service.impl.AppWxServiceImpl; import com.mybatisflex.core.paginate.Page; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; diff --git a/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java b/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java index 26ebac5a..185b2460 100644 --- a/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java +++ b/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java @@ -7,17 +7,15 @@ import cn.hutool.core.util.RandomUtil; import com.alibaba.fastjson2.JSONObject; import com.czg.CzgPayUtils; import com.czg.entity.CzgBaseRespParams; -import com.czg.market.service.MkDistributionConfigService; import com.czg.market.service.MkDistributionUserService; import com.czg.mq.PrintMqListener; import com.czg.order.entity.OrderPayment; import com.czg.order.service.OrderInfoService; import com.czg.order.service.OrderPaymentService; import com.czg.order.service.ShopTableOrderStatisticService; -import com.czg.service.Impl.WxServiceImpl; +import com.czg.service.market.service.impl.WxServiceImpl; import com.czg.task.StatisticTask; import com.czg.utils.AssertUtil; -import com.ijpay.core.kit.AesUtil; import com.mybatisflex.core.query.QueryWrapper; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; diff --git a/cash-service/code-generator/src/main/java/com/czg/Main.java b/cash-service/code-generator/src/main/java/com/czg/Main.java index 0e4ce6c7..0d59af7e 100644 --- a/cash-service/code-generator/src/main/java/com/czg/Main.java +++ b/cash-service/code-generator/src/main/java/com/czg/Main.java @@ -34,7 +34,7 @@ public class Main { // String packageName = "product"; String packageName = "market"; // tableName 指定需要生成的表 - String tableName = "mk_distribution_flow"; + String tableName = "mk_distribution_withdraw_flow"; String author = "ww"; //是否生成DTO实体 默认生成 boolean isGenerateDto = true; diff --git a/cash-service/pay-service/src/main/java/com/czg/service/Impl/AppWxServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/AppWxServiceImpl.java similarity index 75% rename from cash-service/pay-service/src/main/java/com/czg/service/Impl/AppWxServiceImpl.java rename to cash-service/market-service/src/main/java/com/czg/service/market/service/impl/AppWxServiceImpl.java index 5d4a2c12..0cda3309 100644 --- a/cash-service/pay-service/src/main/java/com/czg/service/Impl/AppWxServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/AppWxServiceImpl.java @@ -1,38 +1,30 @@ -package com.czg.service.Impl; +package com.czg.service.market.service.impl; import com.czg.service.RedisService; import com.czg.system.service.SysParamsService; -import com.czg.service.WxService; import com.ijpay.core.kit.RsaKit; import jakarta.annotation.PostConstruct; -import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.config.annotation.DubboService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; /** * 微信支付service * @author Administrator */ -@DubboService +@Component @Slf4j -public class AppWxServiceImpl implements WxService { +@Primary +public class AppWxServiceImpl extends BaseWx { - @Resource - private RedisService autoRedisService; @DubboReference private SysParamsService paramsService; - private static RedisService redisService; - private WxService.Config config = new Config(); - @Override - public Config getConfig() { - return config; - } - - @Override - public RedisService getRedisService() { - return redisService; + public AppWxServiceImpl(@Autowired RedisService autoRedisService) { + this.redisService = autoRedisService; + config = new Config(); } @PostConstruct @@ -66,7 +58,10 @@ public class AppWxServiceImpl implements WxService { config.notifyUrl = paramsService.getSysParamValue("native_notify_url") + "/wx/pay"; config.refundNotifyUrl = ""; config.transferNotifyUrl = paramsService.getSysParamValue("native_notify_url") + "/wx/transfer"; - redisService = this.autoRedisService; + } + + public BaseWx getAppService() { + return this; } } diff --git a/cash-service/pay-service/src/main/java/com/czg/service/WxService.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/BaseWx.java similarity index 89% rename from cash-service/pay-service/src/main/java/com/czg/service/WxService.java rename to cash-service/market-service/src/main/java/com/czg/service/market/service/impl/BaseWx.java index 80cf15a9..08760aaf 100644 --- a/cash-service/pay-service/src/main/java/com/czg/service/WxService.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/BaseWx.java @@ -1,4 +1,4 @@ -package com.czg.service; +package com.czg.service.market.service.impl; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; @@ -6,6 +6,7 @@ import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson2.JSONObject; import com.czg.exception.CzgException; +import com.czg.service.RedisService; import com.ijpay.core.IJPayHttpResponse; import com.ijpay.core.enums.RequestMethodEnum; import com.ijpay.core.enums.SignType; @@ -36,10 +37,12 @@ import java.util.Map; * 微信支付相关 * @author Administrator */ -public interface WxService { - Logger log = LoggerFactory.getLogger(WxService.class); +public abstract class BaseWx { + public Config config; + public RedisService redisService; + public Logger log = LoggerFactory.getLogger(BaseWx.class); @Data - class Config { + public static class Config { public String appId; public String appSecret; public String certPath; @@ -56,11 +59,9 @@ public interface WxService { public String refundNotifyUrl; public String transferNotifyUrl; } - Config getConfig(); - RedisService getRedisService(); - default String getPhone(String code) { + String getPhone(String code) { String requestBody = JSONObject.toJSONString(Map.of("code", code)); String response = HttpUtil.post("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + getAccessToken(false), requestBody); log.info("获取手机号响应: {}", response); @@ -75,9 +76,8 @@ public interface WxService { throw new RuntimeException("获取手机号失败"); } - default String getAccessToken(boolean refresh) { - Object token = getRedisService().get("access_token"); - Config config = getConfig(); + String getAccessToken(boolean refresh) { + Object token = redisService.get("access_token"); if (!refresh && token instanceof String) { return (String) token; } @@ -96,15 +96,15 @@ public interface WxService { if (expiresIn == null) { expiresIn = 7200L; } - getRedisService().set("access_token", accessToken, expiresIn - 200); + redisService.set("access_token", accessToken, expiresIn - 200); return accessToken; } /** * 使用微信支付平台证书公钥加密敏感信息(OAEP) */ - default String encryptByPlatformCert(String content) { - Config config = getConfig(); + String encryptByPlatformCert(String content) { + try (var certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(config.getPlatformCertPath())) { if (certStream == null) { @@ -120,7 +120,7 @@ public interface WxService { } } - default String getSerialNumberFromPem(String certContent) { + String getSerialNumberFromPem(String certContent) { try { // 去掉 PEM 头尾并清理空格换行 String pem = certContent @@ -151,8 +151,8 @@ public interface WxService { return null; } - default String getSerialNumber() { - Config config = getConfig(); + public String getSerialNumber() { + try (var certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(config.getCertPath())) { X509Certificate certificate = PayKit.getCertificate(certStream); if (certificate != null) { @@ -168,8 +168,8 @@ public interface WxService { return null; } - default JSONObject verifySignature(HttpServletRequest request) { - Config config = getConfig(); + public JSONObject verifySignature(HttpServletRequest request) { + try { log.info("开始校验签名并解密"); @@ -186,8 +186,8 @@ public interface WxService { } } - default String decryptToString(String associatedData, String nonceStr, String ciphertext) { - AesUtil aesUtil = new AesUtil(getConfig().getApiV3Key().getBytes(StandardCharsets.UTF_8)); + public String decryptToString(String associatedData, String nonceStr, String ciphertext) { + AesUtil aesUtil = new AesUtil(config.getApiV3Key().getBytes(StandardCharsets.UTF_8)); try { return aesUtil.decryptToString( associatedData.getBytes(StandardCharsets.UTF_8), @@ -199,8 +199,8 @@ public interface WxService { } } - default String getOpenId(String code) { - Config config = getConfig(); + public String getOpenId(String code) { + String response = HttpUtil.get("https://api.weixin.qq.com/sns/jscode2session", Map.of("appid", config.getAppId() , "secret", config.getAppSecret(), "js_code", code, "grant_type", "authorization_code") ); @@ -213,8 +213,8 @@ public interface WxService { throw new RuntimeException("获取openId失败"); } - default Map v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type) { - Config config = getConfig(); + public Map v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type) { + if (desc == null) desc = "订单支付"; UnifiedOrderModel model = new UnifiedOrderModel(); model.setAppid(config.getAppId()); @@ -256,8 +256,8 @@ public interface WxService { } - default Map v2Pay(String openId, BigDecimal amount, String desc, String tradeNo) { - Config config = getConfig(); + Map v2Pay(String openId, BigDecimal amount, String desc, String tradeNo) { + Map payModel = com.ijpay.wxpay.model.UnifiedOrderModel.builder() .appid(config.appId) .mch_id(config.mchId) @@ -290,8 +290,8 @@ public interface WxService { } - default String refund(String tradeNo, String refundTradeNo, BigDecimal amount) { - Config config = getConfig(); + String refund(String tradeNo, String refundTradeNo, BigDecimal amount) { + int finalAmount = amount.multiply(new BigDecimal(100)).intValueExact(); RefundModel model = new RefundModel(); model.setOut_trade_no(tradeNo); @@ -325,7 +325,7 @@ public interface WxService { return jsonObject.getString("refund_id"); } - default String genCode(int shopId, int id, String path) { + String genCode(int shopId, int id, String path) { Map params = Map.of( "scene", "id=" + id + "&shopId=" + shopId, "page", path, @@ -346,8 +346,8 @@ public interface WxService { - default JSONObject transferBalance(String openId, String name, BigDecimal amount, String remarkTxt, String billNoTxt) { - Config config = getConfig(); + JSONObject transferBalance(String openId, String name, BigDecimal amount, String remarkTxt, String billNoTxt) { + String remark = remarkTxt == null ? "佣金" : remarkTxt; String billNo = billNoTxt == null ? IdUtil.simpleUUID() : billNoTxt; Map params = Map.of( diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java index fc98c108..3f4bfd95 100644 --- a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java @@ -3,10 +3,8 @@ package com.czg.service.market.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.IdUtil; -import com.alibaba.fastjson2.JSONObject; import com.czg.account.entity.ShopInfo; import com.czg.account.entity.ShopUser; -import com.czg.account.entity.UserInfo; import com.czg.account.service.ShopInfoService; import com.czg.account.service.ShopUserService; import com.czg.account.service.UserInfoService; @@ -31,7 +29,6 @@ import com.czg.order.dto.MkDistributionPayDTO; import com.czg.order.entity.OrderPayment; import com.czg.order.service.OrderPaymentService; import com.czg.sa.StpKit; -import com.czg.service.Impl.AppWxServiceImpl; import com.czg.service.market.mapper.MkDistributionUserMapper; import com.czg.utils.AssertUtil; import com.czg.utils.CzgRandomUtils; @@ -74,10 +71,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl