How WeChat Pay Solved Cross‑Platform Mobile Challenges with a C++ Architecture
This article explains how WeChat Pay tackled inconsistent iOS and Android implementations by building a unified C++ cross‑platform framework, introducing UseCase‑based business flow, a routing mechanism, and improved network request handling, resulting in fewer bugs, faster development, and higher productivity.
WeChat Pay faces significant challenges across operating systems and applications, mainly due to separate iOS and Android implementations that cause bugs, poor scalability, incomplete data reporting, and inconsistent user experience.
To address the core issue of platform‑specific code, a comprehensive C++ cross‑platform framework was created, reconstructing the core payment flow and achieving full coverage from iOS 7.0.4 and Android 7.0.7.
Performance improvements : the cross‑platform implementation required only 3,512 lines of code for the core payment flow, compared with 6,328 lines in native iOS, a reduction of nearly 45%. Development time for a new feature (e.g., cash‑register redesign) dropped from a week to three person‑days.
Software architecture definition : architecture is defined as the system components and their communication. Business flow is abstracted into a UseCase , while UI pages are represented as UIPage . This separates business logic from view controllers and activities.
Routing mechanism : a routing layer receives data, parses it, and triggers actions such as opening a UseCase, launching a UI page, a WebView, a mini‑program, or a dialog. The routing model consists of a type and the parameters required for that type.
Network request management : the legacy design used a singleton network center, leading to one‑to‑many CGI communication problems and lifecycle bugs. The new design abstracts each CGI as an independent command object tied to a UseCase, ensuring a one‑to‑one relationship and proper lifecycle handling.
Data transmission standardization : shared mutable models are eliminated. Value‑type data is passed unidirectionally, and any required notifications use the delegate pattern, preventing data pollution and making data flow traceable.
These architectural changes unify flow and page transitions, simplify special‑process handling, and reduce duplicated work. For example, opening a WebView or mini‑program now requires up to 83% less code.
Results : crash rates remain stable before and after deployment, code size is reduced, development speed increases, and the system becomes easier to maintain and extend.
In summary, a well‑designed software architecture manages the inherent complexity of payment business requirements, continuously evolves with new features, and delivers tangible business value such as higher productivity, better quality assurance, and robust cross‑platform support.
ITFLY8 Architecture Home
ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.
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.
