PHPackages                             hjy2588818/yii2-wxpay - 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. hjy2588818/yii2-wxpay

ActiveLibrary[Payment Processing](/categories/payments)

hjy2588818/yii2-wxpay
=====================

yii2 微信(weixin)即时到帐接口扩展组件

115PHP

Since May 12Pushed 9y ago1 watchersCompare

[ Source](https://github.com/hjy2588818/yii2-wxpay)[ Packagist](https://packagist.org/packages/hjy2588818/yii2-wxpay)[ RSS](/packages/hjy2588818-yii2-wxpay/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2微信扫码支付
==========

[](#yii2微信扫码支付)

适用于微信扫码支付接口`模式二`，具体使用方法如下：

安装
--

[](#安装)

待提交到[https://packagist.org，目前可用git拉取后自行配置。](https://packagist.org%EF%BC%8C%E7%9B%AE%E5%89%8D%E5%8F%AF%E7%94%A8git%E6%8B%89%E5%8F%96%E5%90%8E%E8%87%AA%E8%A1%8C%E9%85%8D%E7%BD%AE%E3%80%82)

配置使用
----

[](#配置使用)

### 一、配置Yii2组件

[](#一配置yii2组件)

在common下的全局配置文件main.php中添加组件配置，请参考如下alipay的配置：

```
'components' => [
        'wxpay' => [
            'class' => 'iqianfang\yii2wxpay\WxPay',
        ],
    ],
```

注意：一些固定配置/不常用配置放到组件类的init里了，有用到的可以去那里改。

### 二、微信支付配置

[](#二微信支付配置)

#### 1、去微信商户后台下载证书文件，并覆盖cert里的同名文件

[](#1去微信商户后台下载证书文件并覆盖cert里的同名文件)

#### 2、配置微信支付信息

[](#2配置微信支付信息)

在lib/WxPay.Config.php 中配置，具体详见该文件

### 三、逻辑处理

[](#三逻辑处理)

#### 1、支付请求提交

[](#1支付请求提交)

在需要发起支付请求的地方调用

```
Yii::$app->wxpay->submit($order);
```

其中order是你的订单实例，通过它可以获取到`订单号`、`支付总价`等，如果你的逻辑用不到或者与此不同，请自行修改

#### 2、支付结果通知

[](#2支付结果通知)

回调地址的配置在WxPay.php 的`getQrcode`方法中的`SetNotify_url`，具体请根据自己的实际情况配置。 根据设置的notify\_url编写控制器及action代码。以我的配置为例：

```
class PaymentController extends Controller
{
    /**
     * 关闭csrf，以便异步通知可访问
     * @param \yii\base\Action $action
     * @return bool
     * @author WangTao
     */
    public function beforeAction($action)
    {
        $this->enableCsrfValidation = false;
        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }

    /**
     * 响应微信支付异步通知
     * @author WangTao
     */
    public function actionWxpayNotify()
    {
        $data = Yii::$app->wxpay->checkSign();
        $result = Yii::$app->wxpay->getResult();
        if ($data['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
            $order = Order::find()->where(['sn'=>$result['out_trade_no']])->one();
            $order->order_status = 1;
            $order->save();
        }

        Yii::$app->wxpay->replyNotify();
    }
```

其他
--

[](#其他)

`submit`会返回一个二维码，该二维码即为扫码支付用的，具体的html代码在`getQrcode`中。如果你要调整二维码的大小，或者更换其他第三方生成二维码接口自行修改即可

别忘了配置urlManager，开启url美化，否则通知url会有参数，通知会失败

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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/2eca579acc7a56b941266aa3a7668622c83e4bb23440530c1d92d757185f4000?d=identicon)[hjy2588818](/maintainers/hjy2588818)

---

Top Contributors

[![hjy2588818](https://avatars.githubusercontent.com/u/12125515?v=4)](https://github.com/hjy2588818 "hjy2588818 (2 commits)")[![sdqianfang](https://avatars.githubusercontent.com/u/24370327?v=4)](https://github.com/sdqianfang "sdqianfang (2 commits)")

### Embed Badge

![Health badge](/badges/hjy2588818-yii2-wxpay/health.svg)

```
[![Health](https://phpackages.com/badges/hjy2588818-yii2-wxpay/health.svg)](https://phpackages.com/packages/hjy2588818-yii2-wxpay)
```

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[eduardokum/laravel-boleto

Biblioteca com boletos para o laravel

626351.9k2](/packages/eduardokum-laravel-boleto)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[omnipay/dummy

Dummy driver for the Omnipay payment processing library

271.2M33](/packages/omnipay-dummy)

PHPackages © 2026

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