Mobile Development 15 min read

How a C++ Cross‑Platform Framework Transformed WeChat Pay Client Development

The article explains how a C++‑based cross‑platform framework was built to unify iOS and Android implementations of WeChat Pay, reducing code size, improving crash stability, streamlining feature delivery, and addressing architectural issues such as inconsistent UI, poor scalability, and network request management.

ITPUB
ITPUB
ITPUB
How a C++ Cross‑Platform Framework Transformed WeChat Pay Client Development

Background: WeChat Pay faced major challenges due to separate iOS and Android implementations, including inconsistent UI, high bug rates, poor scalability, fragmented quality assurance, and difficulty handling complex payment flows.

Cross‑Platform Solution

A C++‑based cross‑platform framework was created to refactor core payment processes, covering iOS 7.0.4+ and Android 7.0.7+.

Online Metrics

Crash rate remained stable after migration, with no new crashes observed during payment.

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

Feature development time decreased dramatically: a UI redesign required 3 person‑days cross‑platform versus a week for native implementations.

Special flows (WebView, mini‑programs) saw up to 83% code reduction.

What Is Software Architecture?

Architecture is defined as the system’s components and their communication relationships, often expressed via MVC, MVVM, etc. For WeChat Pay, the architecture needed to handle numerous business flows and UI transitions.

Step‑by‑Step Evolution

1. Abstract Business Processes

Traditional MVC/MVP/MVVM models failed to capture complex payment flows. The solution introduced a UseCase abstraction for business logic and a UIPage abstraction for screens, allowing modular, reusable flow definitions.

2. Add Routing Mechanism

A routing layer was added to pass a payment‑domain model (derived from network responses) to the appropriate handler. The router parses the model and triggers actions such as opening a UseCase, launching a UI page, or invoking a WebView/mini‑program.

3. Manage Network Requests

Old architecture used a singleton network center with broadcast callbacks, leading to one‑to‑many communication bugs and lifecycle issues. The new design treats each network request as an independent command object (Cgi) instantiated per UseCase, ensuring a one‑to‑one lifecycle and eliminating cross‑flow interference.

4. Standardize Data Transfer

Shared mutable models caused data pollution and unpredictable bugs. The revised architecture replaces global models with immutable value types, enforces unidirectional data flow, and uses dependency injection or delegate patterns for necessary updates.

Results

Reduced code duplication and line count, improving maintainability.

Unified flow and page navigation across platforms, simplifying debugging.

Isolated network request lifecycles, preventing stale callbacks.

Eliminated data contamination by enforcing single‑direction, typed data transfer.

Accelerated feature delivery and reduced crash risk, delivering a seamless user experience.

Conclusion

Effective software architecture manages complexity inherent in rich payment business requirements. By abstracting use cases, introducing a routing layer, encapsulating network calls, and enforcing disciplined data flow, the WeChat Pay client achieved higher productivity, better stability, and a scalable foundation for future enhancements.

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.

routingmobile architectureWeChat PayC++cross‑platformcode reductionnetwork request management
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

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.