Mobile Development 14 min read

How We Built a C++ Cross‑Platform Architecture for WeChat Pay to Boost Productivity

This article explains how WeChat Pay tackled inconsistent iOS and Android implementations by creating a C++‑based cross‑platform framework, introducing UseCase and UIPage abstractions, a routing mechanism, unified network request handling, and standardized data flow, resulting in reduced code, faster feature delivery, and higher stability.

Java Backend Technology
Java Backend Technology
Java Backend Technology
How We Built a C++ Cross‑Platform Architecture for WeChat Pay to Boost Productivity

Background

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

iOS vs Android checkout UI
iOS vs Android checkout UI

To solve these problems, a C++ cross‑platform framework was built and the core payment flow was refactored, covering iOS from version 7.0.4 and Android from 7.0.7.

Online Metrics

Crash Rate

The crash rate remained stable after launch, with no mandatory crashes, providing a seamless user experience.

Example: sending a red packet uses the cross‑platform C++ code.

Efficiency Improvement

Code line reduction
Code line reduction

The cross‑platform implementation uses 3512 lines versus 6328 lines for native iOS, a 45% reduction.

Feature development examples show cross‑platform taking 3 person‑days versus 1 week for native.

What Is Software Architecture?

Software architecture defines system components and their relationships, often expressed as MVC, MVVM, etc. For WeChat Pay, architecture is seen as the composition of modules and communication methods.

Why Architecture Is Needed

Complex business requirements create inherent software complexity. Managing this complexity through separation of concerns, code reuse, and modular design improves productivity.

Building the Cross‑Platform Architecture

1. Abstract Business Flow

Introduce UseCase to encapsulate business processes and UIPage for UI screens, allowing reuse and clear separation.

UseCase and UIPage diagram
UseCase and UIPage diagram

2. Add Routing Mechanism

Implement a routing system that receives a data model, parses it, and triggers actions such as opening a UseCase, UIPage, WebView, or mini‑program.

Routing mechanism
Routing mechanism

Domain modeling uses UML and Proto protocols to define routing data.

3. Manage Network Requests

Replace the singleton network center with independent Cgi objects using the command pattern, binding each Cgi’s lifecycle to its UseCase.

Cgi command pattern
Cgi command pattern

4. Standardize Data Transfer

Eliminate shared mutable models, use immutable value types, enforce one‑way data flow, and apply the delegate pattern for necessary callbacks.

Data flow diagram
Data flow diagram

Summary

Good software architecture manages complexity arising from demanding business scenarios. By abstracting business flows, adding routing, unifying network handling, and standardizing data transfer, the WeChat Pay cross‑platform architecture reduces code size, accelerates feature delivery, improves stability, and provides a solid 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.

Mobilecross‑platformarchitectureWeChat PayC++
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

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.