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
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
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;
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.
Login account payment
Step 3: Buyer selects payment method
Select payment method
Step 4: Payment successful
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.
Get PID
Step 2: Select "Partner Key" to Query to the partner Identity (PID), a 16-digit pure number starting with 2088.
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:
Configuration code
(3) Find the following parameters in config file for corresponding configuration:
Parameters
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.
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.
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!

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

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 originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool