Hello, I’m the black brother downstairs!
Today, I would like to share with you the payment principle of aggregate payment code, which is also the project I have been doing in the past half a year.
Wechat/Alipay payment code should be familiar to everyone. Most offline small and micro businesses use this payment code, as shown in the picture below.
This way of payment is very convenient, wechat, Alipay backstage application for opening, and then you can apply for relevant materials for free.
However, this way of user experience is not very good, before several times took out Alipay, but swept the wechat payment code.
In addition, the personal payment code usually has a one-day payment limit, such as alipay’s one-day limit of 500 yuan.
With the demand, naturally there will be smart people think of solutions, so there is the aggregation payment code product solution, as shown in the figure below.
A payment code, support a variety of clients, the mainstream is wechat, Alipay, now common will support Unionpay, QQ and so on.
Users choose any supported client scan code, can complete the payment, no longer tangle with the embarrassment of scanning wrong code.
Is it amazing? In fact, the underlying principle is very simple, after reading you will understand, let the little black brother take you to decrypt the underlying principle of aggregation collection code.
Welcome to pay attention to my public account: procedures to get daily dry goods push. If you are interested in my topics, you can also follow my blog: studyidea.cn
Wechat related payment methods
In fact, the payment at the bottom of the aggregate payment code is inseparable from the payment methods supported by wechat and Alipay. Therefore, we first start from the wechat Alipay channel and briefly introduce the payment methods that will be used in this process.
Last article, we take Alipay as an example to introduce, this time we will take wechat payment as an example.
Open wechat Pay official website, you can see a lot of payment methods.
Among them, payment code payment has been completely introduced in the previous two articles, which will not be introduced here. Interested partners can take a look at the following two articles.
How is it possible to pay when your phone is off the Internet? | original
A quick swipe, instant deduction, and the principle behind the payment code don’t you want to know? | original
First of all, let’s introduce wechat Native payment, citing the explanation on wechat official website:
Native payment is a mode in which the merchant system generates a qr code for payment according to the wechat payment agreement, and users complete the payment by “scanning” on wechat. This mode is suitable for PC website payment, physical store single product or order payment, media advertising payment and other scenarios.
Simply speaking, the merchant background calls the wechat payment interface, and wechat returns the link of pre-payment transaction in the following format:
weixin://wxpay/bizpayurl? sr=123456Copy the code
The merchant then turns it into a QR code and provides it to customers to pay by scanning the code on wechat.
This payment method can be applied to PC website shopping scenes, such as the official website of League of Legends to buy relevant game props:
Since wechat Native payment can finally become a TWO-DIMENSIONAL code to complete the payment, can the aggregation payment code adopt wechat Native payment as a payment method?
The answer is yes, but no, the product experience is not great.
It is better to pay with JSAPI, another payment product of wechat Pay.
As for the reason, don’t worry, the next read will understand.
JSAPI payment, also known as the public account payment, noun explanation quoted from the official website introduction:
JSAPI payment means that the user opens the H5 page of the merchant in wechat, and the merchant invokes the JSAPI interface provided by wechat Payment to complete the payment on the H5 page.
The specific business process is as follows:
In daily life, this payment method is used in many application scenarios, such as: geek time public account to buy lessons
Compared with wechat Native payment, this payment method is more troublesome and requires the login authorization function of wechat public account to obtain the user’s OpenID.
In addition, when we call wechat JSAPI background interface and get relevant parameters returned by wechat, we also need to use wechat JSSDK, so as to arouse wechat payment.
Core principle of aggregation payment code
After understanding the underlying payment method required by aggregate payment, let’s take a look at the core principle of aggregate payment code.
The business process of aggregation payment code is as follows:
In the first step, users scan the code using the wechat/Alipay APP to open a cashier page.
The cashier page can be adaptive, and different apps will display different styles. For example, when alipay opens the cashier desk, alipay’s logo will be displayed, while wechat’s logo will be displayed.
In the second step, the user enters the amount at the cashier desk and clicks “Pay” to evoke the payment popup of the APP.
Ok, observing the process, we can see that after scanning the code, the background application needs to identify whether the current APP is wechat or Alipay.
So how do you tell which APP you’re using?
In fact, this principle is very simple. Opening a link in Alipay/wechat will actually initiate an HTTP request using the built-in browser, and the HTTP request header will carry user-Agent (UA), which is used to identify the application type, operating system, software developer and version number of the User Agent software.
The browser in wechat/Alipay initiates an HTTP request, carrying the following User-Agent:
Pay treasure UCBrowser / 11.5.0.939 UCBS / 2.10.1.6 Mobile Safari / 537.36 AliApp AlipayClient / 10.0.15.051805 (AP / 10.0.15.051805) Language/useful - Hans WeChat MQQBrowser TBS 043220 MicroMessenger Safari / 537.36/6.2/6.5.8.1060 NetType Language/zh_CN / 4 gCopy the code
It needs to be noted that the user-Agent may not be the same for different mobile phones and different versions of APP. In fact, we just need to determine whether certain keywords are included. For example, if the user-Agent includes MicroMessenger, it is wechat. Alipay includes AlipayClient.
Use Java code as an example:
String userAgent = request.getHeader("user-agent");
if (Objects.equals(userAgent, "AlipayClient")) {
/ / alipay
} else if (Objects.equals(userAgent, "MicroMessenger")) {
/ / WeChat
}
Copy the code
After this problem is solved, the following process is very simple, just call wechat/Alipay JSAPI payment interface, get the relevant parameters, call the payment.
Tell accurately, pay treasure there JSAPI pay official name is pay treasure life number to pay.
Here to explain the above problem, why can’t the aggregate payment code use wechat Native payment?
The main reason is that the return of wechat Native payment interface is a wechat custom Schema protocol, which can only be opened through wechat scanning code to arouse payment.
How to use wechat Native payment? After the cashier submits the amount, it is necessary to turn the transaction link back to wechat into a TWO-DIMENSIONAL display on the page, and then users use the built-in two-dimensional code recognition function of wechat to evoke payment.
In this way, the product experience will be affected and the success rate of payment will be reduced.
Alipay also has a similar payment interface to wechat Native — face to face payment by scanning code, and the payment link will be returned after successful call.
That here can mention everyone to mention a small problem, aggregation collection code can use alipay pay scan code pay interface that?
The answer is yes, and the experience is better than wechat Native payment.
This is because the Alipay return link is a standard HTTP connection, as follows:
https://qr.alipay.com/xxxx
Copy the code
This link can be invoked as long as it is opened in Alipay.
Therefore, if the aggregate payment code uses the alipay face to face scanning code payment interface, after the amount is submitted at the cashier desk, when the payment link returned by Alipay is received, as long as HTTP 302 is used in the application to jump to the payment link, alipay payment can be aroused.
Voice-over: I also thought that Alipay and wechat can not be used before.
In this way, there are actually two schemes for using payment mode at the bottom of aggregate payment code:
- Wechat JSAPI Pay/Alipay Life Pay
- Wechat JSAPI pay/Alipay face pay scan code payment
So how do you choose that? Personally, I suggest using the first solution. Both wechat and Alipay adopt JSAPI payment.
The main reason is that as long as the 302 redirect arouses alipay payment, the cashier page will be closed, so the whole wechat payment and Alipay payment process is not quite the same
Secondly, when the user pays successfully, JSAPI payment can also jump to a successful page, this page we can pay results show, or a little SAO, but also hang some advertising, or drainage on other public number.
However, if you use Alipay to pay by scanning code, the page will be closed after the payment is completed, and the payment page can not be redirected.
Aggregate payment code core process
After introducing the principle, the following mainly introduces the mainstream aggregation payment code business process on the market. In fact, aggregation payment code can be divided into three types:
- Static aggregate payment code
- Dynamic aggregate payment code
- Unionpay static QR code
Static aggregate payment code is similar to the following, requires the user to actively enter the amount, can be used for unlimited times.
The dynamic aggregation payment code can only be used once, and the amount specified by the merchant, the user can pay the specified amount as long as the scan code.
Such application scenarios as buying large membership in station B:
The static TWO-DIMENSIONAL code of UnionPay actually has the same function as the static aggregation payment code, but it has more functions to support unionPay payment.
In addition to this, the main difference is that unionPay static TWO-DIMENSIONAL code is unionPay sending code, and the corresponding address behind is The address of UnionPay, similar to the following:
https://qr.95516.com/00010000/xxx
Copy the code
Static collection code aggregation process
Static aggregation payment code Main The payment process can be divided into two steps. The first step is login authorization.
Login authorization here generally uses the anonymous login authorization function of wechat and Alipay, so that ordinary users are actually unaware of this process.
Voiceover: If you are a programmer, you may feel that this process goes through many jumps.
In the second step, after the user enters the amount at the cashier, the corresponding order will be created inside the app, and then the payment will be made by invoking JSAPI of wechat/Alipay.
In addition, if Alipay adopts the payment method of face payment and scanning code payment, it actually does not need the first step of login authorization, and can directly jump to the cashier to initiate payment.
Dynamic aggregation payment code process
In fact, the dynamic aggregation payment code and static payment code is generally similar, but the creation of dynamic code has created the corresponding order, the follow-up process and static aggregation payment code is similar.
Unionpay static QR code process
If you scan the qr code of UnionPay using wechat or Alipay, the cashier page will be opened. The subsequent process is exactly the same as the static aggregation payment code.
However, if you scan the code of the UnionPay APP, such as the mobile phone APP of major banks, Meituan, JINGdong, etc., you will pay on the payment page of each APP and then complete the payment.
Our unionPay qr code function will report a jump address in the background of UnionPay, for example
https://www.heihei.com
Copy the code
When a User accesses the QR code of UnionPay using wechat/Alipay, the backstage of UnionPay identifies the access request user-Agent by itself, and then the backstage joins the redirected address according to the rules.
The stitching rules are as follows:
https://www.heihei.com?qrCode=URLENCODE(https://qr.95516.com/00010000/xxx)
Copy the code
conclusion
Aggregating payment codes unify the payment process of users and improve the payment efficiency of merchants.
In addition, the aggregation payment code can also get through with some ERP and other software in the business background, which also improves the production efficiency of the business.
I have to say, the first product designed to aggregate payment code, real genius ~
Aggregation payment code, the principle behind it is not difficult, according to the User-Agent access request, to determine the type of client the User is currently scanning code.
Then call wechat/Alipay anonymous login to obtain the user ID. Finally, after the user enters the amount, call wechat/Alipay to complete the payment.
Ok, today’s article is introduced here, finally, click a “like” before you go ~
Hee hee, National Day is coming, we boil a few days!!
The relevant data
- Pay.weixin.qq.com/wiki/doc/ap…
- opendocs.alipay.com/open/194
- Developers.weixin.qq.com/doc/offiacc…
Welcome to pay attention to my public account: procedures to get daily dry goods push. If you are interested in my topics, you can also follow my blog: studyidea.cn