Table of Contents
In the process of implementing e-commerce websites, we often involve the payment function. Currently, the more popular third-party payments are Alipay and WeChat. The so-called third-party payments are those that have signed contracts with major banks and have A transaction support platform provided by a third-party independent institution with certain strength and credibility. In transactions through a third-party payment platform, after the buyer purchases the goods, he uses the account provided by the third-party platform to pay for the goods, and the third party notifies the seller of the arrival of the payment. This article takes Alipay access as a case.
1. Basic flow chart
2. Detailed step analysis:
3. Alipay interface access
Let’s show you the business logic process of instant payment:
Step 1: Buyer chooses the product of his choice
Step Two: Jump to the cashier page
Step 3: Buyer selects payment method
Step 4: Payment successful
Let’s show you the steps to access:
Step 1: Get the PID, the developer logs in to the open platform, click "Account and Key Management" in the upper right corner.
Query to the partner Identity (PID), a 16-digit pure number starting with 2088. " >Step 2: Select "Partner Key" to Query to the partner Identity (PID), a 16-digit pure number starting with 2088.
Step 3: Configure the secret key
Step 4: Access the project
Note: notify_url page can only return success, asynchronous notification There cannot be any HTML code on the page. Please refer to the asynchronous notification for payment results.
Home Backend Development PHP Tutorial Implementation of php online payment function (Alipay)

Implementation of php online payment function (Alipay)

Apr 04, 2017 pm 02:51 PM
php Alipay

In the process of implementing e-commerce websites, we often involve the payment function. Currently, the more popular third-party payments are Alipay and WeChat. The so-called third-party payments are those that have signed contracts with major banks and have A transaction support platform provided by a third-party independent institution with certain strength and credibility. In transactions through a third-party payment platform, after the buyer purchases the goods, he uses the account provided by the third-party platform to pay for the goods, and the third party notifies the seller of the arrival of the payment. This article takes Alipay access as a case.

1. Basic flow chart

Implementation of php online payment function (Alipay)

Payment process

2. Detailed step analysis:

( 1) The user initiates a request to confirm the order to the mall website (for example, click Buy Now)
(2) The mall website receives the request and saves the order data to the database or other storage media
(3) Returns to the order confirmation page, on the page The order amount and other information should be displayed (the order interface after clicking Buy Now)
(4) The user confirms the payment and initiates a payment request. Note: The payment request is sent to the payment gateway (such as Alipay, online banking) rather than to the mall website.
(5) Display the payment page (this interface is the same interface as Alipay)
(6) The user fills in the authentication information and submits it (scanning the QR code is relatively convenient)
(7) There are two steps here. One is After the deduction is successful, the page jumps to the payment result page (displayed to the user), and the other is the payment notification. These two steps may be executed at the same time in no particular order. After receiving the payment notification, the mall website verifies according to Verification Rules Validity of the information, and make corresponding changes (for example: if valid, change the order to paid status , if invalid, change the order to unpaid status).

Take Alipay as an example: If you want to integrate Alipayinterface into your website, you must first have an Alipay account, then apply for online payment business with Alipay and sign an agreement. After the agreement comes into effect, Alipay will give the website a partner ID and a Security verification code. With these two things, you can develop the Alipay interface according to the Alipay interface document, as shown in the steps above. Only steps 4 and 7 have information exchange between the mall and the payment gateway. In step 4, it means sending the data to the payment gateway (Alipay). In step 7, it is the notification verification part. The verification gateway requests a certain address of the website. The website verifies the information according to the verification rules, records and responds. We are developing almost any payment When it comes to the interface, the focus is on the development of these two parts. If you understand the principles of the payment interface, it will not be difficult to develop the payment interface. It should be emphasized that if we want to test the entire process, then we need to have a merchant account (signing account), which means we need to submit a business license and other materials to Alipay. After passing the Alipay review, we can proceed The account number for payment. (This is rarely available to individuals. You can apply for one in the name of your company during development)

3. Alipay interface access

InterfaceIntroduction and testing
Alipay is currently Several interfaces are provided, such as guaranteed transactions, standard instant payment, and dual functions. There are only some differences in functions, but the website integration method is the same. Taking the standard instant account interface as an example, after signing an agreement with Alipay (that is, after becoming an official merchant), several steps are needed to complete the integration. For each function, Alipay's developer platform has listed detailed steps and case studies. For information on how to sign a contract, please visit Alipay Verification

Let’s show you the business logic process of instant payment:

Step 1: Buyer chooses the product of his choice

Implementation of php online payment function (Alipay)

Step One: Click Buy Now

Step Two: Jump to the cashier page

1. Users can open the mobile wallet and select “Scan Scan", aim at the screen to scan the QR code, wait until the mobile phone prompts for payment, select the payment tool and enter the password to pay;

Implementation of php online payment function (Alipay)

Scan the code


2. If you don’t want to use mobile payment, you can click “Login Account Payment” on the right side of the page as shown above, enter your Alipay account and password to log in.

Implementation of php online payment function (Alipay)

Login account payment

Step 3: Buyer selects payment method

Implementation of php online payment function (Alipay)

Select payment method

Step 4: Payment successful

Implementation of php online payment function (Alipay)

Payment successful

Let’s show you the steps to access:

Step 1: Get the PID, the developer logs in to the open platform, click "Account and Key Management" in the upper right corner.

Implementation of php online payment function (Alipay)

Get PID

Step 2: Select "Partner Key" to Query to the partner Identity (PID), a 16-digit pure number starting with 2088.

Implementation of php online payment function (Alipay)

Key

Step 3: Configure the secret key

Please refer to Alipay DSA, RSA, MD5 Three signature methods, it is recommended to use the official tool provided by Alipay, click here to go.

Step 4: Access the project

(1) Download the official file (demo) and click to download.
(2) Configure the developer information in DEMO, find the alipay.config.php file in the directory and open it, the content is as follows:

Implementation of php online payment function (Alipay)

Configuration code


(3) Find the following parameters in config file for corresponding configuration:

Implementation of php online payment function (Alipay)

Parameters

Implementation of php online payment function (Alipay)

Find this part


(4) If you choose the MD5 signature method, please Configure according to the MD5 method: See step 3
(5) for details. Connect with our php code. We can see that there is another file named alipayapi.php. , this file is used to accept order information, and the order parameters are passed to this file in the form of post. This file has referencedalipay.config.php, so everyone’s basic configuration must be correct. When the parameters are successfully accepted, , will jump to the payment interface pre-written by Alipay.

Implementation of php online payment function (Alipay)

alipayapi.php file


(6) Accept payment results: configure synchronous return (synchronous jump notification) and asynchronous Callback (asynchronous notification). There are two parameters return_url and notification_url in the configuration file, which can be configured to the return_url page and notify_url page in DEMO respectively. Synchronous returns are obtained using the GET method, and asynchronous notifications are obtained using the POST method. There is a 1-minute timeout for synchronous return verification, and there is no time limit for asynchronous notification verification. Both the return_url page and the notify_url page will verify the data using the AlipayNotify.verify() signature verification method.
(7) Final judgment: judge by the trade_status field (transaction status) in the return parameter and write the execution business logic code.

Implementation of php online payment function (Alipay)

Screenshot 2016-12-15 16.30.28.png

Note: notify_url page can only return success, asynchronous notification There cannot be any HTML code on the page. Please refer to the asynchronous notification for payment results.

The above is the detailed content of Implementation of php online payment function (Alipay). For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

See all articles