PHPackages                             cje/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. cje/wechat

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cje/wechat
==========

简单便捷的微信sdk

v1.0.3(1mo ago)07MITPHPPHP &gt;=7.2.0

Since May 4Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/753717010/wechat)[ Packagist](https://packagist.org/packages/cje/wechat)[ RSS](/packages/cje-wechat/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (5)Used By (0)

微信 SDK
======

[](#微信-sdk)

一个功能强大、易于使用的微信 SDK，支持微信公众号和小程序的开发。

功能特性
----

[](#功能特性)

- 支持微信公众号和小程序
- 访问令牌管理（普通版和稳定版）
- HTTP 请求处理
- 消息处理和解析
- 配置管理
- 缓存管理
- 依赖注入
- 事件系统
- 中间件系统
- 监控系统

安装
--

[](#安装)

使用 Composer 安装：

```
composer require cje/wechat
```

配置
--

[](#配置)

### 公众号配置

[](#公众号配置)

```
$config = [
    'appId' => 'your-app-id',
    'appSecret' => 'your-app-secret',
    'token' => 'your-token',
    'encodingAESKey' => 'your-encoding-aes-key' // 可选
];

$app = new \Cje\Wechat\officialAccount\Application($config);
```

### 小程序配置

[](#小程序配置)

```
$config = [
    'appId' => 'your-app-id',
    'appSecret' => 'your-app-secret'
];

$app = new \Cje\Wechat\miniApp\Application($config);
```

基本用法
----

[](#基本用法)

### 获取访问令牌

[](#获取访问令牌)

```
// 获取普通访问令牌
$accessToken = $app->getAccessToken();
echo $accessToken;

// 获取稳定版访问令牌（需要配置缓存）
$config['stable'] = true;
$app = new \Cje\Wechat\officialAccount\Application($config);
$accessToken = $app->getAccessToken();
echo $accessToken;
```

### 发送HTTP请求

[](#发送http请求)

```
// 创建请求对象
$request = new class extends \Cje\Wechat\bases\Request {
    public function getApi(): string {
        return 'cgi-bin/user/get';
    }
    public function getMethod(): string {
        return 'GET';
    }
    public function getNeedAccessToken(): bool {
        return true;
    }
    public function build(): array {
        return ['next_openid' => ''];
    }
};

// 执行请求
$response = $app->get($request);
print_r($response->getContent());
```

### 处理消息

[](#处理消息)

```
// 获取服务器实例
$server = $app->getServer();

// 设置消息处理器
$server->on('text', function ($message) {
    return "你发送的消息是：{$message->Content}";
});

// 处理消息
$response = $server->serve();
echo $response;
```

高级功能
----

[](#高级功能)

### 事件系统

[](#事件系统)

```
// 获取事件调度器
$dispatcher = $app->getEventDispatcher();

// 注册事件监听器
$dispatcher->listen('user.login', function ($event) {
    // 处理登录事件
    echo '用户登录了';
    print_r($event->getData());
});

// 触发事件
$event = new \Cje\Wechat\event\BaseEvent('user.login');
$event->setData(['user_id' => 123]);
$dispatcher->dispatch($event);
```

### 中间件系统

[](#中间件系统)

```
// 注册中间件
$app->get('middlewareManager')->add(function ($request, $next) {
    // 请求前处理
    echo '请求开始';

    // 执行下一个中间件
    $response = $next($request);

    // 响应后处理
    echo '请求结束';

    return $response;
});

// 执行带中间件的请求
$response = $app->handle($request, function ($request) {
    // 处理请求
    return $app->get($request);
});
```

示例
--

[](#示例)

查看 `demo.php` 文件获取更多示例代码。

贡献
--

[](#贡献)

欢迎贡献代码！请遵循以下步骤：

1. Fork 仓库
2. 创建一个新的分支
3. 提交你的更改
4. 发送 Pull Request

许可证
---

[](#许可证)

本项目使用 MIT 许可证。详见 LICENSE 文件。

联系方式
----

[](#联系方式)

如有问题，请通过以下方式联系：

- GitHub:
- Email:

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance94

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Total

4

Last Release

32d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8e2fa55e5680029e06f749779af67faa8a78cf94bb59e82879dbaf3415e1cdc4?d=identicon)[风哀伤](/maintainers/%E9%A3%8E%E5%93%80%E4%BC%A4)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k42](/packages/civicrm-civicrm-core)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[oat-sa/tao-core

TAO core extension

66143.7k121](/packages/oat-sa-tao-core)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)

PHPackages © 2026

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