Home > Backend Development > PHP Tutorial > How to implement PHP website access to Alipay

How to implement PHP website access to Alipay

小云云
Release: 2023-03-22 12:22:01
Original
8109 people have browsed it

Some time ago, I developed a project to connect a PHP website to Alipay. Now I will sort out the process. Because the official website of Alipay provides many interfaces and documents, and it seems a bit cumbersome, so I will sort it out. This article mainly shares with you how to implement PHP website access to Alipay, hoping to help everyone.

 1. Alipay accounts must be reviewed by the enterprise before they can make payments in a formal environment. However, you can develop it even if you are not an enterprise, because Alipay provides a sandbox testing environment for you to test and develop.
 2. Alipay’s new development interface is different from the old one. In the past, as long as you had an account, you must now apply for an “application”. One account can apply for multiple applications, and one application can have multiple functions, such as “ "Computer website payment", "mobile website payment", etc.
 1. Overview of the development process
 1. Just read the official website documentation Ant Financial Open Platform
 2. Download the PHP SDK&demo
 3. Apply for an application or use sand Box environment
4. Generate application private key & application public key
5. Configure config.php
2. Specific operations
1. Enter the open platform
Baidu " Ant Financial Open Platform", now Alipay's development interfaces are all on this open platform! There are various documents here for you to search and study.

If you are using it for the first time, enter the "Document Center"-> "Development Documentation"


We choose the computer website here Payment:


As shown in the picture above, you can learn about the contents of the menu on the left one by one.

Download the sdk of php, click "SDK&Demo" on the left menu, and download the file corresponding to php. The demo after downloading cannot be used directly because the config.php file needs to be configured:


## 2. Apply for an application or use the sandbox environment

After logging in to the "Ant Financial Open Platform", click "Developer Center".
 (1) Apply for an application
After logging in, click "Developer Center"->"Create Application". For specific steps, please refer to the Alipay official website documentation: Computer Website Payment Quick Access

 (2) Use sandbox environment

 You are not an enterprise or individual industrial and commercial household, so you cannot apply for a formal "application" because you need to submit the company's information in step 2.1. So we just use a sandbox environment. Click "Sandbox Environment" -> "Sandbox Application" under "R&D Services" to configure the application public key.


Next, you need to generate a key pair and configure it on the Alipay platform. Alipay provides tools for generating private keys and public keys, which are easy to operate.

 (3) Generate key

Put the mouse on the icon of "RSA2 (SHA256) key (recommended)", and a prompt will appear: click the generation method, and you will enter the corresponding page, download tools, and generate public and private keys. Generate RSA key: https://docs.open.alipay.com/291/105971


  (4) Configure config.php

After generation :
Configure the application public key to the application public key corresponding to the RSA2 of the sandbox application;
Configure the application private key to the "merchant private key" of config.php;
Copy the APPID of the sandbox application to config In the appid of .php;
The "Alipay public key" of the sandbox environment is configured into the "Alipay public key" of config.php;
The "Alipay gateway" of config.php needs to be changed to the "Alipay gateway" of the sandbox application. Alipay Gateway”.

Congfig’s notify_url and return_url are mainly interfaces for processing your own business through the data returned by Alipay. You don’t need to configure it yet, because you can now successfully request Alipay’s payment interface.

2. After configuration, request Alipay 1. Modify config.php, app_id, merchant_private_key, notify_url, return_url, gatewayUrl, alipay_public_key

2 , Alipay official demo page:



# The payment interface must be passed through the product "sandbox wallet" provided by Alipay Scan to pay. The normal Alipay on our mobile phones cannot scan to pay, and only provides the Android version, as shown below. Then you can use the sandbox account provided by Alipay to test.


Related recommendations:

.net Detailed example of how to access Alipay’s payment interface

[PHP backend]Access Alipay
How to access Alipay function on the website

The above is the detailed content of How to implement PHP website access to Alipay. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.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