-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClient.php
More file actions
179 lines (174 loc) · 4.08 KB
/
Client.php
File metadata and controls
179 lines (174 loc) · 4.08 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
require_once 'core/apiRequire.php';
class Client{
protected $subdomain;
protected $email;
protected $token;
protected $password;
protected $apiUrl;
/**
* @var 工单(客服)类
*/
protected $tickets;
/**
*
* @var 工单(普通用户)类
*/
protected $requests;
/**
*
* @var 工单自定义字段
*/
protected $fields;
/**
*
* @var 工单查看分类
*/
protected $views;
/**
*
* @var 用户类
*/
protected $users;
/**
*
* @var 客服组类
*/
protected $groups;
/**
* @var 公司组织类
*/
protected $organizations ;
/**
*
* @var 附件类
*/
protected $attachments ;
/**
*
* @var 文档分区类
*/
protected $categories;
/**
*
* @var 文档分类
*/
protected $forums;
/**
*
* @var 文档类
*/
protected $posts;
/**
*
* @var 社区话题类
*/
protected $topics;
/**
*
* @var 社区问题类
*/
protected $questions;
/**
*
* @var 导入类
*/
protected $imports ;
/**
*
* @var 导出类
*/
protected $exports ;
protected $apiVer = 'v2';
protected $debug;
public function __construct($subdomain,$email){
$this->subdomain = $subdomain;
$this->email = $email;
$this->tickets = new Tickets($this);
$this->requests = new Requests($this);
$this->users = new Users($this);
$this->fields = new Fields($this);
$this->views = new Views($this);
$this->groups = new Groups($this);
$this->organizations = new Organizations($this);
$this->categories = new Categories($this);
$this->forums = new Forums($this);
$this->posts = new Posts($this);
$this->topics = new Topics($this);
$this->questions = new Questions($this);
$this->attachments = new Attachments($this);
$this->imports = new Imports($this);
$this->exports = new Exports($this);
$this->debug = new Debug();
if(stristr($this->subdomain,'kf5.com'))
$this->apiUrl = 'http://'.$this->subdomain.'/api'.$this->apiVer.'/';
else
$this->apiUrl = 'http://'.$this->subdomain.'.kf5.com/api'.$this->apiVer.'/';
}
public function __call($name, $arguments) {
if(isset($this->$name)) {
//return ((isset($arguments[0])) && ($arguments[0] != null) ? $this->$name->setLastId($arguments[0]) : $this->$name);
return $this->$name;
}else{
throw new CustomException("No method called $name available in ".__CLASS__);
}
}
/**
* 设置验证的方式(token or password)
*
* @param string $method
* @param string $value
*/
public function setAuth($method, $value){
switch($method) {
case 'password':
$this->password = $value;
$this->token = '';
break;
case 'token':
$this->password = '';
$this->token = $value;
break;
}
}
public function validateToken(){
return $this->token ? true:false;
}
/**
* 返回当前的apiurl根路径
*
* @return string
*/
public function getApiUrl() {
return $this->apiUrl;
}
/**
* 根据验证的方式不同,拼接参数
*
* @return string
*/
public function getAuthText() {
return ($this->email.($this->password ? ':'.$this->password : '/token:'.$this->token));
}
/**
* 存入返回数据的信息
*
* @param mixed $lastRequestHeaders
* @param mixed $lastResponseCode
* @param string $lastResponseHeaders
*/
public function setDebug($lastRequestHeaders, $lastResponseCode, $lastResponseHeaders, $lastResponBody) {
$this->debug->lastRequestHeaders = $lastRequestHeaders;
$this->debug->lastResponseCode = $lastResponseCode;
$this->debug->lastResponseHeaders = $lastResponseHeaders;
$this->debug->lastResponseBody = $lastResponBody;
}
/**
* 取出返回数据的信息
*
* @return Debug
*/
public function getDebug() {
return $this->debug;
}
}