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

Cross‑Platform Architecture for WeChat Pay: Reducing Code, Improving Quality and Productivity
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.

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.

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
Mobile DevelopmentSoftware Architecturecross-platformC#Data ModelingroutingWeChat Pay

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion