Mobile Development 16 min read

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

This article describes how a C++‑based cross‑platform framework and a unified routing mechanism were built for WeChat Pay to eliminate platform‑specific bugs, streamline data flow, improve crash stability, cut code size by nearly 45%, and boost development productivity across iOS and Android.

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

Background

WeChat Pay faces major issues due to separate iOS and Android implementations, leading to bugs, poor quality assurance, long iteration cycles, incomplete data reporting, and inconsistent user experience.

Online Effect Metrics

After launching the cross‑platform solution, crash rates remained stable, and code for the core payment flow dropped from 6,328 lines (iOS native) to 3,512 lines (cross‑platform), a reduction of about 45%.

What Is Software Architecture

Software architecture is the set of components and their relationships that manage complexity; in this context it is defined as the system’s components and communication methods, often expressed via patterns such as MVC or MVVM .

Why Architecture Is Needed

Complex business requirements create inherent complexity; separating responsibilities and reusing code through architecture mitigates this complexity.

Building the Cross‑Platform Architecture

We introduced a C++‑based cross‑platform framework to unify the payment flow. The core ideas are:

Abstract business processes into independent UseCase objects.

Represent UI screens as UIPage objects.

This abstraction moves business logic out of platform‑specific ViewControllers/Activities, improving reuse and clarity.

Adding a Routing Mechanism

A routing layer passes a data model (the “payment domain model”) to a router, which parses the model and triggers actions such as opening a UseCase , launching a UI page, displaying a WebView, or invoking a mini‑program.

Managing Network Requests

Old implementations used a singleton network center, causing one‑to‑many CGI communication bugs and lifecycle issues. The new design treats each CGI as an independent command object derived from a base CGI class, binding its lifecycle to a single UseCase and eliminating cross‑request interference.

Standardizing Data Transmission

We removed shared mutable models, switched to immutable value types, enforced single‑direction data flow, and used dependency injection or the delegate pattern for necessary updates, thereby preventing data pollution and making the flow traceable.

Results

Unified process and UI flow, making the system easier to maintain.

Centralized handling of special flows (WebView, mini‑program, pop‑ups), reducing duplicated code by up to 83%.

Eliminated one‑to‑many CGI bugs, ensured CGI lifecycle matches business logic, and improved cohesion while reducing coupling.

Data transmission became single‑direction, eliminating the “blackboard” pattern that caused data leaks and crashes.

Conclusion

Effective software architecture manages complexity by abstracting business processes, introducing routing, encapsulating network requests, and enforcing clean data flow. The cross‑platform architecture for WeChat Pay demonstrates measurable improvements in code size, stability, and developer productivity, and serves as a foundation for further feature expansion.

Mobile Developmentsoftware architectureCross‑PlatformC++Data ModelingRoutingWeChat 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

login 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.