How We Built a C++ Cross‑Platform Architecture for WeChat Pay to Boost Productivity
This article explains how WeChat Pay tackled inconsistent iOS and Android implementations by creating a C++‑based cross‑platform framework, introducing UseCase and UIPage abstractions, a routing mechanism, unified network request handling, and standardized data flow, resulting in reduced code, faster feature delivery, and higher stability.
Background
WeChat Pay faces core issues due to separate iOS and Android implementations, leading to bugs, poor communication, low extensibility, long iteration cycles, incomplete data reporting, inadequate quality assurance, and inconsistent user experience.
To solve these problems, a C++ cross‑platform framework was built and the core payment flow was refactored, covering iOS from version 7.0.4 and Android from 7.0.7.
Online Metrics
Crash Rate
The crash rate remained stable after launch, with no mandatory crashes, providing a seamless user experience.
Example: sending a red packet uses the cross‑platform C++ code.
Efficiency Improvement
The cross‑platform implementation uses 3512 lines versus 6328 lines for native iOS, a 45% reduction.
Feature development examples show cross‑platform taking 3 person‑days versus 1 week for native.
What Is Software Architecture?
Software architecture defines system components and their relationships, often expressed as MVC, MVVM, etc. For WeChat Pay, architecture is seen as the composition of modules and communication methods.
Why Architecture Is Needed
Complex business requirements create inherent software complexity. Managing this complexity through separation of concerns, code reuse, and modular design improves productivity.
Building the Cross‑Platform Architecture
1. Abstract Business Flow
Introduce UseCase to encapsulate business processes and UIPage for UI screens, allowing reuse and clear separation.
2. Add Routing Mechanism
Implement a routing system that receives a data model, parses it, and triggers actions such as opening a UseCase, UIPage, WebView, or mini‑program.
Domain modeling uses UML and Proto protocols to define routing data.
3. Manage Network Requests
Replace the singleton network center with independent Cgi objects using the command pattern, binding each Cgi’s lifecycle to its UseCase.
4. Standardize Data Transfer
Eliminate shared mutable models, use immutable value types, enforce one‑way data flow, and apply the delegate pattern for necessary callbacks.
Summary
Good software architecture manages complexity arising from demanding business scenarios. By abstracting business flows, adding routing, unifying network handling, and standardizing data transfer, the WeChat Pay cross‑platform architecture reduces code size, accelerates feature delivery, improves stability, and provides a solid foundation for future enhancements.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
