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

ActiveLibrary[API Development](/categories/api)

qiuxiang/wechat
===============

Wechat SDK

v0.2.0(11y ago)15211MITPHPPHP &gt;=5.3.0

Since May 14Pushed 11y ago1 watchersCompare

[ Source](https://github.com/qiuxiang/wechat)[ Packagist](https://packagist.org/packages/qiuxiang/wechat)[ Docs](http://github.com/qiuxiang/wechat)[ RSS](/packages/qiuxiang-wechat/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (3)Versions (7)Used By (1)

微信公众平台 SDK
==========

[](#微信公众平台-sdk)

微信公众平台消息接口的简洁封装，使用 composer 进行依赖管理。

简单使用
----

[](#简单使用)

```
$wechat = new Wechat('token');

if ($wechat->request->valid()) {
  $wechat->response->text('hello');
}
```

获取请求信息
------

[](#获取请求信息)

获取文本、图片等消息

```
echo $wechat->request->fromUserName; // 获取发送者 OpenID
echo $wechat->request->msgtype;      // 获取消息类型
echo $wechat->request->content;      // 获取文本消息内容
```

值得一提的是，`request` 属性是大小写无关的，这意味着 `request->FromUserName` 与 `request->fromusername` 是一样的。

回复文本消息
------

[](#回复文本消息)

```
$wechat->response->text('hello');
```

回复图文消息
------

[](#回复图文消息)

根据官方文档描述，`title`、`content`、`picture`、`url` 都是可选的。

### 单图文消息

[](#单图文消息)

```
$wechat->response->news(array(
  'title'   => '标题',
  'content' => '描述',
  'picture' => 'http://example.com/picture.png',
  'url'     => 'http://example.com',
));
```

### 多图文消息

[](#多图文消息)

```
$wechat->response->news(array(
  array(
    'title'   => '标题1',
    'picture' => 'http://example.com/picture.png',
    'url'     => 'http://example.com',
  ),
  array(
    'title'   => '标题2',
  ),
));
```

注意，在多图文消息中，尽管可以指定 `content`，但在实际中并不会显示。

单元测试
----

[](#单元测试)

这里还提供了一个方便测试微信后台功能的 `TestCase`

```
class WechatTest extends Wechat\TestCase {
  // 定义微信后台信息
  public $serverUrl = 'http://example.com';
  public $token = 'token';
  public $fromUserName = 'user'; // 用户 OpenID
  public $toUserName = 'server'; // 开发者微信号

  // 测试文本消息
  public function testText() {
    // 发送文本消息
    $result = $this->send('text', 'hello');

    // 对返回结果进行断言
    $this->assertEquals($this->toUserName, $result->ToUserName);
    $this->assertEquals($this->fromUserName, $result->FromUserName);
    $this->assertEquals('world', $result->Content);
    $this->assertEquals('text', $result->MsgType);
  }

  // 测试订阅事件
  public function testSubscribe() {
    // 发送订阅事件
    $result = $this->send('event', array('event' => 'subscribe'));
    // 断言应该返回 'welcome'
    $this->assertEquals('welcome', $result->Content);
  }
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

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

Total

6

Last Release

4350d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.4.0

v0.2.0PHP &gt;=5.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c0e77251b9d27accc068b3d985016ca58cc39a90710fb0a1ab34cac1f289a25d?d=identicon)[7c00](/maintainers/7c00)

---

Top Contributors

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

---

Tags

wechatweixin

### Embed Badge

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

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

###  Alternatives

[overtrue/laravel-wechat

微信 SDK for Laravel

3.0k1.8M53](/packages/overtrue-laravel-wechat)[thenbsp/wechat

微信公众平台第三方 SDK 开发包，优雅、健壮，可扩展，遵循 PSR 开发规范。

9408.2k](/packages/thenbsp-wechat)[naixiaoxin/think-wechat

EasyWechat For Thnkphp5.1+

27316.1k1](/packages/naixiaoxin-think-wechat)[gaoming13/wechat-php-sdk

微信公众平台php版开发包

3311.7k](/packages/gaoming13-wechat-php-sdk)

PHPackages © 2026

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