|
1 | | -# WxJava - WeChat Java SDK Development Instructions |
| 1 | +# Copilot Instruction |
| 2 | +请始终使用中文生成 Pull Request 的标题、描述和提交信息 |
2 | 3 |
|
3 | | -WxJava is a comprehensive WeChat Java SDK supporting multiple WeChat platforms including Official Accounts (公众号), Mini Programs (小程序), WeChat Pay (微信支付), Enterprise WeChat (企业微信), Open Platform (开放平台), and Channel/Video (视频号). This is a Maven multi-module project with Spring Boot and Solon framework integrations. |
4 | 4 |
|
5 | | -**ALWAYS reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the information here.** |
| 5 | +# WxJava - 微信 Java SDK 开发说明 |
6 | 6 |
|
7 | | -## Working Effectively |
| 7 | +WxJava 是一个支持多种微信平台的完整 Java SDK,包含公众号、小程序、微信支付、企业微信、开放平台、视频号、企点等多种功能模块。 |
8 | 8 |
|
9 | | -### Prerequisites and Environment Setup |
10 | | -- **Java Requirements**: JDK 8+ required (project uses Java 8 as minimum target) |
11 | | -- **Maven**: Maven 3.6+ recommended (Maven 3.9.11 validated) |
12 | | -- **IDE**: IntelliJ IDEA recommended (project optimized for IDEA) |
| 9 | +**请始终优先参考本说明,只有在遇到与此内容不一致的意外信息时,才退而使用搜索或 bash 命令。** |
13 | 10 |
|
14 | | -### Bootstrap, Build, and Validate |
15 | | -Execute these commands in sequence after cloning: |
| 11 | +## 高效开发指南 |
| 12 | + |
| 13 | +### 前置条件与环境准备 |
| 14 | +- **Java 要求**:JDK 8+(项目最低目标为 Java 8) |
| 15 | +- **Maven**:推荐 Maven 3.6+(已验证 Maven 3.9.11) |
| 16 | +- **IDE**:推荐使用 IntelliJ IDEA(项目针对 IDEA 优化) |
| 17 | + |
| 18 | +### 引导、构建与校验 |
| 19 | +克隆仓库后按顺序执行以下命令: |
16 | 20 |
|
17 | 21 | ```bash |
18 | | -# 1. Basic compilation (NEVER CANCEL - takes 4-5 minutes) |
| 22 | +# 1. 基础编译(请勿中断 - 约需 4-5 分钟) |
19 | 23 | mvn clean compile -DskipTests=true --no-transfer-progress |
20 | | -# Timeout: Set 8+ minutes. Actual time: ~4 minutes |
| 24 | +# 超时时间:建议设置 8 分钟以上。实际时间:约 4 分钟 |
21 | 25 |
|
22 | | -# 2. Full package build (NEVER CANCEL - takes 2-3 minutes) |
| 26 | +# 2. 完整打包(请勿中断 - 约需 2-3 分钟) |
23 | 27 | mvn clean package -DskipTests=true --no-transfer-progress |
24 | | -# Timeout: Set 5+ minutes. Actual time: ~2 minutes |
| 28 | +# 超时时间:建议设置 5 分钟以上。实际时间:约 2 分钟 |
25 | 29 |
|
26 | | -# 3. Code quality validation (NEVER CANCEL - takes 45-60 seconds) |
| 30 | +# 3. 代码质量校验(请勿中断 - 约需 45-60 秒) |
27 | 31 | mvn checkstyle:check --no-transfer-progress |
28 | | -# Timeout: Set 3+ minutes. Actual time: ~50 seconds |
| 32 | +# 超时时间:建议设置 3 分钟以上。实际时间:约 50 秒 |
29 | 33 | ``` |
30 | 34 |
|
31 | | -**CRITICAL TIMING NOTES:** |
32 | | -- **NEVER CANCEL** any Maven build command |
33 | | -- Compilation phase takes longest (~4 minutes) due to 34 modules |
34 | | -- Full builds are faster on subsequent runs due to incremental compilation |
35 | | -- Always use `--no-transfer-progress` to reduce log noise |
36 | | - |
37 | | -### Testing Structure |
38 | | -- **Test Framework**: TestNG (not JUnit) |
39 | | -- **Test Files**: 298 test files across all modules |
40 | | -- **Default Behavior**: Tests are DISABLED by default in pom.xml (`<skip>true</skip>`) |
41 | | -- **Test Configuration**: Tests require external WeChat API credentials via test-config.xml files |
42 | | -- **DO NOT** attempt to run tests without proper WeChat API credentials as they will fail |
43 | | - |
44 | | -## Project Structure and Navigation |
45 | | - |
46 | | -### Core SDK Modules (Main Development Areas) |
47 | | -- `weixin-java-common/` - Common utilities and base classes (most important) |
48 | | -- `weixin-java-mp/` - WeChat Official Account SDK (公众号) |
49 | | -- `weixin-java-pay/` - WeChat Pay SDK (微信支付) |
50 | | -- `weixin-java-miniapp/` - Mini Program SDK (小程序) |
51 | | -- `weixin-java-cp/` - Enterprise WeChat SDK (企业微信) |
52 | | -- `weixin-java-open/` - Open Platform SDK (开放平台) |
53 | | -- `weixin-java-channel/` - Channel/Video SDK (视频号) |
54 | | -- `weixin-java-qidian/` - Qidian SDK (企点) |
55 | | - |
56 | | -### Framework Integration Modules |
57 | | -- `spring-boot-starters/` - Spring Boot auto-configuration starters |
58 | | -- `solon-plugins/` - Solon framework plugins |
59 | | -- `weixin-graal/` - GraalVM native image support |
60 | | - |
61 | | -### Configuration and Quality |
62 | | -- `quality-checks/google_checks.xml` - Checkstyle configuration |
63 | | -- `.editorconfig` - Code formatting rules (2 spaces = 1 tab) |
64 | | -- `pom.xml` - Root Maven configuration |
65 | | - |
66 | | -## Development Workflow |
67 | | - |
68 | | -### Making Code Changes |
69 | | -1. **Always build first** to establish clean baseline: |
| 35 | +重要时间说明: |
| 36 | +- 绝对不要中断任意 Maven 构建命令 |
| 37 | +- 编译阶段耗时最长(约 4 分钟),原因是项目包含 34 个模块 |
| 38 | +- 后续构建会更快,因为存在增量编译 |
| 39 | +- 始终使用 `--no-transfer-progress` 以减少日志噪音 |
| 40 | + |
| 41 | +### 测试结构 |
| 42 | +- **测试框架**:TestNG(非 JUnit) |
| 43 | +- **测试文件**:共有 298 个测试文件 |
| 44 | +- **默认行为**:pom.xml 中默认禁用测试(`<skip>true</skip>`) |
| 45 | +- **测试配置**:测试需要通过 test-config.xml 提供真实的微信 API 凭据 |
| 46 | +- **注意**:没有真实微信 API 凭据请不要尝试运行测试,测试将会失败 |
| 47 | + |
| 48 | +## 项目结构与导航 |
| 49 | + |
| 50 | +### 核心 SDK 模块(主要开发区) |
| 51 | +- `weixin-java-common/` - 通用工具与基础类(最重要) |
| 52 | +- `weixin-java-mp/` - 公众号 SDK |
| 53 | +- `weixin-java-pay/` - 微信支付 SDK |
| 54 | +- `weixin-java-miniapp/` - 小程序 SDK |
| 55 | +- `weixin-java-cp/` - 企业微信 SDK |
| 56 | +- `weixin-java-open/` - 开放平台 SDK |
| 57 | +- `weixin-java-channel/` - 视频号 / Channel SDK |
| 58 | +- `weixin-java-qidian/` - 企点 SDK |
| 59 | + |
| 60 | +### 框架集成模块 |
| 61 | +- `spring-boot-starters/` - Spring Boot 自动配置 starter |
| 62 | +- `solon-plugins/` - Solon 框架插件 |
| 63 | +- `weixin-graal/` - GraalVM 本地镜像支持 |
| 64 | + |
| 65 | +### 配置与质量控制 |
| 66 | +- `quality-checks/google_checks.xml` - Checkstyle 配置 |
| 67 | +- `.editorconfig` - 代码格式规则(2 个空格等于 1 个制表) |
| 68 | +- `pom.xml` - 根级 Maven 配置 |
| 69 | + |
| 70 | +## 开发工作流 |
| 71 | + |
| 72 | +### 修改代码的流程 |
| 73 | +1. 修改前务必先构建以建立干净基线: |
70 | 74 | ```bash |
71 | 75 | mvn clean compile --no-transfer-progress |
72 | 76 | ``` |
73 | 77 |
|
74 | | -2. **Follow code style** (enforced by checkstyle): |
75 | | - - Use 2 spaces for indentation (not tabs) |
76 | | - - Follow Google Java Style Guide |
77 | | - - Install EditorConfig plugin in your IDE |
| 78 | +2. 遵循代码风格(由 checkstyle 强制): |
| 79 | + - 缩进使用 2 个空格(不要用制表符) |
| 80 | + - 遵循 Google Java 风格指南 |
| 81 | + - 在 IDE 中安装 EditorConfig 插件 |
78 | 82 |
|
79 | | -3. **Validate changes incrementally**: |
| 83 | +3. 增量验证修改: |
80 | 84 | ```bash |
81 | | - # After each change: |
| 85 | + # 每次修改后运行: |
82 | 86 | mvn compile --no-transfer-progress |
83 | | - mvn checkstyle:check --no-transfer-progress |
| 87 | + mvn checkstyle:check --no-transfer-progress |
84 | 88 | ``` |
85 | 89 |
|
86 | | -### Before Submitting Changes |
87 | | -**ALWAYS run these validation steps in sequence:** |
| 90 | +### 提交修改前的必须校验 |
| 91 | +请务必按顺序完成以下校验步骤: |
88 | 92 |
|
89 | | -1. **Code Style Validation**: |
| 93 | +1. 代码风格校验: |
90 | 94 | ```bash |
91 | 95 | mvn checkstyle:check --no-transfer-progress |
92 | | - # Must pass - takes ~50 seconds |
| 96 | + # 必须通过 - 约需 50 秒 |
93 | 97 | ``` |
94 | 98 |
|
95 | | -2. **Full Clean Build**: |
| 99 | +2. 完整清理构建: |
96 | 100 | ```bash |
97 | 101 | mvn clean package -DskipTests=true --no-transfer-progress |
98 | | - # Must succeed - takes ~2 minutes |
| 102 | + # 必须成功 - 约需 2 分钟 |
99 | 103 | ``` |
100 | 104 |
|
101 | | -3. **Documentation**: Update javadoc for public methods and classes |
102 | | -4. **Contribution Guidelines**: Follow `CONTRIBUTING.md` - PRs must target `develop` branch |
| 105 | +3. 文档:为公共方法和类补充或更新 javadoc |
| 106 | +4. 贡献规范:遵循 `CONTRIBUTING.md`,Pull Request 必须以 `develop` 分支为目标 |
103 | 107 |
|
104 | | -## Module Dependencies and Build Order |
| 108 | +## 模块依赖与构建顺序 |
105 | 109 |
|
106 | | -### Core Module Dependencies (Build Order) |
107 | | -1. `weixin-graal` (GraalVM support) |
108 | | -2. `weixin-java-common` (foundation for all other modules) |
109 | | -3. Core SDK modules (mp, pay, miniapp, cp, open, channel, qidian) |
110 | | -4. Framework integrations (spring-boot-starters, solon-plugins) |
| 110 | +### 核心模块依赖(构建顺序) |
| 111 | +1. `weixin-graal`(GraalVM 支持) |
| 112 | +2. `weixin-java-common`(所有模块的基础) |
| 113 | +3. 核心 SDK 模块(mp、pay、miniapp、cp、open、channel、qidian) |
| 114 | +4. 框架集成(spring-boot-starters、solon-plugins) |
111 | 115 |
|
112 | | -### Key Relationship Patterns |
113 | | -- All SDK modules depend on `weixin-java-common` |
114 | | -- Spring Boot starters depend on corresponding SDK modules |
115 | | -- Solon plugins follow same pattern as Spring Boot starters |
116 | | -- Each module has both single and multi-account configurations |
| 116 | +### 主要关系模式 |
| 117 | +- 所有 SDK 模块都依赖于 `weixin-java-common` |
| 118 | +- Spring Boot starters 依赖对应的 SDK 模块 |
| 119 | +- Solon 插件遵循与 Spring Boot starters 相同的依赖模式 |
| 120 | +- 每个模块都有单账号与多账号配置支持 |
117 | 121 |
|
118 | | -## Common Tasks and Commands |
| 122 | +## 常见任务与命令 |
119 | 123 |
|
120 | | -### Validate Specific Module |
| 124 | +### 验证指定模块 |
121 | 125 | ```bash |
122 | | -# Build single module (replace 'weixin-java-mp' with target module): |
| 126 | +# 构建单个模块(将 'weixin-java-mp' 替换为目标模块): |
123 | 127 | cd weixin-java-mp |
124 | 128 | mvn clean compile --no-transfer-progress |
125 | 129 | ``` |
126 | 130 |
|
127 | | -### Check Dependencies |
| 131 | +### 检查依赖 |
128 | 132 | ```bash |
129 | | -# Analyze dependencies: |
| 133 | +# 分析依赖树: |
130 | 134 | mvn dependency:tree --no-transfer-progress |
131 | 135 |
|
132 | | -# Check for dependency updates: |
| 136 | +# 检查依赖更新: |
133 | 137 | ./others/check-dependency-updates.sh |
134 | 138 | ``` |
135 | 139 |
|
136 | | -### Release and Publishing |
| 140 | +### 发布与发布准备 |
137 | 141 | ```bash |
138 | | -# Version check: |
| 142 | +# 版本检查: |
139 | 143 | mvn versions:display-property-updates --no-transfer-progress |
140 | 144 |
|
141 | | -# Deploy (requires credentials): |
| 145 | +# 部署(需要凭据): |
142 | 146 | mvn clean deploy -P release --no-transfer-progress |
143 | 147 | ``` |
144 | 148 |
|
145 | | -## Important Files and Locations |
| 149 | +## 重要文件与位置 |
146 | 150 |
|
147 | | -### Configuration Files |
148 | | -- `pom.xml` - Root Maven configuration with dependency management |
149 | | -- `quality-checks/google_checks.xml` - Checkstyle rules |
150 | | -- `.editorconfig` - IDE formatting configuration |
151 | | -- `.github/workflows/maven-publish.yml` - CI/CD pipeline |
| 151 | +### 配置文件 |
| 152 | +- `pom.xml` - 根级 Maven 配置与依赖管理 |
| 153 | +- `quality-checks/google_checks.xml` - Checkstyle 规则 |
| 154 | +- `.editorconfig` - IDE 格式化配置 |
| 155 | +- `.github/workflows/maven-publish.yml` - CI/CD 工作流 |
152 | 156 |
|
153 | | -### Documentation |
154 | | -- `README.md` - Project overview and usage (Chinese) |
155 | | -- `CONTRIBUTING.md` - Development contribution guidelines |
156 | | -- `demo.md` - Links to demo projects and examples |
157 | | -- Each module has dedicated documentation and examples |
| 157 | +### 文档 |
| 158 | +- `README.md` - 项目概览与使用说明(中文) |
| 159 | +- `CONTRIBUTING.md` - 贡献指南 |
| 160 | +- `demo.md` - 示例项目与演示链接 |
| 161 | +- 每个模块均有单独的文档与示例 |
158 | 162 |
|
159 | | -### Test Resources |
160 | | -- `*/src/test/resources/test-config.sample.xml` - Template for test configuration |
161 | | -- Tests require real WeChat API credentials to run |
| 163 | +### 测试资源 |
| 164 | +- `*/src/test/resources/test-config.sample.xml` - 测试配置模板 |
| 165 | +- 测试运行需要真实的微信 API 凭据 |
162 | 166 |
|
163 | | -## SDK Usage Patterns |
| 167 | +## SDK 使用模式 |
164 | 168 |
|
165 | | -### Maven Dependency Usage |
| 169 | +### Maven 依赖示例 |
166 | 170 | ```xml |
167 | 171 | <dependency> |
168 | 172 | <groupId>com.github.binarywang</groupId> |
169 | | - <artifactId>weixin-java-mp</artifactId> <!-- or other modules --> |
| 173 | + <artifactId>weixin-java-mp</artifactId> <!-- 或其他模块 --> |
170 | 174 | <version>4.7.0</version> |
171 | 175 | </dependency> |
172 | 176 | ``` |
173 | 177 |
|
174 | | -### Common Development Areas |
175 | | -- **API Client Implementation**: Located in `*/service/impl/` directories |
176 | | -- **Model Classes**: Located in `*/bean/` directories |
177 | | -- **Configuration**: Located in `*/config/` directories |
178 | | -- **Utilities**: Located in `*/util/` directories in weixin-java-common |
| 178 | +### 常见开发区域 |
| 179 | +- **API 客户端实现**:位于 `*/service/impl/` 目录 |
| 180 | +- **模型类**:位于 `*/bean/` 目录 |
| 181 | +- **配置**:位于 `*/config/` 目录 |
| 182 | +- **工具类**:位于 `weixin-java-common` 的 `*/util/` 目录 |
179 | 183 |
|
180 | | -## Troubleshooting |
| 184 | +## 故障排查 |
181 | 185 |
|
182 | | -### Build Issues |
183 | | -- **OutOfMemoryError**: Increase Maven memory: `export MAVEN_OPTS="-Xmx2g"` |
184 | | -- **Compilation Failures**: Usually dependency issues - run `mvn clean` first |
185 | | -- **Checkstyle Failures**: Check `.editorconfig` settings in IDE |
| 186 | +### 构建问题 |
| 187 | +- **OutOfMemoryError**:增加 Maven 内存:`export MAVEN_OPTS="-Xmx2g"` |
| 188 | +- **编译失败**:通常为依赖问题 - 先执行 `mvn clean` |
| 189 | +- **Checkstyle 失败**:检查 IDE 的 `.editorconfig` 设置 |
186 | 190 |
|
187 | | -### Common Gotchas |
188 | | -- **Tests Always Skip**: This is normal - tests require WeChat API credentials |
189 | | -- **Multi-Module Changes**: Always build from root, not individual modules |
190 | | -- **Branch Target**: PRs must target `develop` branch, not `master`/`release` |
| 191 | +### 常见陷阱 |
| 192 | +- **测试默认跳过**:这是正常现象 — 测试需要微信 API 凭据 |
| 193 | +- **多模块变更**:总是在仓库根目录构建,而不是单独模块 |
| 194 | +- **分支目标**:Pull Request 必须以 `develop` 分支为目标,而不是 `master` 或 `release` |
191 | 195 |
|
192 | | -## Performance Notes |
193 | | -- **First Build**: Takes 4-5 minutes due to dependency downloads |
194 | | -- **Incremental Builds**: Much faster (~30-60 seconds) |
195 | | -- **Checkstyle**: Runs quickly (~50 seconds) and should be run frequently |
196 | | -- **IDE Performance**: Project uses Lombok - ensure annotation processing is enabled |
| 196 | +## 性能说明 |
| 197 | +- **首次构建**:由于依赖下载,耗时 4-5 分钟 |
| 198 | +- **增量构建**:通常更快(约 30-60 秒) |
| 199 | +- **Checkstyle**:运行迅速(约 50 秒),应当经常运行 |
| 200 | +- **IDE 性能**:项目使用 Lombok,请确保启用注解处理 |
197 | 201 |
|
198 | | -Remember: This is a SDK library project, not a runnable application. Changes should focus on API functionality, not application behavior. |
| 202 | +注意:本项目为 SDK 库项目,而非可运行应用。修改应以 API 功能为主,不要改动应用级行为。 |
0 commit comments