Unlocking the Secrets of Aggregated QR Payment Codes for WeChat and Alipay
This article explains how aggregated QR payment codes unify WeChat and Alipay transactions by detecting the client via User-Agent, using JSAPI instead of Native payments, and outlines static, dynamic, and UnionPay QR workflows with practical code examples.
WeChat Related Payment Methods
The aggregated QR code still relies on WeChat and Alipay payment methods, so we first review the WeChat payment options.
We focus on WeChat payment this time; the Alipay version was covered previously.
On the WeChat Pay website you can see many payment methods.
Payment code (Native) was fully introduced in earlier articles and is not repeated here.
We recommend using the JSAPI payment (also known as public account payment) instead of Native payment for a better user experience.
JSAPI 支付是用户在微信中打开商户的 H5 页面,商户在 H5 页面通过调用微信支付提供的 JSAPI 接口调起微信支付模块完成支付。The business flow for JSAPI payment is illustrated below:
Aggregated QR Code Core Principle
After understanding the underlying payment methods, we explore the core principle of aggregated QR codes.
The business process is shown below:
Step 1: The user scans the QR code with WeChat or Alipay, opening a checkout page that adapts its logo to the app.
Step 2: The user enters the amount and triggers the app's payment popup.
To identify whether the request comes from WeChat or Alipay, the backend examines the User-Agent (UA) header.
支付宝
UCBrowser/11.5.0.939 UCBS/2.10.1.6 Mobile Safari/537.36 AliApp(AP/10.0.15.051805) AlipayClient/10.0.15.051805 Language/zh-Hans
微信
MQQBrowser/6.2 TBS 043220 Safari/537.36 MicroMessenger/6.5.8.1060 NetType/4G Language/zh_CNWe only need to check for key substrings such as "MicroMessenger" for WeChat and "AlipayClient" for Alipay.
String userAgent = request.getHeader("user-agent");
if (Objects.equals(userAgent, "AlipayClient")) {
// Alipay logic
} else if (Objects.equals(userAgent, "MicroMessenger")) {
// WeChat logic
}After detecting the client, the system calls the respective JSAPI payment APIs to complete the transaction.
For Alipay, the JSAPI equivalent is called "Alipay Life Account Payment".
Using Native payment for aggregated QR codes is possible but leads to a poor experience because the returned schema can only be opened by the corresponding app.
Instead, using JSAPI (or Alipay Life payment) allows a smooth flow with optional success-page redirects.
Aggregated QR Code Core Process
Aggregated QR codes can be classified into three types:
Static aggregated QR code – users input the amount; reusable indefinitely.
Dynamic aggregated QR code – amount is preset; usable only once.
UnionPay static QR code – similar to static but supports UnionPay.
Static QR example:
Dynamic QR example (e.g., B‑Station VIP purchase):
UnionPay static QR code URL format: https://qr.95516.com/00010000/xxx Static aggregated QR flow:
Login/authorization is usually performed via anonymous WeChat or Alipay login, invisible to the user.
After the user inputs the amount, the system creates an order and calls the JSAPI payment.
If Alipay Face‑to‑Face payment is used, the login step can be skipped.
Dynamic QR flow is similar, with the order created beforehand:
UnionPay QR code flow:
When a UnionPay QR is scanned by WeChat/Alipay, the backend detects the User-Agent and redirects to the merchant’s URL; when scanned by a UnionPay app, the native UnionPay payment page is shown.
https://www.heihei.com?qrCode=URLENCODE(https://qr.95516.com/00010000/xxx)Conclusion
Aggregated QR codes unify the user payment flow and improve merchant collection efficiency, and can be integrated with ERP systems for higher operational productivity.
The core principle is simple: use the HTTP User-Agent to identify the scanning client, obtain the user ID via anonymous login, let the user enter the amount, and finally invoke WeChat or Alipay payment APIs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
