How to connect the mini program to WeChat payment? (Introduction to development tutorial)

青灯夜游
Release: 2020-05-14 18:10:51
forward
3106 people have browsed it

How to connect the mini program to WeChat payment? (Introduction to development tutorial)

This article mainly talks about the pitfalls encountered in the development process of connecting WeChat applet to WeChat payment. It is divided into two parts, the applet end and the backend interface encapsulation.

1. Backend interface encapsulation

This article introduces interface encapsulation based on ThinkPHP5. The specific steps are as follows:

1. The official WeChat payment document provides PHP Download the sample of script WeChat payment;

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

How to connect the mini program to WeChat payment? (Introduction to development tutorial)

The most important class is WxPayApi.php, after adding the namespace The form is as follows, and the transformation of other classes is similar:

How to connect the mini program to WeChat payment? (Introduction to development tutorial)

3. Introduce the namespace where it needs to be used, and a new object can be used. For example, the unified order interface:

First introduce the required classes:

How to connect the mini program to WeChat payment? (Introduction to development tutorial)

Encapsulate the unified external ordering interface and directly return the parameters required by the mini program to call the payment interface:

How to connect the mini program to WeChat payment? (Introduction to development tutorial)

The repayment interface is similar and can be encapsulated through a unified order class.

2. Mini program integration

The mini program is very simple. You only need to pass the data returned by the interface to the js interface of WeChat payment

The examples returned by the interface are as follows:

How to connect the mini program to WeChat payment? (Introduction to development tutorial)

The examples of data returned by the integrated interface are as follows:

How to connect the mini program to WeChat payment? (Introduction to development tutorial)

3. Summary

1. The WeChat payment API of the official account jssdk used by the mini program WeChat payment API has a wrong parameter in the official document, that is, the "I" in the passed appid must be Capitalize, otherwise it will always prompt parameter error.

2. After calling the unified ordering interface, the results returned by the unified ordering cannot be directly returned to the mini program, and the signature needs to be regenerated.

Recommendation: " Mini Program Development Tutorial"

The above is the detailed content of How to connect the mini program to WeChat payment? (Introduction to development tutorial). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jisuapp.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template