WeChat Pay--Theory

The previous mall system (WeChat applet), used WeChat payment and WeChat refund functions, now let’s summarize

Shopping payment process: place an order--》

WeChat refund: The user applies for a refund for the order; the merchant agrees to the refund at the mall management side, and realizes the WeChat refund

WeChat Pay includes:

Official account payment

Mini program payment

Scan QR code to pay

H5 payment

app payment

Credit card payment

openId:

In order to identify users, each user generates an operId for each official account or applet and other applications. The official account or applet application stores the openId in the database, so that it can be identified the next time you log in.

Mini program deployment:

https://mp.weixin.qq.com/?url=%2Fwxopen%2Fauthprofile%3Faction%3Dindex%26token%3D1040303389%26lang%3Dzh_CN

Development settings:

Payment settings:

Development management:

When the development progresses to a certain stage, after the developer submits the code, the corresponding version can be set as the trial version

When you need to go online, submit the uploaded code to Tencent for review. After the review is passed, you can publish it online, as shown in the figure

WeChat payment process: (I have only written the background code of WeChat payment and WeChat refund, but have not participated in the relevant configuration; I will learn about the entire development process of WeChat payment when I have time in the future)

Go to  https://pRemove ay.weRemove ixin.qq.comRemove /wiki/doc/api/wxa/Remove wxa_api.php?Remove chapter=7_4&Remove index=3  

I don't know if it will be blocked. . . .

Payment mode:

1、

Payment code payment

Payment code payment is a mode in which the user displays the "swiping barcode/QR code" in the WeChat wallet to the merchant system to scan and complete the payment directly. The main application is the scene of cash register opposite to the line below.

2、

Native payment

Native payment is a mode in which the merchant system generates a payment QR code according to the WeChat payment protocol, and the user uses WeChat to "scan" to complete the payment. This mode is suitable for PC website payment, physical store single product or order payment, media advertising payment and other scenarios.

3、

JSAPI payment

JSAPI payment is when the user opens the merchant's H5 page in WeChat, and the merchant invokes the WeChat payment module to complete the payment by calling the JSAPI interface provided by WeChat Pay on the H5 page . The application scenarios are:

  1. ◆ The user enters the merchant's official account in the WeChat official account, opens a certain main page, and completes the payment
  2. ◆ The user's friends share the merchant page connection in the circle of friends, chat window, etc., the user clicks on the link to open the merchant page and completes the payment
  3. ◆ Convert the merchant page into a QR code, the user scans the QR code and opens the page in the WeChat browser to complete the payment

4、

APP payment

APP payment, also known as mobile payment, is a mode in which merchants complete the payment by integrating the open SDK into the mobile application APP and tune up the WeChat payment module.

5、

H5 payment

H5 payment is mainly a payment product that evokes WeChat payment through the browser in mobile devices such as mobile phones and ipads.

6、

Mini program payment

Mini Program Payment is a payment product specifically defined for use in Mini Programs . At present, we can and can only use the small program payment method to evoke WeChat payment in the small program.

Noun introduction:

WeChat payment system

WeChat payment system refers to the general term for the API interface, background business processing system, accounting system, callback notification and other systems involved in the completion of the WeChat payment process.

Merchant backend system

Merchant back-office system is the general term for merchant back-office processing business systems, such as: merchant website, cashier system, invoicing system, delivery system, customer service system, etc.

Merchant Certificate

The merchant certificate is a binary file provided by WeChat. When the merchant system initiates a communication request with the WeChat payment back-end server, it serves as a credential for the WeChat payment back-end to identify the real identity of the merchant .

signature

The merchant backend and WeChat payment backend generate a result based on the same key and algorithm, which is used to verify the legitimacy of the identities of both parties . The signature algorithm is formulated and published by WeChat Pay. Commonly used signature methods are: MD5, SHA1, SHA256, HMAC, etc.

JSAPI web payment

JSAPI web payment is the official account payment mentioned above. You can click on the page link in the WeChat official account, Moments, or chat session, or use WeChat to scan the QR code of the page address to open the merchant HTML5 page in WeChat. Place an order on the page to complete the payment .

Openid

The user's identity in the applet, different applets have different openids . The merchant's back-end system can obtain the user's openid through APIs such as login authorization, payment notification, and order query. The main purpose is to judge the same use. The interface can be called to obtain the openid .

