Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

How a C++ Cross‑Platform Framework Transformed WeChat Pay Client Development
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.

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.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Report an issue with this article
routingmobile architectureWeChat PayC++cross‑platformcode reductionnetwork request management

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion