PHPackages                             lonestonewy/omnipay-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. [Payment Processing](/categories/payments)
4. /
5. lonestonewy/omnipay-alipay

ActiveLibrary[Payment Processing](/categories/payments)

lonestonewy/omnipay-alipay
==========================

增加了批量付款到支付宝账户和即时到帐批量退款接口的Omnipay支付宝接口

v2.0.0(9y ago)5931MITPHP

Since Jun 23Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (12)Used By (0)

Omnipay: Alipay
===============

[](#omnipay-alipay)

**增加了批量付款到支付宝账户和即时到帐批量退款接口**

[![Build Status](https://camo.githubusercontent.com/49ef54b95da70f59f3250ea67ab095edaff2c5e6d58451b9fb762dcfa4476bf5/68747470733a2f2f7472617669732d63692e6f72672f6c6f6b69656c73652f6f6d6e697061792d616c697061792e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/lokielse/omnipay-alipay)[![Latest Stable Version](https://camo.githubusercontent.com/df3db6af8d6d535dea5b5e92cb55b022c18c6a1b5ba8539691a8b14ff5f8fcbe/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6b69656c73652f6f6d6e697061792d616c697061792f76657273696f6e2e706e67)](https://packagist.org/packages/lokielse/omnipay-alipay)[![Total Downloads](https://camo.githubusercontent.com/c4fa1f26afd3d9de52d504491f4e981bcc3efe445db8349c5ac850c38041c42b/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6b69656c73652f6f6d6e697061792d616c697061792f642f746f74616c2e706e67)](https://packagist.org/packages/lokielse/omnipay-alipay)

[Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Alipay support for Omnipay.

> Cross-border Alipay payment please use [`lokielse/omnipay-global-alipay`](https://github.com/lokielse/omnipay-global-alipay)

Installation
------------

[](#installation)

Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it to your `composer.json` file:

```
{
    "require": {
        "lonestonewy/omnipay-alipay": "dev-master"
    }
}
```

And run composer to update your dependencies:

```
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

```

Basic Usage
-----------

[](#basic-usage)

The following gateways are provided by this package:

- Alipay\_Express (Alipay Express Checkout) 支付宝即时到账接口
- Alipay\_Secured (Alipay Secured Checkout) 支付宝担保交易接口
- Alipay\_Dual (Alipay Dual Function Checkout) 支付宝双功能交易接口
- Alipay\_WapExpress (Alipay Wap Express Checkout) 支付宝WAP客户端接口
- Alipay\_MobileExpress (Alipay Mobile Express Checkout) 支付宝无线支付接口
- Alipay\_Bank (Alipay Bank Checkout) 支付宝网银快捷接口

基于lokielse的工作，增加了以下接口

- Alipay\_BatchTrans (Alipay Express Checkout) 支付宝批量转账到支付宝账户接口
- Alipay\_RefundExpress (Alipay Express Checkout) 支付宝即时退款接口

Usage
-----

[](#usage)

### Purchase

[](#purchase)

```
$gateway = Omnipay::create('Alipay_Express');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here');
$gateway->setSellerEmail('merchant@example.com');
$gateway->setReturnUrl('http://www.example.com/return');
$gateway->setNotifyUrl('http://www.example.com/notify');

//For 'Alipay_MobileExpress', 'Alipay_WapExpress'
//$gateway->setPrivateKey('/such-as/private_key.pem');

$options = [
    'out_trade_no' => date('YmdHis') . mt_rand(1000,9999), //your site trade no, unique
    'subject'      => 'test', //order title
    'total_fee'    => '0.01', //order total fee
];

$response = $gateway->purchase($options)->send();

$response->getRedirectUrl();
$response->getRedirectData();

//For 'Alipay_MobileExpress'
//Use the order string with iOS or Android SDK
$response->getOrderString();
```

### Return/Notify

[](#returnnotify)

```
$gateway = Omnipay::create('Alipay_Express');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here');
$gateway->setSellerEmail('merchant@example.com');

//For 'Alipay_MobileExpress', 'Alipay_WapExpress'
//$gateway->setAlipayPublicKey('/such-as/alipay_public_key.pem');

$options = [
    'request_params'=> array_merge($_POST, $_GET), //Don't use $_REQUEST for may contain $_COOKIE
];

$response = $gateway->completePurchase($options)->send();

if ($response->isPaid()) {

   // Paid success, your statements go here.

   //For notify, response 'success' only please.
   //die('success');
} else {

   //For notify, response 'fail' only please.
   //die('fail');
}
```

### 批量付款到支付宝账户

[](#批量付款到支付宝账户)

```
$gateway    = Omnipay::create('Alipay_BatchTransGateway');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here');
$gateway->setSellerEmail('merchant@example.com');
$gateway->setNotifyUrl('http://www.example.com/notify');

$detail_data = '流水号1^收款方账号1^收款账号姓名1^付款金额1^备注说明1|流水号2^收款方账号2^收款账号姓名2^付款金额2^备注说明2......';

$params = [
    'email'=>'merchant@example.com',
    'account_name'=>'merchant.name',
    'detail_data'=>$detail_data,
    'batch_no'=>$batch_no,//批号
    'batch_num'=>$batch_num,//笔数
    'batch_fee'=>$batch_fee,//总金额
    'pay_date'=>$pay_date,//付款日期
];
$response = $gateway->purchase($params)->send();

$redirect_url = $response->getRedirectUrl();
```

### 即时退款接口

[](#即时退款接口)

该接口需要联系支付宝商服提前申请

```
$gateway    = Omnipay::create('Alipay_RefundExpressGateway');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here');
$gateway->setSellerEmail('merchant@example.com');
$gateway->setSignType('MD5');
$gateway->setInputCharset('UTF-8');
$gateway->setNotifyUrl('http://www.example.com/notify');

$data    = array(
    'refund_date' => date('Y-m-d H:i:s',time()),
    'batch_no'=>'1234567890',//退款编号
    'batch_num' => 1,//退款笔数
    'detail_data'=> mb_convert_encoding($this->alipay_trade_no.'^'.$amount.'^客户取消订单','GBK'),//退款数据，一次可以发起一批退款
);

$response = $gateway->refund($data)->send();
$debugData = $response->getData();

Yii::info('支付宝退款数据：'.print_r($debugData, true), 'payment');

if ($response->isSuccessful()) {
    //退款处理成功
}
```

上面的notify使用方法类似，具体可以参考支付宝文档，不再赘述。

For general usage instructions, please see the main [Omnipay](https://github.com/omnipay/omnipay)repository.

Related
-------

[](#related)

- [Omnipay-Alipay](https://github.com/lokielse/omnipay-alipay)
- [Laravel-Omnipay](https://github.com/ignited/laravel-omnipay)
- [Omnipay-GlobalAlipay](https://github.com/lokielse/omnipay-global-alipay)
- [Omnipay-WechatPay](https://github.com/lokielse/omnipay-wechatpay)
- [Omnipay-UnionPay](https://github.com/lokielse/omnipay-unionpay)

Support
-------

[](#support)

If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to.

If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/lokielse/omnipay-alipay/issues), or better yet, fork the library and submit a pull request.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 60.5% 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.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~90 days

Total

11

Last Release

3607d ago

Major Versions

v1.4.9 → v2.0.02016-08-16

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2070148?v=4)[Yong Wang](/maintainers/lonestonewy)[@lonestonewy](https://github.com/lonestonewy)

---

Top Contributors

[![amacneil](https://avatars.githubusercontent.com/u/637671?v=4)](https://github.com/amacneil "amacneil (207 commits)")[![lokielse](https://avatars.githubusercontent.com/u/1573211?v=4)](https://github.com/lokielse "lokielse (79 commits)")[![aderuwe](https://avatars.githubusercontent.com/u/1125184?v=4)](https://github.com/aderuwe "aderuwe (17 commits)")[![pilot](https://avatars.githubusercontent.com/u/28564?v=4)](https://github.com/pilot "pilot (11 commits)")[![TomasKit](https://avatars.githubusercontent.com/u/13846988?v=4)](https://github.com/TomasKit "TomasKit (3 commits)")[![winzou](https://avatars.githubusercontent.com/u/702928?v=4)](https://github.com/winzou "winzou (2 commits)")[![asaph](https://avatars.githubusercontent.com/u/760071?v=4)](https://github.com/asaph "asaph (2 commits)")[![johnkary](https://avatars.githubusercontent.com/u/135607?v=4)](https://github.com/johnkary "johnkary (2 commits)")[![michael2h4ng](https://avatars.githubusercontent.com/u/5486783?v=4)](https://github.com/michael2h4ng "michael2h4ng (2 commits)")[![rlerdorf](https://avatars.githubusercontent.com/u/54641?v=4)](https://github.com/rlerdorf "rlerdorf (2 commits)")[![steveneaston](https://avatars.githubusercontent.com/u/242405?v=4)](https://github.com/steveneaston "steveneaston (2 commits)")[![cfreear](https://avatars.githubusercontent.com/u/619726?v=4)](https://github.com/cfreear "cfreear (1 commits)")[![maclof](https://avatars.githubusercontent.com/u/4358583?v=4)](https://github.com/maclof "maclof (1 commits)")[![amsross](https://avatars.githubusercontent.com/u/450220?v=4)](https://github.com/amsross "amsross (1 commits)")[![michaeldoe](https://avatars.githubusercontent.com/u/1436773?v=4)](https://github.com/michaeldoe "michaeldoe (1 commits)")[![mtudor](https://avatars.githubusercontent.com/u/1683723?v=4)](https://github.com/mtudor "mtudor (1 commits)")[![nedmas](https://avatars.githubusercontent.com/u/842280?v=4)](https://github.com/nedmas "nedmas (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![brunogaspar](https://avatars.githubusercontent.com/u/2285372?v=4)](https://github.com/brunogaspar "brunogaspar (1 commits)")[![benjamindavid](https://avatars.githubusercontent.com/u/2911900?v=4)](https://github.com/benjamindavid "benjamindavid (1 commits)")

---

Tags

paymentgatewaypaymerchantomnipaypurchasealipay

### Embed Badge

![Health badge](/badges/lonestonewy-omnipay-alipay/health.svg)

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

###  Alternatives

[lokielse/omnipay-alipay

Alipay gateway for Omnipay payment processing library

586422.8k11](/packages/lokielse-omnipay-alipay)[lokielse/omnipay-global-alipay

Alipay global gateway for Omnipay payment processing library

3051.3k](/packages/lokielse-omnipay-global-alipay)

PHPackages © 2026

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