How WeChat Pay Built a C++ Cross‑Platform Architecture to Boost Mobile Development Efficiency
This article explains the challenges of separate iOS and Android implementations in WeChat Pay, describes the design and benefits of a C++ cross‑platform framework, and shows how it improves code reuse, reduces bugs, accelerates feature delivery, and enhances overall software quality.
Background
WeChat Pay, as a critical business, faces many client‑side issues, the most fundamental being the split‑platform implementation:
Inconsistent iOS and Android implementations
Easily leads to bugs
Communication cannot guarantee quality
Poor scalability, slow response to business needs
Long iteration cycles
Incomplete data reporting
Incomplete quality‑assurance system
Lack of business and design knowledge accumulation
Loose protocol management
No unified automated testing
Inconsistent user experience (see the previous Android and iOS checkout screens)
To solve the core split‑platform problem and address technical debt, we built a C++ cross‑platform framework and refactored the core payment flow. The framework covers iOS from version 7.0.4 and Android from version 7.0.7.
Online Metrics
Example for iOS:
Crash rate remained stable before and after launch, with no impact on WeChat stability; users did not notice the switch.
Performance improvement The cross‑platform payment flow consists of 3,512 lines of code, compared with 6,328 lines for native iOS – a reduction of nearly 45%. For new feature development:
Cross‑platform implementation: 3 person‑days for iOS + Android, completed before the freeze.
Native implementation: about one week after the freeze for iOS and Android.
Thus, the cross‑platform architecture improves quality assurance and productivity.
For those interested in building a C++ cross‑platform framework from scratch, download the QCon 2019 keynote Keynote .
What Is Software Architecture?
Software architecture can be defined in many ways, from coding standards to release processes. For WeChat Pay, we define it as the system components and their communication relationships, essentially the MVC or MVVM patterns.
Why Do We Need Architecture?
Since 1986, the myth of the man‑month has highlighted that software complexity stems from complex business requirements. Architecture manages this complexity by separating responsibilities, enabling code reuse, and improving productivity.
Building a Payment Cross‑Platform Architecture from Scratch
In the mobile client domain, C++ is used for business logic, but there was no mature architecture for UI and navigation. Simply applying existing architectures would not suffice.
1. Abstract Business Processes
Common patterns like MVC, MVP, MVVM handle UI but ignore business flow and page transitions. We abstract the business flow into a UseCase and the UI into a UIPage, allowing a large process to be decomposed into smaller, reusable units.
Benefits:
Business logic aggregates in UseCase instead of being scattered across ViewControllers/Activities.
Business flow and UI become reusable.
Matches the complex, multi‑step nature of WeChat Pay.
2. Add a Routing Mechanism
Routing passes data to a central router, which parses it and triggers actions. The payment domain model becomes the routing payload.
Special flows (WebView, mini‑programs, pop‑ups) are handled uniformly by the router.
3. Manage Network Requests
Old architecture used a singleton network center, causing one‑to‑many communication issues and lifecycle problems. The new design treats each request as an independent Cgi object, created by a UseCase and bound to its lifecycle.
Advantages:
Eliminates one‑to‑many bugs.
Lifecycle tied to business logic, preventing stray callbacks.
High cohesion, low coupling, with unified caching and encryption.
4. Standardize Data Transfer
Old architecture used a shared model (blackboard pattern), leading to data pollution and untraceable flows. The new approach uses value‑type data, single‑direction injection, and the proxy pattern for notifications.
Results:
Eliminates data contamination.
Data flow becomes single‑direction and traceable.
Summary
The essence of software complexity lies in complex business requirements; architecture manages that complexity. A well‑designed architecture not only fixes legacy defects but also empowers business, delivering benefits such as automated data reporting, duplicate‑payment prevention, and security cross‑cutting. The WeChat Pay cross‑platform architecture will continue to evolve as new payment features emerge.
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.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
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.
