Dry Goods: How WeChat Mini Programs Connect to WeChat Pay

This article describes how to access Mini Program Payment from scratch, especially for developers who have no experience in WeChat payment access.

1. After applying for WeChat Pay

applet certification, you can apply for WeChat Pay in the WeChat Pay menu bar in the background of the applet.





Fill in the company information and corporate account, WeChat payment will send a random amount to the corporate account, and after the verification of the input amount is completed, the agreement is signed online, and the entire WeChat payment application process is completed.

After the WeChat payment application is completed, the WeChat payment merchant number, merchant platform username and password and other information will be sent to the registrant's mailbox.

2. Preparations
2.1 Configure the applet key





On the applet background setting page, click Generate. After the administrator verifies the QR code, the AppSecret will be randomly generated. Please keep the Appsecret in a safe place, and do not store it in the server in plain text. AppSecret is used to interact with the WeChat server. For example, it is needed to obtain the user's openid interface.

2.2 Set the key and download the certificate

Use the username and password obtained by applying for WeChat Pay, log in to the merchant platform (pay.weixin.qq.com), download the certificate and set the key in the account center and API security.

The key is 32 bits, and it needs to be kept properly after setting, because the key cannot be viewed, and all WeChat payment related interfaces will be encrypted with this key.

2.3 Configuring Https Server

The front end of the applet is developed using the framework provided by WeChat, but the back end is still the developer's own server. The applet initiates an https request, which means that the applet developer must configure an https server.

Before configuring the https server, you must first obtain a certificate. The certificate can be purchased from relevant institutions. Tencent Cloud can currently provide users with free certificates.

The certificate installation instructions can be found here:

https://www.qcloud.com/doc/product/400/4143

3. WeChat payment process

WeChat payment has a variety of payment methods, including credit card payment, official account payment, scan code payment, APP payment, here WeChat payment All interfaces: https://pay.weixin.qq.com/wiki/doc/api/index.html

The applet is paid in WeChat, which is actually the official account payment. The detailed documents about payment by official account can be viewed here: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_1All

links related to payment by official account can be found here , developers first need to have a general understanding of these interfaces.

The main process of Mini Program official account payment is as follows (this figure only considers the normal process, and the abnormal process refers to the official account payment document):





3.1 About openid

The request for openid in the above process uses the interface in the latest api of the Mini Program, and developers can View the login interface of the applet.

The openid obtained by the developer from the third-party server needs to be used in the unified ordering interface.

3.2 About the mini-program calling WeChat payment The applet calling WeChat payment

in the above process uses the applet WeChat payment interface wx.requestPayment. For a detailed description of the interface, you can view the WeChat payment API of the applet.

The package and timeStamp parameters in this interface are returned from the developer's third-party server, and the package is obtained by the third-party server from the unified order interface reply.

Other parameters in the interface, appId, noceStr, signType and paySign are stored or calculated by the applet.

Among them, paySign is the signature, and the signature algorithm document is here:

https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3&t=20161107

The main process of the entire official account payment is basically in the first Implemented on the third-party server, developers need to be familiar with the official account payment document, understand the message interaction process and each interface.

Some essential functions of normal WeChat payment are not described here: exception handling, order inquiries, initiating refunds, downloading statements, etc.

quote
"H5 Program Club" is a WeChat public account that focuses on WeChat applet learning and communication, and the release of related outsourcing/recruitment needs information



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326400737&siteId=291194637