How WeChat Pay’s C++ Cross‑Platform Framework Solved Mobile Payment Challenges
WeChat Pay’s new C++ cross‑platform framework unifies iOS and Android payment flows, reducing code by 45%, cutting development time, improving crash stability, and introducing a routing mechanism, use‑case abstraction, and disciplined data handling to boost productivity and quality across mobile payment services.
Background
WeChat Pay faced major issues due to separate iOS and Android implementations, including inconsistent bugs, poor scalability, incomplete data reporting, weak quality assurance, and inconsistent user experience.
iOS and Android implementations differed, leading to bugs and communication gaps.
Poor scalability made rapid business response difficult.
Quality assurance lacked unified testing and design knowledge.
User experience varied between platforms.
To address these core problems and technical debt, a C++ based cross‑platform framework was built, covering iOS from version 7.0.4 and Android from 7.0.7.
Online Metrics
Crash rate : Remained stable before and after launch, with no visible crashes for users.
Efficiency gain : The core payment flow required 3,512 lines of cross‑platform code versus 6,328 lines of native iOS code – a reduction of nearly 45%.
Feature development time dropped dramatically: the same cash‑register redesign that took a week on native iOS/Android was completed in 3‑5 person‑days with the cross‑platform solution.
What Is Software Architecture?
Architecture is defined here as the system’s components and their communication relationships, essentially the MVC/MVVM patterns that programmers work with daily.
Why Architecture Matters
Complex business requirements create inherent software complexity; managing this complexity through responsibility separation and modular design improves productivity.
Building the Cross‑Platform Architecture from Scratch
1. Abstract Business Flow
Traditional MVC/MVP/MVVM patterns do not handle business flow and view transitions well. We introduced a UseCase to encapsulate business logic and a UIPage to represent screens, allowing flow code to be centralized and reusable.
2. Add Routing Mechanism
We created a routing system that receives a data model, parses it, and triggers actions such as opening a UseCase, a UI page, a webview, a mini‑program, or a dialog. The routing data model combines a route type with the required parameters.
3. Manage Network Requests
Old architecture used a singleton network center with broadcast callbacks, causing one‑to‑many communication bugs and lifecycle issues. The new design treats each network request as an independent command object derived from BaseCgi, owned by a UseCase, ensuring a one‑to‑one lifecycle.
4. Standardize Data Transfer
We eliminated shared mutable models, switched to immutable value types, enforced one‑way data flow with dependency injection, and used the delegate pattern for necessary backward notifications. This removed data pollution and made data flow traceable.
Summary
The architecture’s essence is managing complexity arising from intricate payment business requirements. By abstracting use cases, introducing a routing layer, encapsulating network commands, and enforcing disciplined data handling, the cross‑platform framework dramatically reduces code size, accelerates feature delivery, improves stability, and provides a solid foundation for future payment innovations.
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.
