PHPackages                             abcsun/laravel-alipay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. abcsun/laravel-alipay

ActiveLibrary

abcsun/laravel-alipay
=====================

支付宝SDK在Laravel5封装包。

336PHP

Since Jul 18Pushed 9y ago1 watchersCompare

[ Source](https://github.com/abcsun/Alipay)[ Packagist](https://packagist.org/packages/abcsun/laravel-alipay)[ RSS](/packages/abcsun-laravel-alipay/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Alipay
======

[](#alipay)

支付宝SDK在Laravel5封装包。

该拓展包想要达到在Laravel5框架下，便捷使用支付宝的目的。

\##说明

- 来源于[https://github.com/Latrell/Alipay工程](https://github.com/Latrell/Alipay%E5%B7%A5%E7%A8%8B)
- 增加Lumen的服务提供者
- 增加网银支付接口

安装
--

[](#安装)

```
composer require latrell/alipay dev-master

```

更新你的依赖包 `composer update` 或者全新安装 `composer install`。

使用
--

[](#使用)

要使用支付宝SDK服务提供者，你必须自己注册服务提供者到Laravel服务提供者列表中。 基本上有两种方法可以做到这一点。

找到 `config/app.php` 配置文件中，key为 `providers` 的数组，在数组中添加服务提供者。

```
    'providers' => [
        // ...
        'Latrell\Alipay\AlipayServiceProvider',
    ]
```

运行 `php artisan vendor:publish` 命令，发布配置文件到你的项目中。

配置文件 `config/latrell-alipay.php` 为公共配置信息文件， `config/latrell-alipay-web.php` 为Web版支付宝SDK配置， `config/latrell-alipay-mobile.php` 为手机端支付宝SDK配置。

\####Lumen注册alipay服务

Lumen使用AlipayLumenServiceProvider，修改bootstrap/app.php如下

```
$app->register(Latrell\Alipay\AlipayLumenServiceProvider::class);               //alipay
$app->configure('latrell-alipay');      //config file
$app->configure('latrell-alipay-web');      //config file
$app->configure('latrell-alipay-mobile');      //config file
```

例子
--

[](#例子)

### 支付申请

[](#支付申请)

#### 网页即时到帐支付方式

[](#网页即时到帐支付方式)

```
	// 创建支付单。
	$alipay = app('alipay.web');
	$alipay->setOutTradeNo('order_id');
	$alipay->setTotalFee('order_price');
	$alipay->setSubject('goods_name');
	$alipay->setBody('goods_description');

	$alipay->setQrPayMode('4'); //该设置为可选，添加该参数设置，支持二维码支付。

	// 跳转到支付页面。
	return redirect()->to($alipay->getPayLink());
```

#### 网页即时到帐支付方式

[](#网页即时到帐支付方式-1)

```
	// 创建支付单。
	$alipay = app('alipay.web');
	$alipay->setOutTradeNo('order_id');
	$alipay->setTotalFee('order_price');
	$alipay->setSubject('goods_name');
	$alipay->setBody('goods_description');

	$alipay->setDefaultBank('ABCBTB');  //农行简码

	// 跳转到支付页面。
	return redirect()->to($alipay->getBankPayLink());
```

#### 手机端

[](#手机端)

```
	// 创建支付单。
	$alipay = app('alipay.mobile');
	$alipay->setOutTradeNo('order_id');
	$alipay->setTotalFee('order_price');
	$alipay->setSubject('goods_name');
	$alipay->setBody('goods_description');

	// 返回签名后的支付参数给支付宝移动端的SDK。
	return $alipay->getPayPara();
```

### 结果通知

[](#结果通知)

#### 网页

[](#网页)

```
	/**
	 * 异步通知
	 */
	public function webNotify()
	{
		// 验证请求。
		if (! app('alipay.web')->verify()) {
			Log::notice('Alipay notify post data verification fail.', [
				'data' => Request::instance()->getContent()
			]);
			return 'fail';
		}

		// 判断通知类型。
		switch (Input::get('trade_status')) {
			case 'TRADE_SUCCESS':
			case 'TRADE_FINISHED':
				// TODO: 支付成功，取得订单号进行其它相关操作。
				Log::debug('Alipay notify post data verification success.', [
					'out_trade_no' => Input::get('out_trade_no'),
					'trade_no' => Input::get('trade_no')
				]);
				break;
		}

		return 'success';
	}

	/**
	 * 同步通知
	 */
	public function webReturn()
	{
		// 验证请求。
		if (! app('alipay.web')->verify()) {
			Log::notice('Alipay return query data verification fail.', [
				'data' => Request::getQueryString()
			]);
			return view('alipay.fail');
		}

		// 判断通知类型。
		switch (Input::get('trade_status')) {
			case 'TRADE_SUCCESS':
			case 'TRADE_FINISHED':
				// TODO: 支付成功，取得订单号进行其它相关操作。
				Log::debug('Alipay notify get data verification success.', [
					'out_trade_no' => Input::get('out_trade_no'),
					'trade_no' => Input::get('trade_no')
				]);
				break;
		}

		return view('alipay.success');
	}
```

#### 手机端

[](#手机端-1)

```
	/**
	 * 支付宝异步通知
	 */
	public function alipayNotify()
	{
		// 验证请求。
		if (! app('alipay.mobile')->verify()) {
			Log::notice('Alipay notify post data verification fail.', [
				'data' => Request::instance()->getContent()
			]);
			return 'fail';
		}

		// 判断通知类型。
		switch (Input::get('trade_status')) {
			case 'TRADE_SUCCESS':
			case 'TRADE_FINISHED':
				// TODO: 支付成功，取得订单号进行其它相关操作。
				Log::debug('Alipay notify get data verification success.', [
					'out_trade_no' => Input::get('out_trade_no'),
					'trade_no' => Input::get('trade_no')
				]);
				break;
		}

		return 'success';
	}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 68.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/41250730b73e5a266aa51d26064c9923ce114705be20ff10c4797358af45fc67?d=identicon)[abcsun](/maintainers/abcsun)

---

Top Contributors

[![latrell](https://avatars.githubusercontent.com/u/6267962?v=4)](https://github.com/latrell "latrell (11 commits)")[![abcsun](https://avatars.githubusercontent.com/u/1784061?v=4)](https://github.com/abcsun "abcsun (4 commits)")[![daids](https://avatars.githubusercontent.com/u/1639998?v=4)](https://github.com/daids "daids (1 commits)")

### Embed Badge

![Health badge](/badges/abcsun-laravel-alipay/health.svg)

```
[![Health](https://phpackages.com/badges/abcsun-laravel-alipay/health.svg)](https://phpackages.com/packages/abcsun-laravel-alipay)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
