通讯录

<?php
$config = [
    // 企业微信后台的 企业 ID
    'corpId' => 'xxxxxxxxxxxxxxxxx',

    // 通讯录的 secret
    'corpSecret' => 'xxxxxxxxxxxxxxxxx',

    // ...
];

// 企业微信
$work = \EasySwoole\WeChat\Factory::work($config);

成员管理

创建成员

<?php
$data = [
    "userid" => "easyswoole",
    "name" => "EasySwoole",
    "english_name" => "easyswoole",
    "mobile" => "12345678910",
];
$work->user->create($data);

读取成员

$work->user->get('easyswoole');

更新成员

<?php
$work->user->update('easyswoole', [
    "isleader" => 0,
    'position' => 'PHP 工程师',
    // ...
]);

删除成员

<?php
$work->user->delete('easyswoole');
// 或者删除多个
$work->user->delete(['easyswoole', 'zhangsan', 'wangwu']);

获取部门成员

<?php
$work->user->getDepartmentUsers($departmentId);
// 递归获取子部门下面的成员
$work->user->getDepartmentUsers($departmentId, true);

获取部门成员详情

<?php
$work->user->getDetailedDepartmentUsers($departmentId);
// 递归获取子部门下面的成员
$work->user->getDetailedDepartmentUsers($departmentId, true);

用户 ID 转为 openid

<?php
$work->user->userIdToOpenid($userId);
// 或者指定应用 ID
$work->user->userIdToOpenid($userId, $agentId);

openid 转为用户 ID

$work->user->openidToUserId($openid);

手机号转为用户 ID

$work->user->mobileToUserId($mobile);

二次验证

企业在成员验证成功后,调用如下接口即可让成员加入成功

$work->user->accept($userId);

邀请成员

企业可通过接口批量邀请成员使用企业微信,邀请后将通过短信或邮件下发通知。

<?php
$params = [
    // 成员ID列表, 最多支持1000个
    'user' => ['UserID1', 'UserID2', 'UserID3'],

    // 部门ID列表,最多支持100个
    'party' => ['PartyID1', 'PartyID2'],

    // 标签ID列表,最多支持100个
    'tag' => ['TagID1', 'TagID2']
];

$work->user->invite($params);

user、party、tag 三者不能同时为空

获取邀请二维码

<?php
// qrcode尺寸类型,1: 171 x 171; 2: 399 x 399; 3: 741 x 741; 4: 2052 x 2052
$sizeType = 1; 

$work->user->getInvitationQrCode($sizeType);

部门管理

创建部门

<?php
$work->department->create([
    'name' => '广州研发中心',
    'parentid' => 1,
    'order' => 1,
    'id' => 2,
]);

更新部门

<?php
$work->department->update($id, [
    'name' => '广州研发中心',
    'parentid' => 1,
    'order' => 1,
]);

删除部门

<?php
$work->department->delete($id);

获取部门列表

<?php
$work->department->list();
// 获取指定部门及其下的子部门
$work->department->list($id);

标签管理

创建标签

$work->user->tag->create($tagName, $tagId);

更新标签名字

$work->user->tag->update($tagId, $tagName);

删除标签

$work->user->tag->delete($tagId);

获取标签列表

$work->user->tag->list();

获取标签成员(标签详情)

$work->user->tag->get($tagId);

增加标签成员

<?php
$work->user->tag->tagUsers($tagId, [$userId1, $userId2, ...]);
// 指定部门
$work->user->tag->tagDepartments($tagId, [$departmentId1, $departmentId2, ...]);

删除标签成员

<?php
$work->user->tag->untagUsers($tagId, [$userId1, $userId2, ...]);
// 指定部门
$work->user->tag->untagDepartments($tagId, [$departmentId1, $departmentId2, ...]);

异步批量接口

注意: 【异步批量接口】需要使用 ”通讯录同步” secret 所获取的 accesstoken 来调用。 传送门: https://work.weixin.qq.com/wework_admin/frame#apps/contactsApi

增量更新成员

<?php
$params = [
    'media_id' => 'mediaId',
    'to_invite' => true,
    'callback' => [
        'url' => 'xxx',
        'token' => 'xxx',
        'encodingaeskey' => 'xxx'
    ]
];

$work->user->batchJobs->batchUpdateUsers(array $params);

全量覆盖成员

<?php
$params = [
    'media_id' => 'mediaId',
    'to_invite' => true,
    'callback' => [
        'url' => 'xxx',
        'token' => 'xxx',
        'encodingaeskey' => 'xxx'
    ]
];

$work->user->batchJobs->batchReplaceUsers(array $params);

全量覆盖部门

<?php
$params = [
    'media_id' => 'mediaId',
    'callback' => [
        'url' => 'xxx',
        'token' => 'xxx',
        'encodingaeskey' => 'xxx'
    ]
];

$work->user->batchJobs->batchReplaceDepartments(array $params);

获取异步任务结果

<?php
$jobId = '2322232';

$work->user->batchJobs->getJobStatus(array $jobId);

互联企业

获取应用的可见范围

$work->user->linkedCorp->getAgentPermissions();

获取互联企业成员详细信息

<?php
$userId = 'corpId/userId';

$work->user->linkedCorp->getUser(string $userId);

获取互联企业部门成员

<?php
$departmentId = 'linkedId/departmentId';
$fetchChild = true;

$work->user->linkedCorp->getUsers(string $departmentId, bool $fetchChild = true);

获取互联企业部门成员详情

<?php
$departmentId = 'linkedId/departmentId';
$fetchChild = true;

$work->user->linkedCorp->getDetailedUsers(string $departmentId, bool $fetchChild = true);

获取互联企业部门列表

<?php
$departmentId = 'linkedId/departmentId';

$work->user->linkedCorp->getDepartments(string $departmentId);