PHPackages                             midi/work-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. midi/work-wechat

ActiveLibrary[API Development](/categories/api)

midi/work-wechat
================

企业微信php-sdk

v1.1.5(3y ago)6701[1 issues](https://github.com/humSuperman/work-wechat/issues)MITPHPPHP &gt;=7.0

Since Mar 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/humSuperman/work-wechat)[ Packagist](https://packagist.org/packages/midi/work-wechat)[ RSS](/packages/midi-work-wechat/feed)WikiDiscussions master Synced 1mo ago

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

work-wechat
===========

[](#work-wechat)

环境需求
----

[](#环境需求)

- PHP &gt;= 7.0.0
- [Composer](https://getcomposer.org/) &gt;= 2.0

安装
--

[](#安装)

```
composer require midi/work-wechat
```

#### [验证URL有效性](https://developer.work.weixin.qq.com/document/path/90238#%E9%AA%8C%E8%AF%81url%E6%9C%89%E6%95%88%E6%80%A7)

[](#验证url有效性)

```
$service = new WorkWechat\Service\EventService('corpId','encodingAesKey','token');
try{
    // 需要自行urldecode
    echo $service->verifyURL('msgSignature',(int)'timestamp','nonce','msgEncrypt');
}catch (\Exception $e){
    print $e;
    echo '';
}
```

#### [接收post业务数据](https://developer.work.weixin.qq.com/document/path/91116#32-%E6%94%AF%E6%8C%81http-post%E8%AF%B7%E6%B1%82%E6%8E%A5%E6%94%B6%E4%B8%9A%E5%8A%A1%E6%95%B0%E6%8D%AE)

[](#接收post业务数据)

```
$service = new WorkWechat\Service\EventService('corpId','encodingAesKey','token');
$xml = file_get_contents("php://input");
try{
    // 需要自行urldecode
    // 接收到的数据已转为array
    $service->decryptMsg('msgSignature',(int)'timestamp','nonce',$xml);
}catch (\Exception $e){
    print $e;
    echo 'fail';
}
```

#### [网页授权](https://developer.work.weixin.qq.com/document/path/91022)

[](#网页授权)

```
$url = WorkWechat\Service\AuthService::getRedirectUrl('corpId','https://www.baidu.com')
```

#### [扫码登录](https://developer.work.weixin.qq.com/document/path/91019)

[](#扫码登录)

```
$url = WorkWechat\Service\AuthService::getQrCodeUrl('corpId','agentId','https://www.baidu.com','')
```

#### [获取access\_token](https://developer.work.weixin.qq.com/document/path/91039)

[](#获取access_token)

```
// 已增加本地文件缓存
$service = new WorkWechat\Service\AccessTokenService('corpId','secret');
$accessToken = $service->getToken();
// 刷新access_token
$accessToken = $service->refresh();
```

#### [获取访问用户身份](https://developer.work.weixin.qq.com/document/path/91023)

[](#获取访问用户身份)

```
$service = new WorkWechat\Service\UserService();
$service->setAccessToken($accessToken);
$service->companyUserByCode('code');
```

#### [读取成员](https://developer.work.weixin.qq.com/document/path/90196)

[](#读取成员)

```
$userService = new WorkWechat\Service\UserService();
$userService->setAccessToken($accessToken);
$userService->detail('userId')
```

#### [获取客户详情](https://developer.work.weixin.qq.com/document/path/92114)

[](#获取客户详情)

```
$customerService = new WorkWechat\Service\CustomerService();
$customerService->setAccessToken($accessToken);
$customerService->customerDetail('externalUserid')
```

#### [联系客户统计](https://developer.work.weixin.qq.com/document/path/92132)

[](#联系客户统计)

```
$customerService = new WorkWechat\Service\CustomerService();
$customerService->setAccessToken($accessToken);
$customerService->userBehaviorData(['userid','userid',...],['deptmentId',...],1618780712,1649903913)
```

#### 企业部门

[](#企业部门)

```
$departmentService = new WorkWechat\Service\DepartmentService();
$departmentService->setAccessToken($accessToken);
// 获取所有部门
$departmentService->list();
// 获取某个部门及下级部门
$departmentService->list(id);
// 部门详情
$departmentService->detail(id);

// 所有部门及部门下属员工
$departmentService->totalUserList();

// 所有部门及部门下属员工 树形结构
$departmentService->departmentTreeAndTotalUser();
```

#### [发送文本消息](https://developer.work.weixin.qq.com/document/path/90236#%E6%96%87%E6%9C%AC%E6%B6%88%E6%81%AF)

[](#发送文本消息)

```
$messageService = new WorkWechat\Service\MessageService('agentId');
$messageService->setAccessToken($accessToken);
$messageService->setMessage('text-message'); // 设置发送的文本消息
$messageService->setSecrecy(1); // 设置消息是否保密 0-否 1-是
$messageService->sendTextMsgToCompanyUser('userId','userId','userId','userId','userId','userId','userId'); // 向多个/一个userId发送此消息
```

#### 如何获取external\_userid

[](#如何获取external_userid)

[通过成员userId获取](https://developer.work.weixin.qq.com/document/path/92113)[前端jsapi获取](https://developer.work.weixin.qq.com/document/path/91799)

#### 获取企业jsapi ticket

[](#获取企业jsapi-ticket)

[wx.config](https://developer.work.weixin.qq.com/document/path/94313)

```
$service = new WorkWechat\Service\TicketService('corpId','secret');
$service->setAccessToken($accessToken);
$service->company();
// 刷新企业jsapi ticket
$service->refreshCompany()
```

#### 获取应用jsapi ticket

[](#获取应用jsapi-ticket)

[wx.agentConfig](https://developer.work.weixin.qq.com/document/path/94313)

```
$service = new WorkWechat\Service\TicketService('corpId','secret');
$service->setAccessToken($accessToken);
$service->agent();
// 刷新应用jsapi ticket
$service->refreshCompany()
```

#### 明文corpid转换为加密corpid

[](#明文corpid转换为加密corpid)

[明文corpid转换为加密corpid](https://developer.work.weixin.qq.com/document/path/95604)

```
$service = new WorkWechat\Service\TicketService('corpId','secret');
$service->setAccessToken($accessToken);
$service->openCorpId("corpid");
```

#### 通讯录标签管理

[](#通讯录标签管理)

[标签创建更新及绑定企业成员](https://developer.work.weixin.qq.com/document/path/90210)

```
$service = new WorkWechat\Service\TagService();
$service->setAccessToken($accessToken);
// 具体实现方法
$service->list();
$service->create("标签名");
$service->update($tagId,"标签名");
$service->delete($tagId);
$service->userList($tagId);
// 绑定用户或部门下用户
$service->bindTagUser($tagId,'userId-1','userId-2','userId-3','userId-4',...); // 可绑定1个或多个，100条上限
$service->bindTagDepartment($tagId,$deptId,$deptId,$deptId,$deptId,$deptId,...); // 可绑定1个或多个，100条上限
// 绑定用户或部门下用户
$service->deleteTagUser($tagId,'userId-1','userId-2','userId-3','userId-4',...); // 删除1个或多个，100条上限
$service->deleteTagDepartment($tagId,$deptId,$deptId,$deptId,$deptId,$deptId,...); // 删除1个或多个，100条上限
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

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

Recently: every ~45 days

Total

21

Last Release

1248d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c19ce42521d93e829e50d202af5cbbaa038c4a262d62d943314d98fc510c710?d=identicon)[humSuperman](/maintainers/humSuperman)

---

Top Contributors

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

---

Tags

work wechat

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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