The corresponding relationship between the account parameters in the email and the interface API parameters is shown in Table 3.1:

Parameters in the email API parameter name Detailed description
APPID appid The appid is the unique identifier of the WeChat applet background APP . After applying for the applet account in the applet background, WeChat will automatically assign the corresponding appid to identify the application. It can be viewed in Mini Program-->Settings-->Development Settings.
WeChat Pay Merchant Number mch_id After the merchant applies for WeChat Pay, the merchant receiving account number assigned by WeChat Pay.
API key key The key that generates the signature during the transaction is only kept in the merchant system and WeChat payment backend, and will not be spread across the network. Merchants keep the key properly, do not transmit it on the network, or store it in other clients, to ensure that the key will not be leaked. Merchants can log in to the WeChat merchant platform to set up according to the email prompts. It can also be set according to the following path: WeChat Merchant Platform (pay.weixin.qq.com)-->Account Settings-->API Security-->Key Settings
Appsecret secret AppSecret is the interface password corresponding to APPID, which is used to obtain interface invocation credentials .

Interface rules:

Agreement rules:

Merchants accessing WeChat Pay and calling API must follow the following rules:

transfer method To ensure transaction security, HTTPS transmission is adopted
Submission method Submit using POST method
Data Format The submitted and returned data are in XML format, and the root node is named xml
Character Encoding Unified UTF-8 character encoding
Signature algorithm MD5, it will be compatible with SHA1, SHA256, HMAC, etc. in the future.
Signature requirements Both request and received data need to verify the signature . For details, please refer to the security specification-signature algorithm
Certificate requirements A merchant certificate is required to call the interface for requesting refunds and canceling orders
Judgment logic First judge the agreement field return, then judge the business return, and finally judge the transaction status

Parameter specification:

1. Transaction amount

The transaction amount defaults to RMB transaction, the parameter payment amount unit in the interface is [minutes], and the parameter value cannot contain decimals . The unit of transaction amount in the statement is [yuan].

The payment amount of foreign currency transactions is accurate to the smallest unit of the currency, and the parameter value cannot take a decimal point.

2. Transaction type trade_type

JSAPI--JSAPI payment (or applet payment) , Native--Native payment, APP--app payment, MWEB--H5 payment, different trade_types determine the method of transfer payment, please upload correctly according to the payment product

MICROPAY-payment code payment, payment code payment has a separate payment interface, so the interface does not need to be uploaded, this field will appear in the statement

3. Currency type

Domestic merchant accounts only support RMB

CNY: Chinese yuan

4. Time

Standard Beijing time, the time zone is Dongba District; if the merchant’s system time is non-standard Beijing time. The parameter value must first be converted to standard Beijing time according to the time zone where the merchant system is located.  For example, if the location of the merchant is 0 time zone in London, the local time is November 11, 2014 0:00:00, and converted to Beijing time is November 11, 2014 Day 8: 0: 0 seconds.

5. Timestamp

Standard Beijing Time, the time zone is Dongba District, the number of seconds since 0:00:00 on January 1, 1970. Note: The value obtained by some systems is in milliseconds and needs to be converted into seconds (10 digits).

6. Merchant order number

The order number paid by the merchant is customized and generated by the merchant . It only supports the combination of letters, numbers, underscore-, underscore_, vertical bar|, asterisk* and these English half-width characters. Do not use special characters such as Chinese characters or full-width characters. WeChat Pay requires merchant order numbers to be unique (it is recommended to generate order numbers based on the current system time and a random sequence). To re-initiate a payment, the original order number should be used to avoid repeated payments; the order number that has been paid or that has been called to close or cancel the order (please refer to the API list below) cannot re-initiate the payment.

7, body field format

scenes to be used Payment mode Commodity field rules Sample Remarks
PC website Scan QR code to pay The title name of the homepage of the website opened by the browser-product overview Tencent Recharge Center-QQ Member Recharge  
WeChat browser Official account payment Merchant name-sales product category Tencent Games Online e-commerce, the business name must be the business that actually sells the product
Store QR Code Official account payment Store name-sales product category Xiaozhang Nanshan Store-Supermarket Offline store payment
Store QR Code Scan QR code to pay Store name-sales product category Xiaozhang Nanshan Store-Supermarket Offline store payment
Store payment code Payment code payment Store name-sales product category Xiaozhang Nanshan Store-Supermarket Offline store payment
Third-party mobile browser H5 payment The title name of the homepage of the mobile webpage opened by the browser-product overview Tencent Recharge Center-QQ Member Recharge  
Third party APP APP payment App name on the app market-product overview Everyday Love Elimination-Game Recharge  

