How isteinsgate/wechatpay-java works
Project Type and Purpose
• This is an open-source Java SDK (client library) for calling WeChat Pay APIv3.
• It is not a deployable service or microservice but a layered library offering:
• A core module for HTTP transport, signing, encryption, and notification handling.
• A service module that implements each business API (payments, refunds, profit-sharing, etc.) and provides example code.
• Optional shangmi (国密) extension and test harness modules.
A. Client Application (your code that calls the SDK)
B. Service Module
• Sub-components: payments, refund, certificate, billdownload, etc.
C. Core Module
• HTTP Client Layer (AbstractHttpClient, OkHttpClientAdapter, DefaultHttpClientBuilder)
• Crypto Layer (Signer/Verifier, PrivacyEncryptor/PrivacyDecryptor, AeadAesCipher)
• Certificate Management (AutoCertificateService, CertificateDownloader, in-memory providers)
• Notification Handling (NotificationParser, NotificationConfig variants)
• Utilities (JSON, I/O, nonces, PEM handling)
D. External Systems
• WeChat Pay API Endpoints (api.mch.weixin.qq.com & fallback api2.wechatpay.cn)
• WeChat Pay Platform Certificates
• Merchant Resources (merchant private key, APIv3 key)
1. Initialization
• Client → Core.Config (e.g. RSAAutoCertificateConfig.Builder)
• Core.Config → AutoCertificateService (downloads platform certs)
2. Business Request
• Client → Service.<X>Service → Core.HttpClient
• HttpClient → Crypto.Signer (sign request)
• HttpClient → HTTP → WeChat Pay Server
• Response → HttpClient → Crypto.Verifier (verify resp. signature) → Decrypt (if needed) → Service returns domain object to Client
3. Notification Handling
• WeChat Pay → HTTP callback endpoint → Client wraps raw body/headers into RequestParam → Core.NotificationParser (verifies + decrypts) → Domain event object returned to Client
4. Manual/Advanced HTTP
• Client → OkHttpClientAdapter (for unsupported APIs) → same sign/verify flows
5. Bill Download
• Two-step: Service requests download URL → HttpClient.download() → stream data → Client verifies digest
Architectural Patterns & Design Principles
• Layered Architecture: Clear separation between Core (infrastructure) and Service (business APIs).
• Builder Pattern: All configs and service instantiations use fluent builders.
• Adapter Pattern: OkHttpClientAdapter implements a generic HttpClient API.
• Strategy Pattern: Pluggable NotificationConfig, PrivacyEncryptor, PrivacyDecryptor.
• Facade: Service classes present a simple API masking core complexity.
• Background Processing: AutoCertificateService uses a scheduled thread.
Major Technologies & Frameworks
• Java 1.8+
• Gradle multi-project build
• OkHttp for HTTP
• SLF4J for logging
• Gson for JSON
• JUnit/TestNG for tests
• Tencent Kona SMSuite (国密) in shangmi module
Essential Checklist
[ ] Core and Service modules clearly separated
[ ] Crypto and HTTP sub-components inside Core labeled
[ ] Notification handling path included
[ ] Dual-domain retry strategy noted on HTTP client
[ ] Extension module shangmi shown as optional plugin
[ ] Config builders and background cert-refresh thread called out