Kaynağa Gözat

物流多appId推送

yfh 1 ay önce
ebeveyn
işleme
a2f6dbd844

+ 18 - 8
fs-service-system/src/main/java/com/fs/system/mapper/WxMiniProgramConfigMapper.java

@@ -2,18 +2,19 @@ package com.fs.system.mapper;
 
 import java.util.List;
 import com.fs.system.domain.WxMiniProgramConfig;
+import org.apache.ibatis.annotations.Select;
 
 /**
  * 微信小程序支付配置Mapper接口
- * 
+ *
  * @author fs
  * @date 2025-12-01
  */
-public interface WxMiniProgramConfigMapper 
+public interface WxMiniProgramConfigMapper
 {
     /**
      * 查询微信小程序支付配置
-     * 
+     *
      * @param id 微信小程序支付配置ID
      * @return 微信小程序支付配置
      */
@@ -21,7 +22,7 @@ public interface WxMiniProgramConfigMapper
 
     /**
      * 查询微信小程序支付配置列表
-     * 
+     *
      * @param wxMiniProgramConfig 微信小程序支付配置
      * @return 微信小程序支付配置集合
      */
@@ -29,7 +30,7 @@ public interface WxMiniProgramConfigMapper
 
     /**
      * 新增微信小程序支付配置
-     * 
+     *
      * @param wxMiniProgramConfig 微信小程序支付配置
      * @return 结果
      */
@@ -37,7 +38,7 @@ public interface WxMiniProgramConfigMapper
 
     /**
      * 修改微信小程序支付配置
-     * 
+     *
      * @param wxMiniProgramConfig 微信小程序支付配置
      * @return 结果
      */
@@ -45,7 +46,7 @@ public interface WxMiniProgramConfigMapper
 
     /**
      * 删除微信小程序支付配置
-     * 
+     *
      * @param id 微信小程序支付配置ID
      * @return 结果
      */
@@ -53,9 +54,18 @@ public interface WxMiniProgramConfigMapper
 
     /**
      * 批量删除微信小程序支付配置
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */
     public int deleteWxMiniProgramConfigByIds(Long[] ids);
+
+    /**
+     * 查询所有再用支付配置
+     *
+     * @return
+     */
+    @Select("select * from wx_mini_program_config where status = 0")
+    List<WxMiniProgramConfig> selectAll();
+
 }

+ 2 - 1
fs-service-system/src/main/java/com/fs/wx/service/ShippingService.java

@@ -45,6 +45,7 @@ public class ShippingService {
      * @return 微信 API 的响应
      */
     public WeChatApiResponse uploadShippingInfo(UploadShippingInfoRequest request) {
+        WeChatAuthService weChatAuthService = WeChatAuthFactory.getWeChatAuthService(request.getAppid());
         String accessToken = weChatAuthService.getAccessToken(false);
         if (accessToken == null) {
             log.error("获取微信 Access Token 失败");
@@ -58,7 +59,7 @@ public class ShippingService {
                 .queryParam("access_token", accessToken)
                 .toUriString();
 
-        log.debug("请求微信上传发货接口 URL: {}", url);
+        log.debug("请求微信上传发货接口 Appid: {} URL: {}", request.getAppid(),url);
 
         ObjectMapper objectMapper = new ObjectMapper();
         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

+ 46 - 0
fs-service-system/src/main/java/com/fs/wx/service/WeChatAuthFactory.java

@@ -0,0 +1,46 @@
+package com.fs.wx.service;
+
+import com.fs.system.domain.WxMiniProgramConfig;
+import com.fs.system.mapper.WxMiniProgramConfigMapper;
+import com.fs.wx.service.impl.InMemoryWeChatAuthServiceImpl;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.SmartInitializingSingleton;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+import javax.validation.constraints.NotNull;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Component
+public class WeChatAuthFactory implements ApplicationContextAware, SmartInitializingSingleton {
+    private static ApplicationContext applicationContext;
+    private final static Map<String,WeChatAuthService> weChatAuthServices = new ConcurrentHashMap<>();
+
+    @Override
+    public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException {
+        WeChatAuthFactory.applicationContext = applicationContext;
+    }
+
+    @Override
+    public void afterSingletonsInstantiated() {
+        WxMiniProgramConfigMapper mapper = applicationContext.getBean(WxMiniProgramConfigMapper.class);
+        List<WxMiniProgramConfig> configs = mapper.selectAll();
+        for (WxMiniProgramConfig config : configs) {
+            WeChatAuthService weChatAuthService = new InMemoryWeChatAuthServiceImpl(config.getAppid(),config.getAppSecret());
+            weChatAuthServices.put(config.getAppid(),weChatAuthService);
+        }
+    }
+
+    /**
+     * 通过appid获取WeChatAuthService
+     * @param appid 小程序ID
+     * @return WeChatAuthService
+     */
+    public static WeChatAuthService getWeChatAuthService(String appid){
+        return weChatAuthServices.get(appid);
+    }
+
+}

+ 5 - 0
fs-service-system/src/main/java/com/fs/wx/service/impl/InMemoryWeChatAuthServiceImpl.java

@@ -30,6 +30,11 @@ public class InMemoryWeChatAuthServiceImpl implements WeChatAuthService {
     }
 
 
+    public InMemoryWeChatAuthServiceImpl(String appId, String appSecret) {
+        this.appId = appId;
+        this.appSecret = appSecret;
+    }
+
     @Override
     public synchronized void clearToken(){
         log.info("清除token缓存...");