Bläddra i källkod

fix 修改 wx-java-cp

Young 2 år sedan
förälder
incheckning
46165dfd55

+ 1 - 0
support-demo/src/main/java/cn/nosum/wx/cp/config/WxCpAppConfig.java

@@ -9,6 +9,7 @@ import lombok.Data;
  */
 @Data
 public class WxCpAppConfig {
+
     /**
      * 设置企业微信应用的AgentId
      */

+ 15 - 5
support-demo/src/main/java/cn/nosum/wx/cp/config/WxCpConfiguration.java

@@ -30,13 +30,23 @@ public class WxCpConfiguration {
 
     @PostConstruct
     public void initServices() {
-        cpServices = this.properties.getAppConfigs().stream().map(a -> {
+        cpServices = this.properties.getAppConfigs().stream().map(agent -> {
             val configStorage = new WxCpDefaultConfigImpl();
             configStorage.setCorpId(this.properties.getCorpId());
-            configStorage.setAgentId(a.getAgentId());
-            configStorage.setCorpSecret(a.getSecret());
-            configStorage.setToken(a.getToken());
-            configStorage.setAesKey(a.getAesKey());
+            configStorage.setAgentId(agent.getAgentId());
+            configStorage.setCorpSecret(agent.getSecret());
+            configStorage.setToken(agent.getToken());
+            configStorage.setAesKey(agent.getAesKey());
+
+            // 设置代理对象
+            WxCpHttpProxyConfig proxy = properties.getProxy();
+            if (proxy.isEnabled()){
+                configStorage.setHttpProxyHost(proxy.getHost());
+                configStorage.setHttpProxyPort(proxy.getPort());
+                configStorage.setHttpProxyUsername(proxy.getUserName());
+                configStorage.setHttpProxyPassword(proxy.getPassword());
+            }
+
             val service = new WxCpServiceApacheHttpClientImpl();
             service.setWxCpConfigStorage(configStorage);
             return service;

+ 37 - 0
support-demo/src/main/java/cn/nosum/wx/cp/config/WxCpHttpProxyConfig.java

@@ -0,0 +1,37 @@
+package cn.nosum.wx.cp.config;
+
+import lombok.Data;
+
+/**
+ * 企微微信 HTTP 请求配置.
+ *
+ * @author Young
+ */
+@Data
+public class WxCpHttpProxyConfig {
+
+    /**
+     * 是否启用
+     */
+    private boolean enabled = Boolean.FALSE;
+
+    /**
+     * 主机
+     */
+    private String host = "127.0.0.1";
+
+    /**
+     * 端口号
+     */
+    private Integer port = 8080;
+
+    /**
+     * 用户名
+     */
+    private String userName = "username";
+
+    /**
+     * 密码
+     */
+    private String password = "password";
+}

+ 5 - 0
support-demo/src/main/java/cn/nosum/wx/cp/config/WxCpMultiAppConfig.java

@@ -22,6 +22,11 @@ public class WxCpMultiAppConfig {
     private String corpId;
 
     /**
+     * 企微微信 HTTP 接口请求代理配置
+     */
+    private WxCpHttpProxyConfig proxy;
+
+    /**
      * 应用配置列表
      */
     private List<WxCpAppConfig> appConfigs;

+ 6 - 1
support-demo/src/main/resources/application.yaml

@@ -1,7 +1,12 @@
 wx:
   cp:
     corp-id: wwced999fef1d39e62
-    default-secret: KI9-gT-jQTjbZZSD7wHxv5idYBshwtOVUOWsPss4wfU
+    proxy:
+      enabled: true
+      host: 192.168.0.1
+      port: 1234
+      user-name: test
+      password: test
     app-configs:
       - agentId: 1000039
         secret: KI9-gT-jQTjbZZSD7wHxv5idYBshwtOVUOWsPss4wfU