Mobile Development 14 min read

Cross‑Platform Architecture for WeChat Pay: Reducing Code, Improving Quality and Productivity

This article describes how WeChat Pay built a C++‑based cross‑platform framework that unifies iOS and Android payment flows, introduces a UseCase‑driven architecture with routing, refactors network request handling, and standardizes data transmission to cut code by 45%, boost reliability, and accelerate feature delivery.

Top Architect
Top Architect
Top Architect
Cross‑Platform Architecture for WeChat Pay: Reducing Code, Improving Quality and Productivity

Background

WeChat Pay faced serious issues caused by separate iOS and Android implementations, including bugs, poor extensibility, inconsistent user experience, and a fragile quality‑assurance system.

Online Impact

After launching the C++ cross‑platform framework (available from iOS 7.0.4 and Android 7.0.7), crash rates remained stable and code size for the core payment flow dropped from 6,328 lines (iOS native) to 3,512 lines, a reduction of nearly 45%.

What Is Software Architecture?

Architecture is defined as the set of components and their communication relationships, often expressed through patterns such as MVC or MVVM. For WeChat Pay, the focus is on managing complex business flows and UI transitions.

Why Architecture Is Needed

Complex business requirements generate inherent software complexity; separating responsibilities, reusing code, and managing this complexity are the core goals of a good architecture.

From Zero to One: Building the Cross‑Platform Architecture

1. Abstract Business Flow

Traditional MVC/MVP/MVVM ignore the orchestration of business processes. We introduced a UseCase to encapsulate each payment flow and a UIPage to represent UI screens, enabling clear separation and reuse.

2. Add a Routing Mechanism

A routing layer receives a data model (the “payment domain model”) and dispatches actions such as opening a UseCase, launching a page, a WebView, or a mini‑program. This unifies flow control and special‑case handling.

3. Manage Network Requests

Legacy code used a singleton network center with one‑to‑many callbacks, leading to lifecycle bugs. We refactored CGI calls into independent objects using the command pattern, binding each request’s lifecycle to its owning UseCase and providing unified caching and encryption.

4. Standardize Data Transmission

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, thereby preventing data pollution and making the flow traceable.

Result

The new architecture unifies iOS and Android payment flows, reduces code duplication, improves stability, and accelerates feature development (e.g., a UI redesign completed in 3 person‑days versus a week for native implementations). It also lays the foundation for future capabilities such as automated data reporting, anti‑duplicate payment checks, and security cross‑cutting concerns.

Conclusion

Good software architecture is about managing complexity derived from business needs; the cross‑platform design for WeChat Pay demonstrates how systematic abstraction, routing, request management, and data hygiene can turn a fragmented codebase into a robust, productive platform.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Mobile Developmentcross-platformCroutingWeChat Pay
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.