普兆健康管家后端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
6.5 KiB

  1. # 小程序模块配置说明
  2. ## 概述
  3. 本文档说明小程序登录服务需要配置的内容,包括数据库、Redis、微信配置等。
  4. ## 1. 数据库配置
  5. ### 1.1 数据库表结构
  6. 需要确保 `applet_user` 表已创建,表结构如下:
  7. ```sql
  8. CREATE TABLE `applet_user` (
  9. `id` varchar(32) NOT NULL COMMENT '主键',
  10. `create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  11. `create_time` datetime DEFAULT NULL COMMENT '创建日期',
  12. `update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
  13. `update_time` datetime DEFAULT NULL COMMENT '更新日期',
  14. `sys_org_code` varchar(64) DEFAULT NULL COMMENT '所属部门',
  15. `name` varchar(100) DEFAULT NULL COMMENT '昵称',
  16. `openid` varchar(100) DEFAULT NULL COMMENT '第三方认证id',
  17. `phone` varchar(20) DEFAULT NULL COMMENT '手机号',
  18. `bmi` decimal(10,2) DEFAULT NULL COMMENT '体总指数',
  19. `fat` decimal(10,2) DEFAULT NULL COMMENT '脂肪',
  20. `avatar` varchar(500) DEFAULT NULL COMMENT '头像',
  21. PRIMARY KEY (`id`),
  22. UNIQUE KEY `uk_openid` (`openid`),
  23. UNIQUE KEY `uk_phone` (`phone`)
  24. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='小程序用户表';
  25. ```
  26. ### 1.2 数据库连接配置
  27. `application.yml` 中配置数据库连接:
  28. ```yaml
  29. spring:
  30. datasource:
  31. url: jdbc:mysql://localhost:3306/jeecg-boot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
  32. username: root
  33. password: root
  34. driver-class-name: com.mysql.cj.jdbc.Driver
  35. ```
  36. ## 2. Redis配置
  37. ### 2.1 Redis连接配置
  38. `application.yml` 中配置Redis:
  39. ```yaml
  40. spring:
  41. redis:
  42. host: localhost
  43. port: 6379
  44. password:
  45. database: 0
  46. timeout: 10000ms
  47. lettuce:
  48. pool:
  49. max-active: 8
  50. max-wait: -1ms
  51. max-idle: 8
  52. min-idle: 0
  53. ```
  54. ### 2.2 Redis配置类
  55. 需要创建Redis配置类:
  56. ```java
  57. @Configuration
  58. public class RedisConfig {
  59. @Bean
  60. public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
  61. RedisTemplate<String, Object> template = new RedisTemplate<>();
  62. template.setConnectionFactory(factory);
  63. // 设置key的序列化方式
  64. template.setKeySerializer(new StringRedisSerializer());
  65. // 设置value的序列化方式
  66. template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
  67. // 设置hash key的序列化方式
  68. template.setHashKeySerializer(new StringRedisSerializer());
  69. // 设置hash value的序列化方式
  70. template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
  71. template.afterPropertiesSet();
  72. return template;
  73. }
  74. }
  75. ```
  76. ## 3. 微信小程序配置
  77. ### 3.1 微信配置
  78. `application.yml` 中配置微信小程序信息:
  79. ```yaml
  80. wechat:
  81. mpAppId: your_applet_appid
  82. mpAppSecret: your_applet_secret
  83. merchantId: your_merchant_id # 如果需要支付功能
  84. ```
  85. ### 3.2 微信配置类
  86. 确保 `WxHttpUtils` 类能正确读取配置:
  87. ```java
  88. @Component
  89. public class WxHttpUtils {
  90. @Value("${wechat.mpAppId}")
  91. private String appid;
  92. @Value("${wechat.mpAppSecret}")
  93. private String secret;
  94. }
  95. ```
  96. ## 4. JWT配置
  97. ### 4.1 JWT密钥配置
  98. `application.yml` 中配置JWT密钥:
  99. ```yaml
  100. jeecg:
  101. jwt:
  102. secret: your_jwt_secret_key
  103. expire: 604800 # 7天,单位秒
  104. ```
  105. ### 4.2 JWT工具类配置
  106. 确保 `JwtUtil` 类能正确读取配置:
  107. ```java
  108. @Component
  109. public class JwtUtil {
  110. @Value("${jeecg.jwt.secret}")
  111. private String secret;
  112. @Value("${jeecg.jwt.expire}")
  113. private long expire;
  114. }
  115. ```
  116. ## 5. 日志配置
  117. ### 5.1 日志级别配置
  118. `application.yml` 中配置日志级别:
  119. ```yaml
  120. logging:
  121. level:
  122. org.jeecg.modules.applet: DEBUG
  123. org.jeecg.modules.common.wxUtils: DEBUG
  124. ```
  125. ## 6. 安全配置
  126. ### 6.1 CORS配置
  127. 如果需要跨域访问,需要配置CORS:
  128. ```java
  129. @Configuration
  130. public class CorsConfig {
  131. @Bean
  132. public CorsFilter corsFilter() {
  133. CorsConfiguration config = new CorsConfiguration();
  134. config.addAllowedOrigin("*");
  135. config.addAllowedHeader("*");
  136. config.addAllowedMethod("*");
  137. UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
  138. source.registerCorsConfiguration("/**", config);
  139. return new CorsFilter(source);
  140. }
  141. }
  142. ```
  143. ## 7. 依赖配置
  144. ### 7.1 Maven依赖
  145. 确保 `pom.xml` 中包含以下依赖:
  146. ```xml
  147. <!-- Redis -->
  148. <dependency>
  149. <groupId>org.springframework.boot</groupId>
  150. <artifactId>spring-boot-starter-data-redis</artifactId>
  151. </dependency>
  152. <!-- HTTP客户端 -->
  153. <dependency>
  154. <groupId>org.apache.httpcomponents</groupId>
  155. <artifactId>httpclient</artifactId>
  156. </dependency>
  157. <!-- JSON处理 -->
  158. <dependency>
  159. <groupId>com.alibaba</groupId>
  160. <artifactId>fastjson</artifactId>
  161. </dependency>
  162. <!-- MyBatis Plus -->
  163. <dependency>
  164. <groupId>com.baomidou</groupId>
  165. <artifactId>mybatis-plus-boot-starter</artifactId>
  166. </dependency>
  167. ```
  168. ## 8. 环境变量配置
  169. ### 8.1 生产环境配置
  170. 在生产环境中,建议使用环境变量或配置中心来管理敏感信息:
  171. ```yaml
  172. wechat:
  173. mpAppId: ${WECHAT_MP_APPID:default_appid}
  174. mpAppSecret: ${WECHAT_MP_SECRET:default_secret}
  175. spring:
  176. redis:
  177. host: ${REDIS_HOST:localhost}
  178. port: ${REDIS_PORT:6379}
  179. password: ${REDIS_PASSWORD:}
  180. ```
  181. ## 9. 监控配置
  182. ### 9.1 健康检查
  183. 可以添加健康检查端点:
  184. ```yaml
  185. management:
  186. endpoints:
  187. web:
  188. exposure:
  189. include: health,info,metrics
  190. endpoint:
  191. health:
  192. show-details: always
  193. ```
  194. ## 10. 注意事项
  195. 1. **安全性**:生产环境中不要将敏感信息硬编码在代码中
  196. 2. **性能**:Redis连接池配置要根据实际负载调整
  197. 3. **监控**:建议添加应用监控和日志收集
  198. 4. **备份**:定期备份数据库和Redis数据
  199. 5. **测试**:在部署前进行充分的测试
  200. ## 11. 常见问题
  201. ### 11.1 Redis连接失败
  202. - 检查Redis服务是否启动
  203. - 检查网络连接和防火墙设置
  204. - 检查Redis配置是否正确
  205. ### 11.2 微信API调用失败
  206. - 检查微信小程序配置是否正确
  207. - 检查网络连接是否正常
  208. - 检查微信API调用频率限制
  209. ### 11.3 数据库连接失败
  210. - 检查数据库服务是否启动
  211. - 检查数据库连接配置
  212. - 检查数据库用户权限
  213. ## 12. 部署检查清单
  214. - [ ] 数据库表已创建
  215. - [ ] Redis服务已启动
  216. - [ ] 微信小程序配置正确
  217. - [ ] JWT密钥已配置
  218. - [ ] 日志配置正确
  219. - [ ] 网络连接正常
  220. - [ ] 安全配置已设置
  221. - [ ] 监控已配置
  222. - [ ] 备份策略已制定