Home PHP Framework ThinkPHP How to use Alipay open platform in ThinkPHP6?

How to use Alipay open platform in ThinkPHP6?

Jun 12, 2023 am 08:11 AM
thinkphp Alipay open platform

With the popularity and development of e-commerce, safe and convenient online payment methods have become an indispensable service for consumers. As one of the largest online payment platforms in China, Alipay provides trust and convenience to hundreds of millions of users. For enterprises, it is also an indispensable choice for payment business. This article will introduce how to use the Alipay open platform under the ThinkPHP6 framework to facilitate enterprises to conduct payment services.

1. Preparation

Before using the Alipay open platform for development, corresponding developer registration and application creation are required. The specific steps are as follows:

1. Register as a developer

First, developers need to enter the Alipay Open Platform (https://open.alipay.com/platform/home.htm) and complete Register and get developer ID and KEY.

2. Create an application

Application creation needs to be done in the backend of the open platform. Select Create Application and fill in the basic information of the application.

After the creation is completed, APP ID, key and other related information will be generated.

2. Configure Alipay Open Platform SDK

Pay API is a common open interface of Alibaba Open Platform. Using Pay API for payment can greatly reduce the difficulty of development. Pay API provides out-of-the-box payment functionality, allowing users to quickly and easily develop complete payment processes.

1. Introduction of SDK

To develop the Alipay open platform in ThinkPHP6, you need to introduce the SDK first and add:

"require": {
"alipay/easysdk":"^2.1"
}
Copy after login

in composer.json and then execute composer install After installing the SDK, you can start Alipay-related development.

2. Configuration file

To configure in ThinkPHP6, you need to create a new configuration file config/easysdk.php, and then copy the following content into it:

<?php
return [
    'app_id' => '', //应用ID
    'notify_url' => '', //支付回调通知地址
    'return_url' => '', //支付结束后跳转地址
    'ali_public_key' => '', //支付宝公钥
    'private_key' => '', //应用私钥
    'log' => [ //日志配置
        'file' => './logs/easysdk.log',
        'level' => 'debug',
        'type' => 'daily', //按日志文件
    ],
    'http' => [ //API请求配置
        'timeout' => 5.0,
        'connect_timeout' => 5.0,
    ],
];
Copy after login

3. Initiate payment Request

After you have the preparations and configuration files, you can initiate a payment request in ThinkPHP6. The specific steps are as follows:

1. Write the controller

First, you need to create a new controller file AlipyController.php in the app/controller directory. Write the following content in the file:

<?php
namespace appcontroller;

use thinkApp;
use thinkhelperArr;
use thinkacadeConfig;
use alipayEasySDKKernelFactory;

class AlipayController
{
    public function pay()
    {
        //支付金额
        $totalAmount = 10.00;
        $pay = Factory::payment(Config::get('easysdk'));

        //构造支付请求参数
        $builder = $pay->common()->precreate(
            [
                'out_trade_no' => '20191120' . uniqid(),
                'total_amount' => $totalAmount,
                'subject' => '思音联合会 -- 支付测试',
            ]
        );

        //发起支付请求,获取响应
        $response = $builder->getResponse();
        $qrCode = Arr::get($response->bizContent, 'qr_code');

        //展示支付二维码
        echo "<img src='{$qrCode}'>";
    }
}
Copy after login

2. Make a request

Enter the route of the above controller in the browser to make a payment request. The page will display the payment QR code.

The above are the steps for payment development using Alipay open platform in ThinkPHP6. Using the Pay API for payment allows developers to focus more on business process development and reduce development time and costs. At the same time, the payment methods provided by Alipay are also very safe and convenient, providing convenience for enterprises.

The above is the detailed content of How to use Alipay open platform in ThinkPHP6?. 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 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)

How to withdraw money from Bitget Wallet to Alipay How to withdraw money from Bitget Wallet to Alipay Sep 04, 2024 pm 07:25 PM

The steps to withdraw money to Alipay using BitgetWallet are as follows: Open BitgetWallet and enter your password or use your fingerprint to unlock. Click Withdraw to select a cryptocurrency. Enter Alipay information and fill in the payment account number and amount. Select network Select the network that matches the Alipay payment method. Set Handling Fee Confirm the handling fee amount and accept it. Confirm and submit the inspection information and click Confirm. Waiting for confirmation awaits verification by the blockchain network. Fund withdrawals received will be credited to the Alipay payment account.

How to solve the problem of 'Undefined array key 'sign'' error when calling Alipay EasySDK using PHP? How to solve the problem of 'Undefined array key 'sign'' error when calling Alipay EasySDK using PHP? Mar 31, 2025 pm 11:51 PM

Problem Description When calling Alipay EasySDK using PHP, after filling in the parameters according to the official code, an error message was reported during operation: "Undefined...

List of handling fees for okx trading platform List of handling fees for okx trading platform Feb 15, 2025 pm 03:09 PM

The OKX trading platform offers a variety of rates, including transaction fees, withdrawal fees and financing fees. For spot transactions, transaction fees vary according to transaction volume and VIP level, and adopt the "market maker model", that is, the market charges a lower handling fee for each transaction. In addition, OKX also offers a variety of futures contracts, including currency standard contracts, USDT contracts and delivery contracts, and the fee structure of each contract is also different.

ThinkPHP6 routing: How to completely obtain URL parameters containing special characters such as Chinese? ThinkPHP6 routing: How to completely obtain URL parameters containing special characters such as Chinese? Apr 01, 2025 pm 02:51 PM

ThinkPHP6 routing parameters are processed in Chinese and complete acquisition. In the ThinkPHP6 framework, URL parameters containing special characters (such as Chinese and punctuation marks) are often processed...

How to solve the problem of cURL error 77 when connecting to Elasticsearch 8 using ThinkPHP6 and elasticsearch-php clients? How to solve the problem of cURL error 77 when connecting to Elasticsearch 8 using ThinkPHP6 and elasticsearch-php clients? Mar 31, 2025 pm 11:36 PM

Using the ThinkPHP6 framework combined with elasticsearch-php client to operate Elasticsearch...

Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Mar 04, 2025 pm 04:51 PM

Gate.io (Sesame Open Door) is the world's leading cryptocurrency trading platform. This article provides a complete tutorial on spot trading of Gate.io. The tutorial covers steps such as account registration and login, KYC certification, fiat currency and digital currency recharge, trading pair selection, limit/market transaction orders, and orders and transaction records viewing, helping you quickly get started on the Gate.io platform for cryptocurrency trading. Whether a beginner or a veteran, you can benefit from this tutorial and easily master the Gate.io trading skills.

Ouyi Exchange app domestic download tutorial Ouyi Exchange app domestic download tutorial Mar 21, 2025 pm 05:42 PM

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

See all articles