PHPackages                             workwexin/wecom - 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. workwexin/wecom

ActiveLibrary[API Development](/categories/api)

workwexin/wecom
===============

WeCom (Enterprise WeChat) PHP SDK for message and contacts

30PHP

Since May 26Pushed 1mo agoCompare

[ Source](https://github.com/cping6/work_wexin)[ Packagist](https://packagist.org/packages/workwexin/wecom)[ RSS](/packages/workwexin-wecom/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

WorkWeXin WeCom SDK
===================

[](#workwexin-wecom-sdk)

企业微信 PHP SDK。当前按 service 模块封装能力，用户创建 `WeCom` 实例后，通过对应 service 调用方法。

安装
--

[](#安装)

```
composer require workwexin/wecom
```

快速开始
----

[](#快速开始)

```
use WorkWeXin\WeCom;

$wecom = WeCom::fromApp("wx123", 1000002, "app_secret");

$wecom->message()->sendText("你好", ["touser" => "userid1"]);
$wecom->contacts()->getUser("userid1");
```

也可以使用数组配置：

```
$wecom = WeCom::make([
    "corp_id" => "wx123",
    "agent_id" => 1000002,
    "secret" => "app_secret"
]);
```

调用方式
----

[](#调用方式)

SDK 的主要调用方式是：

```
$wecom->{service}()->{method}(...);
```

例如：

```
$wecom->message()->sendMarkdown("**内容**", ["touser" => "userid1"]);
$wecom->contacts()->listUsers(1, true);
$wecom->approval()->getTemplateDetail("template_id");
$wecom->oa()->getCheckinData($startTime, $endTime, ["userid1"]);
```

消息模块也提供少量快捷方法：

```
$wecom->sendText("你好", "userid1");
$wecom->sendMarkdown("**内容**", ["userid1", "userid2"]);
```

可用 Service
----------

[](#可用-service)

service用途`message()`应用消息`contacts()`通讯录`auth()`身份与登录`callback()`回调加解密`callbackEvents()`回调事件分发`customerContact()`客户联系`approval()`审批`oa()`OA：打卡、日程、会议室、待办等`miniProgram()`小程序`payment()`支付常用示例
----

[](#常用示例)

发送应用消息：

```
$wecom->message()->sendText("你好", ["touser" => "userid1"]);
$wecom->message()->sendMarkdown("**加粗**内容", ["touser" => "userid1|userid2"]);
$wecom->message()->sendTextCard("标题", "描述", "https://example.com", ["touser" => "userid1"]);
```

通讯录：

```
$wecom->contacts()->getUser("userid1");
$wecom->contacts()->listUsers(1, true);
$wecom->contacts()->createUser([
    "userid" => "userid1",
    "name" => "张三",
    "department" => [1]
]);
```

审批与 OA：

```
$wecom->approval()->listTemplates();
$wecom->approval()->getApprovalDetail("sp_no");
$wecom->oa()->getCheckinData($startTime, $endTime, ["userid1"]);
```

客户联系：

```
$wecom->customerContact()->listFollowUsers();
$wecom->customerContact()->listExternalContacts("userid1");
```

小程序：

```
$wecom->miniProgram()->getSession("js_code");
$wecom->miniProgram()->getJsapiTicket();
```

支付：

```
$wecom->payment()->queryOrder($data);
$sign = $wecom->payment()->sign($data, "payment_api_key");
```

配置
--

[](#配置)

单企业单应用推荐使用：

```
$wecom = WeCom::fromApp("wx123", 1000002, "app_secret", [
    "cache_path" => __DIR__ . "/runtime/cache",
    "timeout" => 5.0
]);
```

多企业或多应用使用完整配置：

```
$wecom = WeCom::make([
    "corps" => [
        "default" => [
            "corp_id" => "wx123",
            "apps" => [
                "default" => [
                    "agent_id" => 1000002,
                    "secret" => "app_secret"
                ]
            ],
            "callback" => [
                "token" => "callback_token",
                "encoding_aes_key" => "encoding_aes_key"
            ]
        ]
    ],
    "cache" => [
        "path" => __DIR__ . "/runtime/cache",
        "ttl" => 7200
    ],
    "http" => [
        "timeout" => 5.0,
        "base_uri" => "https://qyapi.weixin.qq.com"
    ]
]);
```

Token 与签名
---------

[](#token-与签名)

- 普通 service 接口统一使用企业微信 `access_token`，SDK 会自动获取并缓存。
- 回调验签和加解密使用 `callback.token` 与 `callback.encoding_aes_key`。
- 支付签名使用支付 API key，通过 `payment()->sign()` 和 `payment()->verifySignature()` 处理。

错误处理
----

[](#错误处理)

企业微信接口返回错误时会抛出 `WorkWeXin\Exception\WeComException`：

```
try {
    $wecom->contacts()->getUser("userid1");
} catch (\WorkWeXin\Exception\WeComException $e) {
    echo $e->getCode() . ": " . $e->getMessage();
}
```

示例文件
----

[](#示例文件)

更多示例见 `examples/`：

- `examples/basic.php`
- `examples/callback.php`
- `examples/customer_contact.php`
- `examples/approval_oa.php`
- `examples/miniprogram.php`
- `examples/payment.php`

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance61

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce2f6eeaefc7077f2e238b6a2f1ad390d2fdaebf7acefe513f4f80936cc85eb3?d=identicon)[chenchangping1987](/maintainers/chenchangping1987)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/workwexin-wecom/health.svg)

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

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k14](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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