PHPackages                             lhq5189/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. lhq5189/alipay

ActiveYii2-extension[Payment Processing](/categories/payments)

lhq5189/alipay
==============

alipay for Yii2

1.0.1(9y ago)02BSD-3-ClausePHP

Since Dec 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/lhq5189/alipay)[ Packagist](https://packagist.org/packages/lhq5189/alipay)[ RSS](/packages/lhq5189-alipay/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Yii2-Alipay

支付宝即时到账的Yii2扩展包！ 在liulipeng 的批量付款上改动而来

Install With Composer

The preferred way to install this extension is through composer.

Either run

php composer.phar require lhq5189/alipay "\*" or for the dev-master

php composer.phar require lhq5189/alipay "dev" Or, you may add

"lhq5189/alipay": "\*" to the require section of your composer.json file and execute php composer.phar update.

Usage

Once the extension is installed, simply modify your application configuration as follows:

return \[ 'alipayPartner' =&gt; '2088000000000000', 'alipaySellerEmail' =&gt; '', 'alipayKey' =&gt; 'j8gdfgdgrshhrthgdgsgtrhrdgdfg', \];

AlipayController

这是即时到账例子，支付宝其它接口换成相应的接口即可使用

namespace frontend\\controllers;

use app\\models\\Test\_pay; use yii\\log\\Logger; use app\\models\\Test2; use lhq5189\\alipay\\AlipayNotify; use yii\\web\\Controller; use lhq5189\\alipay\\AlipayConfig; use lhq5189\\alipay\\AlipaySubmit; use Yii;

class Pay2Controller extends Controller { public $layout='main'; public function beforeAction($action) { if ('notify' == $action-&gt;id || 'index' == $action-&gt;id) { $this-&gt;enableCsrfValidation = false; } return parent::beforeAction($action); } public function actionIndex() { $data = Yii::$app-&gt;request-&gt;post(); $body = $data\['name'\]; $total\_fee = $data\['price'\]; $out\_trade\_no = $data\['id'\]; /**请求参数**/

```
    //服务器异步、同步通知页面路径
   $notify_url = Yii::$app->urlManager->createAbsoluteUrl(['pay2/notify']);
    $return_url = Yii::$app->urlManager->createAbsoluteUrl(['pay2/return']);
    //需http://格式的完整路径，不允许加?id=123这类自定义参数，yii2默认的路由方面无法接收到异步通知，要 改为www.com/xxx/xxx/形式访问才可以

    $alipayConfig = (new AlipayConfig())->getAlipayConfig();

    //构造要请求的参数数组，无需改动
    $parameter = array(
        "service" => "create_direct_pay_by_user",
        "partner" => trim($alipayConfig['partner']),
        "notify_url"    => $notify_url,
        "return_url" =>$return_url,
        'body'=>$body,
        'out_trade_no'=>$out_trade_no,
        'subject'=>$body,
        'payment_type'=>1,
        'show_url'=>'http://www.xxxxx.com',
        'total_fee'=>$total_fee,
        'seller_id'=>trim($alipayConfig['partner']),
        "_input_charset"    => trim(strtolower($alipayConfig['input_charset']))
    );

    //建立请求
    $alipaySubmit = new AlipaySubmit($alipayConfig);
    $html_text = $alipaySubmit->buildRequestForm($parameter,"get", "正在跳转到支付页面");
    return $html_text;
}

public function actionNotify()
{
    $alipayConfig = (new AlipayConfig())->getAlipayConfig();

    Yii::getLogger()->log("alipay Notify Start", Logger::LEVEL_ERROR);

    Yii::getLogger()->log("↓↓↓↓↓↓↓↓↓↓alipayConfig↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓", Logger::LEVEL_ERROR);
    Yii::getLogger()->log(print_r($alipayConfig, true), Logger::LEVEL_ERROR);

    $notify = new AlipayNotify($alipayConfig);
    if ($notify->verifyNotify()) {
        $trade_no = Yii::$app->request->post('trade_no');
        $orderid = Yii::$app->request->post('out_trade_no');
        $subject = Yii::$app->request->post('subject');
        $trade_status = Yii::$app->request->post('trade_status');
        $total_fee = Yii::$app->request->post('total_fee');
        $buyer_email = Yii::$app->request->post('buyer_email');
        /**********************************************************************
         * 以下为支付成功后自己的操作，可以根据具体情况写

        $model = new Test2();
        $model->title = $orderid;
        $model->name = $trade_no.'-'.$orderid.'-'.$subject.'-'.$trade_status.'-'.$total_fee.'-'.time().'-'.$buyer_email;
        $model->time = time();
        $model->save();
        $modelcf = Test_pay::findOne($orderid);
        $modelcf->is_pay =1;
        $modelcf->username =$buyer_email;
        $modelcf->save();
         **********************************************************************************/

```

// Yii::getLogger()-&gt;log('verify Notify success', Logger::LEVEL\_ERROR); return "success"; } else { Yii::getLogger()-&gt;log('verify Notify failed', Logger::LEVEL\_ERROR); return "fail"; } }

```
public function actionReturn(){
    $alipayConfig = (new AlipayConfig())->getAlipayConfig();
    $notify = new AlipayNotify($alipayConfig);
    $notify->verifyNotify();
    $data = Yii::$app->request->get();
    if($data){
        $this->redirect('/testpay/list');   //支付成功后跳转地址

    }else{
        echo '支付失败';
    }
}

```

}

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

3489d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6381967?v=4)[haiquan liu](/maintainers/lhq5189)[@lhq5189](https://github.com/lhq5189)

---

Top Contributors

[![lhq5189](https://avatars.githubusercontent.com/u/6381967?v=4)](https://github.com/lhq5189 "lhq5189 (4 commits)")

---

Tags

yii2alipay

### Embed Badge

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

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[guanguans/yii-pay

适配于 Yii 的 alipay 和 wechat 的支付扩展包

515.8k](/packages/guanguans-yii-pay)

PHPackages © 2026

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