Home  >  Article  >  WeChat Applet  >  WeChat mini program WeChat payment access development

WeChat mini program WeChat payment access development

Y2J
Y2JOriginal
2017-04-24 14:24:272468browse

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. The main contents of this article are as follows:

1. Backend interface encapsulation;

2. Mini program integration;

3. Summary of pitfalls.

1. Backend interface encapsulation

Based on ThinkPHP 5 for interface encapsulation, the specific steps are as follows:

1. The official WeChat payment document provides an example of PHP script WeChat payment. Download it;

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 copy the classes in the sample to This directory, and then add the namespace;

WeChat mini program WeChat payment access development

Sample transformation results

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

WeChat mini program WeChat payment access development

#3. Introduce the namespace where it needs to be used, and use new as an object, and place an order uniformly Interface example:

First introduce the required classes:

WeChat mini program WeChat payment access development

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

WeChat mini program WeChat payment access development

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.

Sample returned by the interface For example:

WeChat mini program WeChat payment access development

The data returned by the integrated interface is as follows:

WeChat mini program WeChat payment access development

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 capitalized, otherwise it will always prompt for parameter errors. I have been debugging this for a long time. I hope friends who see it will pay attention.

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.

3. If you have any questions, please leave a message to discuss.

The above is the detailed content of WeChat mini program WeChat payment access development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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