The WeChat payment capability in the mini program was launched with the release of the mini program. However, there is only one description of the requestPayment function for the WeChat payment interface in the mini program documentation.
This requestPayment function is indeed the only function that needs to be called on the front end of the mini program, but the successful access to WeChat Pay is actually far more than this one function. For developers who have not connected to WeChat Pay, they will feel confused and unable to get started.
This article explains how to access mini program payment from scratch, especially suitable for developers who have no experience in WeChat payment access.
After the mini program is authenticated, you can apply for WeChat payment in the WeChat payment menu bar in the mini program background.
Fill in the company information and public account, WeChat Pay will transfer a random amount to the public account, enter the amount to complete the verification, and sign the migration online, that is Completed the application process for WeChat Pay.
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 email address.
2.1 Configure the applet key
On the Mini Program background settings page, click Generate. After the administrator verifies the QR code, the AppSecret will be randomly generated. Please keep the Appsecret properly and do not store it in plain text on the server. 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 when applying for WeChat payment, log in to the merchant platform (pay.weixin.qq.com), and go to the account Center, API Security to download the certificate and set up the key.
The key is 32 bits and needs to be kept properly after setting, because the key cannot be viewed. All WeChat payment-related interfaces will be encrypted using this key.
2.3 Configure Https server
The front-end of the mini program is developed using the framework provided by WeChat, but the backend is still the developer's own server. The mini program initiates an https request, which means the mini program 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 free certificates to users.
Certificate installation instructions are available here:
https://www.qcloud.com/doc/product/400/4143
WeChat payment has a variety of payment methods, including card payment, official account payment, scan code payment, APP payment, here are all the interfaces of WeChat payment: https://pay.weixin .qq.com/wiki/doc/api/index.html
The mini program is used to activate payment in WeChat. It is actually a public account payment. Detailed documentation on public account payment can be viewed here: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_1
All Links related to official account payment can be found at this link. Developers first need to have a general understanding of these interfaces.
The main process of mini program public account payment is as follows (this figure only considers the normal process, for abnormal processes, please refer to the public account payment document):
3.1 About openid
The openid requested in the above process uses the interface in the latest API of the mini program. Developers can view the login interface of the mini program.
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 to activate WeChat payment
In the above process, the mini program to activate WeChat payment uses the mini program WeChat payment interface wx.requestPayment. For a detailed description of the interface, please view the WeChat Payment API of the mini program.
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.
where 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 entire main process of official account payment is basically implemented on a third-party server. Developers need to read the official account payment document thoroughly and understand the message interaction process and each interface.
Some functions that are essential for normal WeChat payment are not described here: exception handling, order query, refund initiation, statement download, etc.
The WeChat payment interface of JSSDK is a method of using JS to call up the payment of the official account in the official account. For details, please refer to the documentation of the official platform.
As you can see, the mini program is very similar to the WeChat payment of JSSDK. Here is a comparison of the differences between the two:
The above is JeffChen ( WeChat Official Account: Mobile Development Technology) Sharing about mini programs accessing WeChat payment, I hope it will be helpful to you.
For more articles related to how to enter payment from 0 in the WeChat applet, please pay attention to the PHP Chinese website!