jingzhongge лет назад: 2
Родитель
Сommit
cb2821ffcf

+ 4 - 2
webapidemo-api/src/main/java/com/example/controller/wechat/WxSignatureCheckService.java

@@ -1,5 +1,6 @@
1 1
 package com.example.controller.wechat;
2 2
 
3
+import org.springframework.beans.factory.annotation.Value;
3 4
 import org.springframework.stereotype.Service;
4 5
 
5 6
 import java.util.ArrayList;
@@ -8,8 +9,9 @@ import java.util.Arrays;
8 9
 @Service
9 10
 public class WxSignatureCheckService {
10 11
 
11
-    //token
12
-    private final String token = "wxtoken";
12
+
13
+    @Value("${spring.wechat.Token}")
14
+    private String token;
13 15
 
14 16
     public String wxSignatureCheck(String signature, String timestamp, String nonce, String echostr) {
15 17
         ArrayList<String> array = new ArrayList<String>();

+ 25 - 0
webapidemo-api/src/main/resources/application-dev.yml

@@ -68,3 +68,28 @@ spring:
68 68
     password:
69 69
     # 连接超时时间
70 70
     timeout: 10s
71
+  rabbitmq:
72
+    host: 192.168.1.200
73
+    port: 5672
74
+    username: admin
75
+    password: 123456
76
+    virtual-host: /
77
+    #确认消息已发送到交换机(Exchange)
78
+    publisher-confirm-type: correlated
79
+    #确认消息已发送到队列(Queue)
80
+    publisher-returns: true
81
+    listener:
82
+      #      direct:
83
+      #        auto-startup: false
84
+      simple:
85
+        retry:
86
+          enabled: true           # 开启消费者出现异常情况下,进行重试消费,默认false
87
+          max-attempts: 3         # 最大重试次数,默认为3
88
+          initial-interval: 3000  # 重试间隔时间,默认1000(单位毫秒)
89
+    #        auto-startup: false
90
+
91
+  wechat:
92
+    AppId: wx4ff77198ae11494b
93
+    AppSecret: 2142698972a706a651f371e412d48a78
94
+    Token: wxtoken
95
+    EncodingAESKey:

+ 69 - 8
webapidemo-api/src/main/resources/application-production.yml

@@ -2,16 +2,43 @@ server:
2 2
   port: 8000
3 3
 swagger: false
4 4
 spring:
5
-  datasource:
6
-    type: com.alibaba.druid.pool.DruidDataSource
7
-    druid:
8
-      url: jdbc:mysql://192.168.1.200:3306/jiayi?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
9
-      username: root
10
-      password: 800100
11
-      driver-class-name: com.mysql.cj.jdbc.Driver
5
+  shardingsphere:
6
+    datasource:
7
+      names: master,slave0,slave1
8
+      master:
9
+        type: com.alibaba.druid.pool.DruidDataSource
10
+        driver-class-name: com.mysql.cj.jdbc.Driver
11
+        url: jdbc:mysql://10.160.153.119:3306/jiayi?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
12
+        username: root
13
+        password: 123456
14
+      slave0:
15
+        type: com.alibaba.druid.pool.DruidDataSource
16
+        driver-class-name: com.mysql.cj.jdbc.Driver
17
+        url: jdbc:mysql://10.160.153.119:3306/jiayi?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
18
+        username: root
19
+        password: 123456
20
+      slave1:
21
+        type: com.alibaba.druid.pool.DruidDataSource
22
+        driver-class-name: com.mysql.cj.jdbc.Driver
23
+        url: jdbc:mysql://10.160.153.119:3306/jiayi?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
24
+        username: root
25
+        password: 123456
26
+    rules:
27
+      readwrite-splitting:
28
+        data-sources:
29
+          mds:
30
+            type: static
31
+            props:
32
+              write-data-source-name: master
33
+              read-data-source-names: slave0,slave1
34
+            load-balancer-name: read-random
35
+        load-balancers:
36
+          read-random:
37
+            type: round_robin
38
+    enabled: true
12 39
   redis:
13 40
     # 地址
14
-    host: 192.168.1.200
41
+    host: 10.160.153.119
15 42
     # 端口,默认为6379
16 43
     port: 6379
17 44
     # 数据库索引
@@ -20,3 +47,37 @@ spring:
20 47
     password:
21 48
     # 连接超时时间
22 49
     timeout: 10s
50
+  data:
51
+    mongodb:
52
+      authentication-database: admin
53
+      host: 10.160.153.119
54
+      port: 27017
55
+      database: wechat
56
+      username: root
57
+      password: '123456'
58
+
59
+  rabbitmq:
60
+    host: 10.160.153.119
61
+    port: 5672
62
+    username: admin
63
+    password: 123456
64
+    virtual-host: /
65
+    #确认消息已发送到交换机(Exchange)
66
+    publisher-confirm-type: correlated
67
+    #确认消息已发送到队列(Queue)
68
+    publisher-returns: true
69
+    listener:
70
+      #      direct:
71
+      #        auto-startup: false
72
+      simple:
73
+        retry:
74
+          enabled: true           # 开启消费者出现异常情况下,进行重试消费,默认false
75
+          max-attempts: 3         # 最大重试次数,默认为3
76
+          initial-interval: 3000  # 重试间隔时间,默认1000(单位毫秒)
77
+  #        auto-startup: false
78
+
79
+  wechat:
80
+    AppId: wx4ff77198ae11494b
81
+    AppSecret: 2142698972a706a651f371e412d48a78
82
+    Token: wxtoken
83
+    EncodingAESKey:

+ 2 - 21
webapidemo-api/src/main/resources/application.yml

@@ -3,8 +3,8 @@ spring:
3 3
     date-format: yyyy-MM-dd HH:mm:ss
4 4
     time-zone: GMT+8
5 5
   profiles:
6
-    #active: production
7
-    active: dev
6
+    active: production
7
+    #active: dev
8 8
 
9 9
   resources:
10 10
     static-locations: file:/home/website/webapidemo/Api/file/image/  #资源路径
@@ -15,25 +15,6 @@ spring:
15 15
     multipart:
16 16
       max-file-size: 20MB #单个文件最大为20M
17 17
       max-request-size: 20MB #单次请求文件总数大小为20M
18
-  rabbitmq:
19
-    host: 192.168.1.200
20
-    port: 5672
21
-    username: admin
22
-    password: 123456
23
-    virtual-host: /
24
-      #确认消息已发送到交换机(Exchange)
25
-    publisher-confirm-type: correlated
26
-      #确认消息已发送到队列(Queue)
27
-    publisher-returns: true
28
-    listener:
29
-#      direct:
30
-#        auto-startup: false
31
-      simple:
32
-        retry:
33
-          enabled: true           # 开启消费者出现异常情况下,进行重试消费,默认false
34
-          max-attempts: 3         # 最大重试次数,默认为3
35
-          initial-interval: 3000  # 重试间隔时间,默认1000(单位毫秒)
36
-#        auto-startup: false
37 18
 mybatis-plus:
38 19
   global-config:
39 20
     db-config:

+ 3 - 3
webapidemo-service/src/main/java/com/example/service/rabbitmqListener/Consumer.java

@@ -253,10 +253,10 @@ public class Consumer {
253 253
             String path = null;
254 254
             if ("image".equals(msgType)) {
255 255
                 file = new File(pathName, l + ".jpg");
256
-                path = "http://192.168.1.15:8000/image/" + format + "/" + l + ".jpg";
256
+                path = "/image/" + format + "/" + l + ".jpg";
257 257
             } else if ("video".equals(msgType)) {
258 258
                 file = new File(pathName, l + ".mp4");
259
-                path = "http://192.168.1.15:8000/image/" + format + "/" + l + ".mp4";
259
+                path = "/image/" + format + "/" + l + ".mp4";
260 260
                 mongoDBMessage.setThumbMediaId(queueMessage.getThumbMediaId());
261 261
             } else if ("voice".equals(msgType) || "audio".equals("msgType")) {
262 262
                 file = new File(pathName, l + ".amr");
@@ -288,7 +288,7 @@ public class Consumer {
288 288
                     String newPath = "file/image/" + format;
289 289
                     File voiceFile = new File(newPath, l + ".mp3");
290 290
                     DloadImgUtil.formatConversion(file, voiceFile);
291
-                    String voice = "http://192.168.1.15:8000/image/" + format + "/" + l + ".mp3";
291
+                    String voice = "/image/" + format + "/" + l + ".mp3";
292 292
 
293 293
                     mongoDBMessage.setPicUrl(voice);
294 294
                     FileUtil.deleteTempFile(file);

+ 15 - 4
webapidemo-util/src/main/java/com/example/util/config/RabbitConfig.java

@@ -6,6 +6,7 @@ import org.springframework.amqp.core.AmqpAdmin;
6 6
 import org.springframework.amqp.rabbit.core.RabbitAdmin;
7 7
 import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
8 8
 import org.springframework.amqp.support.converter.MessageConverter;
9
+import org.springframework.beans.factory.annotation.Value;
9 10
 import org.springframework.context.annotation.Bean;
10 11
 import org.springframework.context.annotation.Configuration;
11 12
 
@@ -14,14 +15,24 @@ import org.springframework.context.annotation.Configuration;
14 15
  */
15 16
 @Configuration
16 17
 public class RabbitConfig {
18
+
19
+    @Value("${spring.rabbitmq.host}")
20
+    private static String host;
21
+    @Value("${spring.rabbitmq.port}")
22
+    private static int port;
23
+    @Value("${spring.rabbitmq.username}")
24
+    private static String username;
25
+    @Value("${spring.rabbitmq.password}")
26
+    private static String password;
27
+
17 28
     public static Connection getConnection() {
18 29
         Connection connection = null;
19 30
         try {
20 31
             ConnectionFactory factory = new ConnectionFactory();
21
-            factory.setHost("192.168.1.200");
22
-            factory.setPort(5672);
23
-            factory.setUsername("admin");
24
-            factory.setPassword("123456");
32
+            factory.setHost(host);
33
+            factory.setPort(port);
34
+            factory.setUsername(username);
35
+            factory.setPassword(password);
25 36
             connection = factory.newConnection();
26 37
         } catch (Exception e) {
27 38
             e.printStackTrace();

+ 16 - 8
webapidemo-util/src/main/java/com/example/util/config/WxMpConfig.java

@@ -3,6 +3,7 @@ package com.example.util.config;
3 3
 import me.chanjar.weixin.mp.api.WxMpService;
4 4
 import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
5 5
 import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
6
+import org.springframework.beans.factory.annotation.Value;
6 7
 import org.springframework.context.annotation.Bean;
7 8
 import org.springframework.context.annotation.Configuration;
8 9
 
@@ -13,17 +14,26 @@ import org.springframework.context.annotation.Configuration;
13 14
 @Configuration
14 15
 public class WxMpConfig {
15 16
 
17
+	@Value("${spring.wechat.AppId}")
18
+	private String AppId;
19
+	@Value("${spring.wechat.AppSecret}")
20
+	private String AppSecret;
21
+	@Value("${spring.wechat.Token}")
22
+	private String Token;
23
+	@Value("${spring.wechat.EncodingAESKey}")
24
+	private String EncodingAESKey;
25
+
16 26
 	@Bean
17
-		public WxMpDefaultConfigImpl wxMpDefaultConfigImpl() {
27
+	public WxMpDefaultConfigImpl wxMpDefaultConfigImpl() {
18 28
 		WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
19 29
 		// 设置微信公众号的appid
20
-		config.setAppId("wx4ff77198ae11494b");
30
+		config.setAppId(AppId);
21 31
 		// 设置微信公众号的app corpSecret
22
-		config.setSecret("2142698972a706a651f371e412d48a78");
32
+		config.setSecret(AppSecret);
23 33
 		// 设置微信公众号的token
24
-		config.setToken("wxtoken");
34
+		config.setToken(Token);
25 35
 		// 设置微信公众号的EncodingAESKey
26
-		config.setAesKey("");
36
+		config.setAesKey(EncodingAESKey);
27 37
 		return config;
28 38
 	}
29 39
 
@@ -35,6 +45,4 @@ public class WxMpConfig {
35 45
 		return wxMpService;
36 46
 	}
37 47
 
38
-
39
-
40
-}
48
+}