通讯录

  1. $config = [
  2. 'corp_id' => 'xxxxxxxxxxxxxxxxx',
  3. 'secret' => 'xxxxxxxxxx', // 通讯录的 secret
  4. //...
  5. ];
  6. $contacts = Factory::work($config);

成员管理

创建成员

  1. $data = [
  2. "userid" => "overtrue",
  3. "name" => "超哥",
  4. "english_name" => "overtrue"
  5. "mobile" => "1818888888",
  6. ];
  7. $contacts->user->create($data);

读取成员

  1. $contacts->user->get('overtrue');

更新成员

  1. $contacts->user->update('overtrue', [
  2. "isleader" => 0,
  3. 'position' => 'PHP 酱油工程师',
  4. //...
  5. ]);

删除成员

  1. $contacts->user->delete('overtrue');
  2. // 或者删除多个
  3. $contacts->user->delete(['overtrue', 'zhangsan', 'wangwu']);

获取部门成员

  1. $contacts->user->getDepartmentUsers($departmentId);
  2. // 递归获取子部门下面的成员
  3. $contacts->user->getDepartmentUsers($departmentId, true);

获取部门成员详情

  1. $contacts->user->getDetailedDepartmentUsers($departmentId);
  2. // 递归获取子部门下面的成员
  3. $contacts->user->getDetailedDepartmentUsers($departmentId, true);

用户 ID 转为 openid

  1. $contacts->user->userIdToOpenid($userId);
  2. // 或者指定应用 ID
  3. $contacts->user->userIdToOpenid($userId, $agentId);

openid 转为用户 ID

  1. $contacts->user->openidToUserId($openid);

手机号转为用户 ID

  1. $contacts->user->mobileToUserId($mobile);

二次验证

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

  1. $contacts->user->accept($userId);

邀请成员

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

  1. $params = [
  2. 'user' => ['UserID1', 'UserID2', 'UserID3'], // 成员ID列表, 最多支持1000个
  3. 'party' => ['PartyID1', 'PartyID2'], // 部门ID列表,最多支持100个
  4. 'tag' => ['TagID1', 'TagID2'], // 标签ID列表,最多支持100个
  5. ];
  6. $contacts->user->invite($params);

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

获取邀请二维码

  1. $sizeType = 1; // qrcode尺寸类型,1: 171 x 171; 2: 399 x 399; 3: 741 x 741; 4: 2052 x 2052
  2. $contacts->user->getInvitationQrCode($sizeType);

部门管理

创建部门

  1. $contacts->department->create([
  2. 'name' => '广州研发中心',
  3. 'parentid' => 1,
  4. 'order' => 1,
  5. 'id' => 2,
  6. ]);

更新部门

  1. $contacts->department->update($id, [
  2. 'name' => '广州研发中心',
  3. 'parentid' => 1,
  4. 'order' => 1,
  5. ]);

删除部门

  1. $contacts->department->delete($id);

获取部门列表

  1. $contacts->department->list();
  2. // 获取指定部门及其下的子部门
  3. $contacts->department->list($id);

标签管理

创建标签

  1. $contacts->tag->create($tagName, $tagId);

更新标签名字

  1. $contacts->tag->update($tagId, $tagName);

删除标签

  1. $contacts->tag->delete($tagId);

获取标签列表

  1. $contacts->tag->list();

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

  1. $contacts->tag->get($tagId);

增加标签成员

  1. $contacts->tag->tagUsers($tagId, [$userId1, $userId2, ...]);
  2. // 指定部门
  3. $contacts->tag->tagDepartments($tagId, [$departmentId1, $departmentId2, ...]);

删除标签成员

  1. $contacts->tag->untagUsers($tagId, [$userId1, $userId2, ...]);
  2. // 指定部门
  3. $contacts->tag->untagDepartments($tagId, [$departmentId1, $departmentId2, ...]);