-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Staff.php
executable file
·154 lines (138 loc) · 3.6 KB
/
Staff.php
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Staff.php.
*
* @author overtrue <i@overtrue.me>
* @copyright 2015 overtrue <i@overtrue.me>
*
* @link https://github.com/overtrue
* @link http://overtrue.me
*/
namespace EasyWeChat\Staff;
use EasyWeChat\Core\AbstractAPI;
/**
* Class Staff.
*/
class Staff extends AbstractAPI
{
const API_LISTS = 'https://api.weixin.qq.com/cgi-bin/customservice/getkflist';
const API_ONLINE = 'https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist';
const API_DELETE = 'https://api.weixin.qq.com/customservice/kfaccount/del';
const API_UPDATE = 'https://api.weixin.qq.com/customservice/kfaccount/update';
const API_CREATE = 'https://api.weixin.qq.com/customservice/kfaccount/add';
const API_MESSAGE_SEND = 'https://api.weixin.qq.com/cgi-bin/message/custom/send';
const API_AVATAR_UPLOAD = 'http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg';
/**
* List all staffs.
*
* @return array
*/
public function lists()
{
return $this->parseJSON('get', [self::API_LISTS]);
}
/**
* List all online staffs.
*
* @return array
*/
public function onlines()
{
return $this->parseJSON('get', [self::API_ONLINE]);
}
/**
* Create a staff.
*
* @param string $email
* @param string $nickname
* @param string $password
*
* @return bool
*/
public function create($email, $nickname, $password)
{
$params = [
'kf_account' => $email,
'nickname' => $nickname,
'password' => $password,
];
return $this->parseJSON('json', [self::API_CREATE, $params]);
}
/**
* Update a staff.
*
* @param string $email
* @param string $nickname
* @param string $password
*
* @return bool
*/
public function update($email, $nickname, $password)
{
$params = [
'kf_account' => $email,
'nickname' => $nickname,
'password' => $password,
];
return $this->parseJSON('json', [self::API_UPDATE, $params]);
}
/**
* Delete a staff.
*
* @param string $email
*
* @return bool
*/
public function delete($email)
{
$params = [
'kf_account' => $email,
];
return $this->parseJSON('get', [sprintf(self::API_DELETE.'?kf_account=%s', $email)]);
}
/**
* Set staff avatar.
*
* @param string $email
* @param string $path
*
* @return bool
*/
public function avatar($email, $path)
{
return $this->parseJSON('upload', [self::API_AVATAR_UPLOAD, ['media' => $path], [], ['kf_account' => $email]]);
}
/**
* Get message builder.
*
* @param \EasyWeChat\Message\AbstractMessage|string $message
*
* @return \EasyWeChat\Staff\MessageBuilder
*
* @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException
*/
public function message($message)
{
$messageBuilder = new MessageBuilder($this);
return $messageBuilder->message($message);
}
/**
* Send a message.
*
* @param string|array $message
*
* @return mixed
*/
public function send($message)
{
return $this->parseJSON('json', [self::API_MESSAGE_SEND, $message]);
}
}