8. Bank type

Character Bank Code Bank name

ICBC_DEBIT

Industrial and Commercial Bank of China (debit card)

safety regulations:

 

Open mode:

Normal mode: commonly used; suitable for direct-connected merchants who have their own development team or outsourced developers to collect payments.

Service provider model:

Business Process:

The interactive diagram of Mini Program payment is as follows:

The main interaction between the merchant system and the WeChat payment system:

1. Call the login interface in the applet to get the user's openid. For the api, please refer to the public api [ small program login API ]

wx.login(Object object)
calls the interface to obtain login credentials (code) .
Exchange the user login status information through the credentials, including the user's unique identifier (openid) and the session key (session_key) for this login

 

 

 

2. Merchant server calls and pays to place an order uniformly. For the api, please refer to the public api [ Uniform Order API-click to pay

Uniform Order
Placement Merchants first call this interface in the Mini Program to generate a pre-payment transaction order in the WeChat payment service backend , and return the correct pre-payment transaction to initiate the payment.

 

 

 

                         3. The merchant server calls to sign again, and for the api, see the public api [ Sign again-enter the payment password

Mini program calls up payment API

URL address: https://api.mch.weixin.qq.com/pay/unifiedorder

 

 

4. Merchant server connection 4. Receive payment notification, api see public api【Payment result notification API

Notification of payment result:

After the payment is completed, WeChat will send the relevant payment results and user information to the merchant in the form of a data stream. The merchant needs to receive and process, and return a response according to the document specification.

 

 

 

5. Merchant server queries payment results, api see public api [ query order API ]

This interface provides query of all WeChat payment orders. Merchants can actively query the order status through the query order interface to complete the next step of business logic

 

Mini program calls up payment API

1. The applet calls up the list of payment data signature fields:

Field name variable name Required Types of Sample value description
Mini Program ID appId Yes String wxd678efh567hg6787 Mini Program ID assigned by WeChat
Timestamp timeStamp Yes String 1490840662 Timestamp: The number of seconds from 00:00:00 on January 1, 1970 to the present, that is, the current time
Random string nonceStr Yes String 5K8264ILTKCH16CQ2502SI8ZNMTM67VS Random string, no longer than 32 bits. Recommended random number generation algorithm
data pack package Yes String prepay_id=wx2017033010242291fcfe0db70013231072 Unify the prepay_id parameter value returned by the order interface, the submission format is such as: prepay_id= wx2017033010242291fcfe0db70013231072
Signature method signType Yes String MD5 Signature type, the default is MD5, supports HMAC-SHA256 and MD5. Note that this must be consistent with the signature type of the unified order

Examples are as follows:

paySign = MD5(appId=wxd678efh567hg6787&nonceStr=5K8264ILTKCH16CQ2502SI8ZNMTM67VS&package=prepay_id=wx2017033010242291fcfe0db70013231072&signType=MD5&timeStamp=1490840662&key=qazwsxedcrfvtgbyhnujmikolp111111) = 22D9B4E54AB1950F51E0649E8810ACD6

2、调用wx.requestPayment(OBJECT)发起微信支付(点击支付功能)

参数 类型 必填 说明
timeStamp String 时间戳从1970年1月1日00:00:00至今的秒数,即当前的时间
nonceStr String 随机字符串,长度为32个字符以下。
package String 统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=*
signType String 签名类型,默认为MD5,支持HMAC-SHA256和MD5。注意此处需与统一下单的签名类型一致
paySign String 签名,具体签名方案参见微信公众号支付帮助文档;
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

3、回调结果(此时是用户输入支付密码

回调类型 errMsg 说明
success requestPayment:ok 调用支付成功
fail requestPayment:fail cancel 用户取消支付
fail requestPayment:fail (detail message) 调用支付失败,其中 detail message 为后台返回的详细失败原因
后端开发:
//todo
 

Guess you like

Origin blog.csdn.net/qq_24271537/article/details/109547255