With the launch of the mini program, WeChat has also opened up the payment function of the mini program, and the mini program documentation only has a description of the requestPayment function for the WeChat payment interface. The requestPayment function is indeed the only function that needs to be called on the front end of the WeChat applet. However, there is far more than one function to enable the applet to access WeChat payment. For developers who have not connected to WeChat payment, they will find it difficult to start.
To access the payment function in the mini program, you must first apply for WeChat payment. After the mini program is authenticated, you can apply for WeChat payment in the background of the mini program and the WeChat payment menu bar.
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, sign the migration online, and WeChat is completed Payment application process.
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. Configure the mini program key, click Generate on the mini program background settings page, and 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.
Set the key and download the certificate. Use the username and password obtained when applying for WeChat payment. Log in to the merchant platform and download the certificate and set the key in the Account Center and API Security. 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. Configure the 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 that the mini program developer must configure an https server. Before configuring an 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. WeChat Pay has a variety of payment methods, including card payment, official account payment, scan code payment, and APP payment. The mini program is used to activate payment in WeChat, but it is actually a public account payment. Developers first need to have a general understanding of these interfaces.
About openid
In the above process, openid is requested using 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.
The mini program calls up WeChat payment
The mini program in the above process calls up WeChat payment, and uses the mini program WeChat payment interface wx.requestPayment. The interface's For a detailed description, 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.
The other parameters in the interface, appId, noceStr, signType and paySign are stored or calculated by the applet, where paySign is the signature. The entire main process of official account payment is basically implemented on a third-party server. Developers need to read the official account payment documents 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.
Whether it is the payment function or the birth of mini programs, WeChat is convenient and changing people's lives in its own way. Nowadays, various small programs can be seen everywhere around us, recorded in users’ WeChat lists, and many of them are practical tool-like small programs that can realize transactions.
Recommendation: " Mini Program Development Tutorial"
The above is the detailed content of Introduction to methods of developing mini programs to access WeChat payment functions. For more information, please follow other related articles on the PHP Chinese website!