Quickly develop WeChat applet 2-WeChat payment

1. Background

When interviewing programmers, there are two experiences that will bring big bonus points. First, have you done business related to payment finance? Second, have you written the underlying framework middleware code. Today we will talk about WeChat payment. How to connect.

2. Related concepts

1. WeChat merchant platform

To use WeChat payment, the first step is to register on the WeChat merchant platform. Prepare your business license, legal person ID card, etc. to complete the registration. The platform will generate MCH_ID (merchant ID), MCH_KEY (merchant key), Then apply to activate payment product types, operation certificates, bind bank cards, etc.

2. Access mode

direct connection mode

           Merchants develop their own systems to connect with WeChat Pay for transactions, and WeChat Pay settles funds to the merchant's settlement account.

Service provider model

            Merchants do not have their own systems. Instead, the system developers officially registered with WeChat Pay provide assistance to complete the registration. It seems that this is done by Youzan.

3. Payment product type

JSAPI web page payment : that is, official account payment, click Pay on the official account web page to activate the payment control.

Mini program payment: The mini program is connected to the WeChat payment API to enable users to complete transaction scenarios within the mini program.

In addition, there are offline payment code payment and scan code payment . This is what is often asked when paying, do you scan me or should I scan you?

There are also AppSDK payment, H5 payment , etc.

3. Related interfaces

1. Unified order placement

WeChat's various payment product types (except payment codes) need to first call the unified order interface, generate a prepayment transaction order in the WeChat background, and then invoke the corresponding payment controls according to various payment scenarios.

Request parameters: APPID\MCH_ID\random string, order code, product-related information, price, payment success callback address, etc.

Return value: Prepaid transaction session ID

Double signature concept

First signature: signature for calling the unified ordering interface

The second signature: Sign the prepayment transaction session ID + APPID + random string and then return it to the applet. The applet gets this signature string and adjusts the interface to invoke the payment window.

2、wx.requestPayment

The mini program calls requestPayment to call up the payment window. If the payment is successful after entering the payment password, the WeChat server will call back the callback address you passed when prepaying.

Request parameters: String generated by prepaid secondary signature

3. Payment callback notification interface

When making a callback, perform a decryption and return the merchant order number, the payment order number generated by the WeChat platform (to facilitate reconciliation), the actual user payment amount, payment time, etc.

4. Refund application interface

If it is returned in the original way and cannot be refunded after one year, partial refund can be made. When calling the refund interface, the operation certificate needs to be loaded for two-way authentication. PS: We do not provide this interface to users, but do it in the management system. When customers need a refund, they call the hotline to find customer service. There are still some differences between vertical e-commerce and platform e-commerce.

5. Query refund interface

There is a delay in WeChat refund. It takes 20 minutes to return the change payment. If it is a bank card, it takes 3 working days. PS: I am not sure if there is any adjustment now.

4. WeChat payment call sequence diagram

PS: During development, if there is system interaction between three parties or more, it is best to draw the timing diagram, so as to facilitate the overall understanding. Generally, flow charts (product logic), ER diagrams (data flow), class diagrams ( Code structure) and sequence diagram (code interaction) are basically the same.

Guess you like

Origin blog.csdn.net/2301_76787421/article/details/133501356