Mobile Development 17 min read

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

This article explains how WeChat Pay solved the fragmented iOS/Android implementations by building a C++‑based cross‑platform framework, introducing UseCase‑driven flow abstraction, a unified routing mechanism, disciplined network request handling, and standardized data passing, resulting in up to 45% code reduction and faster feature delivery.

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

As a critical business, WeChat Pay faced many problems on the client side, the core of which was the split‑platform implementation leading to bugs, poor quality assurance, low scalability, and long iteration cycles.

Background

iOS and Android implementations were inconsistent, causing bugs, communication issues, poor extensibility, and a fragile quality‑assurance system.

To address these core issues and eliminate technical debt, a C++‑based cross‑platform framework was built, and the core payment flow was refactored.

WeChat Pay cross‑platform coverage started from iOS 7.0.4 and Android 7.0.7.

Online Effect Metrics

Crash rate remained stable before and after launch, with no mandatory crashes, achieving seamless user experience.

Code size for the core payment flow reduced from 6,328 lines (iOS native) to 3,512 lines (cross‑platform), a reduction of nearly 45%.

Feature development effort dropped from 5 person‑days (native) to 3 person‑days (cross‑platform) for a cash‑register redesign, and the same for a simplified version.

What Is Software Architecture?

Software architecture is the composition of system components and their relationships, often expressed as MVC, MVVM, etc.

Why Need Software Architecture?

Complex business requirements create inherent complexity; architecture manages this complexity through responsibility separation and code reuse.

Building the Payment Cross‑Platform Architecture From Zero to One

1. Abstract Business Process

Traditional MVC mixes business flow with UI controllers, leading to scattered code and poor reuse. To handle WeChat Pay’s many flows and complex page transitions, a new abstraction UseCase was introduced to encapsulate business logic, and UIPage to represent screens.

Benefits:

Business logic aggregates in UseCase instead of being scattered across ViewControllers/Activities.

Business flow and UI become reusable.

Fits the complex, multi‑step nature of WeChat Pay.

2. Add Routing Mechanism

A routing mechanism parses data and triggers actions such as opening a UseCase, a UI page, a WebView, a mini‑program, or a dialog.

In this article, CGI refers to a network request similar to HTTP.

Routing unifies flow handling, reduces duplication, and makes special processes (e.g., opening a WebView) consistent.

3. Manage Network Requests

Old architecture used a singleton network center with broadcast notifications, leading to one‑to‑many communication bugs and lifecycle issues.

Solution:

Encapsulate each request as an independent BaseCgi object (command pattern).

Bind the request lifecycle to the UseCase that initiates it, ensuring the request is destroyed when the UseCase finishes.

Provide unified caching and encryption capabilities.

4. Standardize Data Passing

Previous shared models caused data pollution and hard‑to‑trace bugs. The new approach eliminates public mutable models, passes immutable value types, uses single‑direction injection, and employs the delegate pattern for necessary callbacks.

Benefits:

Eliminates data‑pollution bugs.

Data flow becomes single‑direction and traceable.

Summary

Software architecture’s essence is managing complexity arising from business requirements. By abstracting business flows, introducing routing, managing network requests, and standardizing data transmission, the WeChat Pay cross‑platform architecture achieved higher quality, reduced code, and faster feature delivery, while laying a foundation for future extensions such as automated data reporting, anti‑duplicate payment, and security cross‑cutting concerns.

software architecturecross-platformC++routingData Flownetwork requestsWeChat 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.