User.php
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace Weasy\External\Api\Struct\User;
use Weasy\External\Utils\Error\ParameterError;
use Weasy\External\Utils\Error\QyApiError;
use Weasy\External\Utils\Utils;
class User
{
public $userid = null; // string
public $name = null; // string
public $english_name = null; // string
public $mobile = null; // string
public $department = null; // uint array
public $order = null; // uint array
public $position = null; // string
public $gender = null; // uint [bug]
public $email = null; // string
public $telephone = null; // string
public $isleader = null; // uint
public $avatar = null; // string
public $avatar_mediaid = null; // string
public $address = null; // string
public $enable = null; // uint
public $extattr = null; // ExtattrList
public $status = null; // uint, 激活状态: 1=已激活,2=已禁用,4=未激活。已激活代表已激活企业微信或已关注微信插件。未激活代表既未激活企业微信又未关注微信插件。
/**
* @param $arr
*
* @return User
*/
static public function Array2User($arr)
{
$user = new User();
$user->userid = Utils::arrayGet($arr, "userid");
$user->name = Utils::arrayGet($arr, "name");
$user->english_name = Utils::arrayGet($arr, "english_name");
$user->mobile = Utils::arrayGet($arr, "mobile");
$user->department = Utils::arrayGet($arr, "department");
$user->order = Utils::arrayGet($arr, "order");
$user->position = Utils::arrayGet($arr, "position");
$user->gender = Utils::arrayGet($arr, "gender");
$user->email = Utils::arrayGet($arr, "email");
$user->telephone = Utils::arrayGet($arr, "telephone");
$user->isleader = Utils::arrayGet($arr, "isleader");
$user->avatar = Utils::arrayGet($arr, "avatar");
$user->avatar_mediaid = Utils::arrayGet($arr, "avatar_mediaid");
$user->address = Utils::arrayGet($arr, "address");
$user->enable = Utils::arrayGet($arr, "enable");
$user->status = Utils::arrayGet($arr, "status");
if (array_key_exists("extattr", $arr)) {
$attrs = $arr["extattr"]["attrs"];
if (is_array($attrs)) {
$user->extattr = new ExtattrList();
foreach ($attrs as $item) {
$name = $item["name"];
$value = $item["value"];
$user->extattr->attrs[] = new ExtattrItem($name, $value);
}
}
}
return $user;
}
/**
* @param $arr
*
* @return array
*/
static public function Array2UserList($arr)
{
$userList = $arr["userlist"];
$retUserList = array();
if (is_array($userList)) {
foreach ($userList as $item) {
$user = User::Array2User($item);
$retUserList[] = $user;
}
}
return $retUserList;
}
/**
* @param $user
*
* @throws ParameterError
*/
static public function CheckUserCreateArgs($user)
{
Utils::checkNotEmptyStr($user->userid, "userid");
Utils::checkNotEmptyStr($user->name, "name");
Utils::checkNotEmptyArray($user->department, "department");
}
/**
* @param $user
*
* @throws ParameterError
*/
static public function CheckUserUpdateArgs($user)
{
Utils::checkNotEmptyStr($user->userid, "userid");
}
/**
* @param $userIdList
*
* @throws ParameterError
* @throws QyApiError
*/
static public function CheckuserBatchDeleteArgs($userIdList)
{
Utils::checkNotEmptyArray($userIdList, "userid list");
foreach ($userIdList as $userId) {
Utils::checkNotEmptyStr($userId, "userid");
}
if (count($userIdList) > 200) {
throw new QyApiError("no more than 200 userid once");
}
}
}