PHPackages                             blackhive/yii2-easywechat - 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. [API Development](/categories/api)
4. /
5. blackhive/yii2-easywechat

ActiveYii2-extension[API Development](/categories/api)

blackhive/yii2-easywechat
=========================

easywechat 4 for yii2

0.1.6(4y ago)61101MITPHP

Since Apr 10Pushed 4y ago1 watchersCompare

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

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

yii2-easywechat
===============

[](#yii2-easywechat)

[![Latest Stable Version](https://camo.githubusercontent.com/0877d4133425ebbb6a216ef168fc06463646dd711d7a979043f21e848e1806d9/68747470733a2f2f706f7365722e707567782e6f72672f626c61636b686976652f796969322d656173797765636861742f762f737461626c65)](https://packagist.org/packages/blackhive/yii2-easywechat)[![Total Downloads](https://camo.githubusercontent.com/0c5d103f505d0665e49d8ae0d98c80f3df16ca3ae29ed5060a97dfaebdabc1ed/68747470733a2f2f706f7365722e707567782e6f72672f626c61636b686976652f796969322d656173797765636861742f646f776e6c6f616473)](https://packagist.org/packages/blackhive/yii2-easywechat)[![Latest Unstable Version](https://camo.githubusercontent.com/c360252a0f1bf494e8cef4957e157926a5a28b23e5bfaea96d1bc960678342c3/68747470733a2f2f706f7365722e707567782e6f72672f626c61636b686976652f796969322d656173797765636861742f762f756e737461626c65)](https://packagist.org/packages/blackhive/yii2-easywechat)[![License](https://camo.githubusercontent.com/2f81664d4ea68e77535d082752c10d1faf025f4cf92ccf6482482724f5e6e1ce/68747470733a2f2f706f7365722e707567782e6f72672f626c61636b686976652f796969322d656173797765636861742f6c6963656e7365)](https://packagist.org/packages/blackhive/yii2-easywechat)

easywechat 4 for yii2

基于 [overtrue/wechat](https://github.com/overtrue/wechat)

友情提示，微信支付的沙箱不要用，它和支付宝的沙箱不是一个东西。。。

安装
--

[](#安装)

```
composer require --prefer-dist blackhive/yii2-easywechat -vvv
```

配置
--

[](#配置)

在 `config/main.php` 添加应用组件:

```
'components' => [
	// ...
	'wechat' => [
		'class' => 'blackhive\easywechat\Wechat',
		//'openidName' => 'wx.openid',
	],
]
```

在 `config/params_local.php` 中添加配置参数：

```
[
    'wechat' => [
        // 微信商户平台
        'pay' => [
            'app_id' => '',
            'mch_id' => '',
            'key' => '',
            'cert_path' => dirname(__FILE__) . '/path/to/apiclient_cert.pem', // 绝对路径！！！！
            'key_path' => dirname(__FILE__) . '/path/to/apiclient_key.pem',  // 绝对路径！！！！
            'notify_url' => '',
        ],
        // 微信公众平台
        'mp' => [
            'app_id' => '',
            'secret' => '',
            'oauth' => [
                'scopes'   => ['snsapi_base'],
                'callback' => '/wechat/oauth-callback',
            ],
        ],
        // 微信开放平台
        'open' => [
            'app_id'   => '',
            'secret'   => '',
            'token'    => '',
            'aes_key'  => ''
        ]
]
```

使用
--

[](#使用)

```
// 微信支付客户端
$payment = Yii::$app->wechat->payment;

// 微信公众号客户端
$officialAccount = Yii::$app->wechat->officialAccount;

// 微信公众平台客户端
$openPlatform = Yii::$app->wechat->openPlatform;

// 是否在微信客户端内
if (Yii::$app->wechat->isWechat()){
    // 微信内的操作
}

Yii::$app->wechat->openid = 'jfdjdjfjdaj';

// 从 session 中获取 openid
Yii::$app->wechat->openid;

// 微信网页授权:
if (Yii::$app->wechat->inWechat && !Yii::$app->wechat->openid) {// 从 session 中获取 openid
    Yii::$app->wechat->returnUrl = ['user/order', 'id' => 1];
    return Yii::$app->wechat->officialAccount->oauth->redirect()->send();
}

// 网页授权回调控制器 /wechat/oauth-callback
$oauth  = Yii::$app->wechat->officialAccount->oauth;
Yii::$app->wechat->openid = $oauth->user()->getId();// 向 session 中保存 openid
return $this->redirect(Yii::$app->wechat->returnUrl);
```

具体使用请参考 [EasyWeChat文档](https://www.easywechat.com/4.x/overview.html)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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 ~427 days

Total

4

Last Release

1673d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/02e8246bd86b3f16b57f8cf3cfbb2341d7880edd36f2d348af2d3ceeed4c48b8?d=identicon)[haobing](/maintainers/haobing)

---

Top Contributors

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

---

Tags

yii2wechateasywechat

### Embed Badge

![Health badge](/badges/blackhive-yii2-easywechat/health.svg)

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

###  Alternatives

[jianyan74/yii2-easy-wechat

WeChat SDK for yii2, 基于 overtrue/easywechat

14339.4k1](/packages/jianyan74-yii2-easy-wechat)[naixiaoxin/think-wechat

EasyWechat For Thnkphp5.1+

27316.1k1](/packages/naixiaoxin-think-wechat)

PHPackages © 2026

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