-
Notifications
You must be signed in to change notification settings - Fork 2
User
freyo edited this page May 29, 2017
·
2 revisions
成员信息的获取是企业微信开发中比较常用的一个功能了,以下所有成员相关操作,使用的管理组须拥有指定部门的管理权限,否则无法正常使用。
<?php
use EntWeChat\Foundation\Application;
// ...
$app = new Application($options);
$userService = $app->user;
$userInfo = [
"userid" => "zhangsan",
"name" => "张三",
"department" => [1, 2],
"position" => "产品经理",
"mobile" => "15913215421",
"gender" => "1",
"email" => "[email protected]",
"weixinid" => "zhangsan4dev",
"avatar_mediaid" => "2-G6nrLmr5EC3MNb_-zL1dDdzkd0p7cNliYu9V5w7o8K0",
"extattr" => [
"attrs" => [
["name" => "爱好", "value" => "旅游"],
["name" => "卡号", "value" =>"1234567234"]
]
]
];
$userService->create($userInfo);
如果非必须的字段未指定,则不更新该字段之前的设置值
$userId = 'zhangsan';
$userInfo = [
"name" => "张三",
"department" => [1, 2],
"position" => "产品经理",
"mobile" => "15913215421",
"gender" => "1",
"email" => "[email protected]",
"weixinid" => "zhangsan4dev",
"avatar_mediaid" => "2-G6nrLmr5EC3MNb_-zL1dDdzkd0p7cNliYu9V5w7o8K0",
"extattr" => [
"attrs" => [
["name" => "爱好", "value" => "旅游"],
["name" => "卡号", "value" =>"1234567234"]
]
]
];
$userService->update($userId, $userInfo);
删除单个:
$userId = 'zhangsan';
$userService->delete($userId);
删除多个:
$userIds = [$userId1, $userId2, ...];
$userService->batchDelete($userIds);
$userService->get($userId);
按部门获取成员基本信息:
$userService->batchGet($departmentId, $fetchChild = null, $status = null);
example:
$users = $userService->batchGet(1);
// result
{
"errcode": 0,
"errmsg": "ok",
"userlist": [
{
"userid": "zhangsan",
"name": "李四",
"department": [1, 2]
}
]
}
按部门获取成员详细信息:
$userService->lists($departmentId, $fetchChild = null, $status = null);
$users = $userService->lists(1);
// result
{
"errcode": 0,
"errmsg": "ok",
"userlist": [
{
"userid": "zhangsan",
"name": "李四",
"department": [1, 2],
"position": "后台工程师",
"mobile": "15913215421",
"gender": "1",
"email": "[email protected]",
"weixinid": "lisifordev",
"avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
"status": 1,
"extattr": {"attrs":[{"name":"爱好","value":"旅游"},{"name":"卡号","value":"1234567234"}]}
}
]
}
关于用户管理请参考微信官方文档:http://qydev.weixin.qq.com/wiki/ 管理成员
章节。