PHPackages                             easyswoole/wechat - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. easyswoole/wechat

ActiveLibrary[Queues &amp; Workers](/categories/queues)

easyswoole/wechat
=================

Coroutine safety WeChat library

2.0.9(3y ago)8140.8k↑24.8%29[2 issues](https://github.com/easy-swoole/wechat/issues)4Apache-2.0PHPPHP &gt;=7.2

Since Jun 17Pushed 3y ago7 watchersCompare

[ Source](https://github.com/easy-swoole/wechat)[ Packagist](https://packagist.org/packages/easyswoole/wechat)[ Docs](https://www.easyswoole.com/)[ RSS](/packages/easyswoole-wechat/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (37)Used By (4)

easyswoole-wechat
=================

[](#easyswoole-wechat)

- 仿照 [easywechat](https://github.com/w7corp/easywechat) API实现的`协程安全`wechat库

说明
--

[](#说明)

- 首先感谢`easywechat`作者们创造的优秀项目，但由于在协程环境下使用会有潜在的跨协程问题，故有了此项目。 考虑到大多数用户的习惯，我们保留了绝大多数API的命名和风格习惯，以便用户更好的上手；但在部分可能存在潜在风险的地方， 我们则进行了重新设计，以保障协程环境下的运行安全。

依赖环境
----

[](#依赖环境)

- PHP &gt;= 7.1 (推荐使用 PHP &gt;= 7.2)
- [composer](https://getcomposer.org/)
- [swoole](https://github.com/swoole/swoole-src) 扩展 &gt;= 4.4.19 (推荐使用 Swoole &gt;= 4.4.23)
- openssl 扩展

安装
--

[](#安装)

```
$ composer require easyswoole/wechat 2.x --no-dev
```

基本使用
----

[](#基本使用)

以服务端为例

```
    $config = [
        'appId' => 'wxefe41fdeexxxxxx',
        'token' => 'dczmnau31ea9nzcnxxxxxxxxx',
        'aesKey' => 'easyswoole'
    ];

    $officialAccount = \EasySwoole\WeChat\Factory::officialAccount($config);

    $server = $officialAccount->server;

    /** 注册消息事件回调 */
    $server->push(function (\EasySwoole\WeChat\Kernel\Contracts\MessageInterface $message) {
        return new \EasySwoole\WeChat\Kernel\Messages\Text(implode(",", $message->transformForJsonRequest()));
    });

    /** @var \Psr\Http\Message\ServerRequestInterface $psr7Request  */
    $psr7Request = mockRequest();

    /**
    * @var \Psr\Http\Message\ResponseInterface $reply
    * forceValidate() 表示启用请求验证，以确保请求来自微信发送。默认不启用验证
    * serve() 会解析本次请求后回调之前注册的事件（包括AES解密和解析XML）
    * server() 接受一个显式实现了 \Psr\Http\Message\ServerRequestInterface 的request对象
    */
    $reply = $server->forceValidate()->serve($psr7Request);

    /**
    * $reply 是一个显式实现了PSR-7的对象，用户只需要处理该对象即可正确响应给微信
    * 下面是一个原生swoole的响应方法
    */
    $swooleResponse->status($reply->getStatusCode());

    /**
     * PSR-7 的Header并不是单纯的k => v 结构
     */
    foreach ($reply->getHeaders() as $name => $values) {
        $swooleResponse->header($name, implode(", ", $values));
    }

    $swooleResponse->write($reply->getBody()->__toString());
```

以客户端为例

```
    $config = [
        'appId' => 'wxefe41fdeexxxxxx',
        'token' => 'dczmnau31ea9nzcnxxxxxxxxx',
        'aesKey' => 'easyswoole'
    ];

    $officialAccount = \EasySwoole\WeChat\Factory::officialAccount($config);

    /** 获取用户列表 */
    $list = $officialAccount->user->list();
```

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

36

Last Release

1323d ago

Major Versions

1.2.4 → v2.0.0-alpha2021-03-23

1.2.x-dev → 2.0.12021-09-24

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

v2.0.0-alphaPHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/45c234d5f129ea570e630425636299127647534f0c2cbb073555e2c45d403d6f?d=identicon)[kiss291323003](/maintainers/kiss291323003)

---

Top Contributors

[![Player626](https://avatars.githubusercontent.com/u/44792981?v=4)](https://github.com/Player626 "Player626 (108 commits)")[![RunsTp](https://avatars.githubusercontent.com/u/28254581?v=4)](https://github.com/RunsTp "RunsTp (75 commits)")[![XueSiLf](https://avatars.githubusercontent.com/u/31389659?v=4)](https://github.com/XueSiLf "XueSiLf (31 commits)")[![kiss291323003](https://avatars.githubusercontent.com/u/24490609?v=4)](https://github.com/kiss291323003 "kiss291323003 (12 commits)")[![liuzeyi](https://avatars.githubusercontent.com/u/18137528?v=4)](https://github.com/liuzeyi "liuzeyi (4 commits)")[![LinkedDestiny](https://avatars.githubusercontent.com/u/5689061?v=4)](https://github.com/LinkedDestiny "LinkedDestiny (1 commits)")[![kyour-cn](https://avatars.githubusercontent.com/u/38110013?v=4)](https://github.com/kyour-cn "kyour-cn (1 commits)")[![ysongyang](https://avatars.githubusercontent.com/u/19664630?v=4)](https://github.com/ysongyang "ysongyang (1 commits)")

---

Tags

asyncswoolewechateasyswoole

### Embed Badge

![Health badge](/badges/easyswoole-wechat/health.svg)

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

###  Alternatives

[easyswoole/easyswoole

An efficient swoole framework

4.8k186.9k50](/packages/easyswoole-easyswoole)[easyswoole/rpc

An efficient swoole framework

7731.6k2](/packages/easyswoole-rpc)[easyswoole/compiler

easyswoole component

691.1k](/packages/easyswoole-compiler)

PHPackages © 2026

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