Get the App
SLTechnology News&Howtos  ›  Development  › 

How to develop WeChat Mini Programs WeChat Pay's access function

Shulou Source: shulou.com Published: 2022-05-31 23:00:11 09月21日 Update

This article mainly introduces the relevant knowledge of "how to develop the access function of WeChat Mini Programs and WeChat Pay". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to develop the access function of WeChat Mini Programs and WeChat Pay" can help you solve the problem.

1. WeChat Pay's official document provides a sample of the PHP script WeChat Pay, which can be downloaded.

2. The sample has encapsulated each class, we just need to add a namespace, create a new directory wxpay under the extend directory of TP5, copy the classes in the sample to this directory, and then add a namespace

Results of sample modification

One of the most important classes is WxPayApi.php. After adding the namespace, the form is as follows, and the modifications of other classes are similar:

3. Introduce namespaces where needed, and new can be used with a single object. For example, a unified API for issuing orders:

Introduce the required classes first:

Encapsulate the external unified order issuing API, and directly return the parameters needed by Mini Program to call the payment API:

Similar to the repayment interface, it can be encapsulated through a unified order class.

II. Mini Program end integration

Mini Program is very simple. You only need to pass the data returned by the API to WeChat Pay's js interface.

The example returned by the API is as follows:

Examples of data returned by the integration API are as follows:

This is the end of the content about "how to develop the access function of WeChat Mini Programs and WeChat Pay". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Payment interface program space function development access directory knowledge encapsulation unification data industry small program sequence transformation integration different practical other classes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Redmi NVidia macOS