FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
weworkapi_php/api/src/API.class.php at master · EternalSuno/weworkapi_php · GitHub
EternalSuno
/
weworkapi_php
Public
forked from
sbzhu/weworkapi_php
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
weworkapi_php
/
api
/
src
/
API.class.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
245 lines (206 loc) · 11.2 KB
Breadcrumbs
weworkapi_php
/
api
/
src
/
API.class.php
Copy path
File metadata and controls
245 lines (206 loc) · 11.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
include_once
(
__DIR__
.
"
/../../utils/Utils.class.php
"
);
include_once
(
__DIR__
.
"
/../../utils/HttpUtils.class.php
"
);
include_once
(
__DIR__
.
"
/../../utils/error.inc.php
"
);
abstract
class
API
{
public
$
rspJson
=
null
;
public
$
rspRawStr
=
null
;
const
USER_CREATE
=
'
/cgi-bin/user/create?access_token=ACCESS_TOKEN
'
;
const
USER_GET
=
'
/cgi-bin/user/get?access_token=ACCESS_TOKEN
'
;
const
USER_UPDATE
=
'
/cgi-bin/user/update?access_token=ACCESS_TOKEN
'
;
const
USER_DELETE
=
'
/cgi-bin/user/delete?access_token=ACCESS_TOKEN
'
;
const
USER_BATCH_DELETE
=
'
/cgi-bin/user/batchdelete?access_token=ACCESS_TOKEN
'
;
const
USER_SIMPLE_LIST
=
'
/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN
'
;
const
USER_LIST
=
'
/cgi-bin/user/list?access_token=ACCESS_TOKEN
'
;
const
USERID_TO_OPENID
=
'
/cgi-bin/user/convert_to_openid?access_token=ACCESS_TOKEN
'
;
const
OPENID_TO_USERID
=
'
/cgi-bin/user/convert_to_userid?access_token=ACCESS_TOKEN
'
;
const
USER_AUTH_SUCCESS
=
'
/cgi-bin/user/authsucc?access_token=ACCESS_TOKEN
'
;
const
DEPARTMENT_CREATE
=
'
/cgi-bin/department/create?access_token=ACCESS_TOKEN
'
;
const
DEPARTMENT_UPDATE
=
'
/cgi-bin/department/update?access_token=ACCESS_TOKEN
'
;
const
DEPARTMENT_DELETE
=
'
/cgi-bin/department/delete?access_token=ACCESS_TOKEN
'
;
const
DEPARTMENT_LIST
=
'
/cgi-bin/department/list?access_token=ACCESS_TOKEN
'
;
const
TAG_CREATE
=
'
/cgi-bin/tag/create?access_token=ACCESS_TOKEN
'
;
const
TAG_UPDATE
=
'
/cgi-bin/tag/update?access_token=ACCESS_TOKEN
'
;
const
TAG_DELETE
=
'
/cgi-bin/tag/delete?access_token=ACCESS_TOKEN
'
;
const
TAG_GET_USER
=
'
/cgi-bin/tag/get?access_token=ACCESS_TOKEN
'
;
const
TAG_ADD_USER
=
'
/cgi-bin/tag/addtagusers?access_token=ACCESS_TOKEN
'
;
const
TAG_DELETE_USER
=
'
/cgi-bin/tag/deltagusers?access_token=ACCESS_TOKEN
'
;
const
TAG_GET_LIST
=
'
/cgi-bin/tag/list?access_token=ACCESS_TOKEN
'
;
const
BATCH_JOB_GET_RESULT
=
'
/cgi-bin/batch/getresult?access_token=ACCESS_TOKEN
'
;
const
BATCH_INVITE
=
'
/cgi-bin/batch/invite?access_token=ACCESS_TOKEN
'
;
const
AGENT_GET
=
'
/cgi-bin/agent/get?access_token=ACCESS_TOKEN
'
;
const
AGENT_SET
=
'
/cgi-bin/agent/set?access_token=ACCESS_TOKEN
'
;
const
AGENT_GET_LIST
=
'
/cgi-bin/agent/list?access_token=ACCESS_TOKEN
'
;
const
MENU_CREATE
=
'
/cgi-bin/menu/create?access_token=ACCESS_TOKEN
'
;
const
MENU_GET
=
'
/cgi-bin/menu/get?access_token=ACCESS_TOKEN
'
;
const
MENU_DELETE
=
'
/cgi-bin/menu/delete?access_token=ACCESS_TOKEN
'
;
const
MESSAGE_SEND
=
'
/cgi-bin/message/send?access_token=ACCESS_TOKEN
'
;
const
MEDIA_GET
=
'
/cgi-bin/media/get?access_token=ACCESS_TOKEN
'
;
const
GET_USER_INFO_BY_CODE
=
'
/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN
'
;
const
GET_USER_DETAIL
=
'
/cgi-bin/user/getuserdetail?access_token=ACCESS_TOKEN
'
;
const
GET_TICKET
=
'
/cgi-bin/ticket/get?access_token=ACCESS_TOKEN
'
;
conST
GET_JSAPI_TICKET
=
'
/cgi-bin/get_jsapi_ticket?access_token=ACCESS_TOKEN
'
;
const
GET_CHECKIN_OPTION
=
'
/cgi-bin/checkin/getcheckinoption?access_token=ACCESS_TOKEN
'
;
const
GET_CHECKIN_DATA
=
'
/cgi-bin/checkin/getcheckindata?access_token=ACCESS_TOKEN
'
;
const
GET_APPROVAL_DATA
=
'
/cgi-bin/corp/getapprovaldata?access_token=ACCESS_TOKEN
'
;
const
GET_INVOICE_INFO
=
'
/cgi-bin/card/invoice/reimburse/getinvoiceinfo?access_token=ACCESS_TOKEN
'
;
const
UPDATE_INVOICE_STATUS
=
'
/cgi-bin/card/invoice/reimburse/updateinvoicestatus?access_token=ACCESS_TOKEN
'
;
const
BATCH_UPDATE_INVOICE_STATUS
=
'
/cgi-bin/card/invoice/reimburse/updatestatusbatch?access_token=ACCESS_TOKEN
'
;
const
BATCH_GET_INVOICE_INFO
=
'
/cgi-bin/card/invoice/reimburse/getinvoiceinfobatch?access_token=ACCESS_TOKEN
'
;
const
GET_PRE_AUTH_CODE
=
'
/cgi-bin/service/get_pre_auth_code?suite_access_token=SUITE_ACCESS_TOKEN
'
;
const
SET_SESSION_INFO
=
'
/cgi-bin/service/set_session_info?suite_access_token=SUITE_ACCESS_TOKEN
'
;
const
GET_PERMANENT_CODE
=
'
/cgi-bin/service/get_permanent_code?suite_access_token=SUITE_ACCESS_TOKEN
'
;
const
GET_AUTH_INFO
=
'
/cgi-bin/service/get_auth_info?suite_access_token=SUITE_ACCESS_TOKEN
'
;
const
GET_ADMIN_LIST
=
'
/cgi-bin/service/get_admin_list?suite_access_token=SUITE_ACCESS_TOKEN
'
;
const
GET_USER_INFO_BY_3RD
=
'
/cgi-bin/service/getuserinfo3rd?suite_access_token=SUITE_ACCESS_TOKEN
'
;
const
GET_USER_DETAIL_BY_3RD
=
'
/cgi-bin/service/getuserdetail3rd?suite_access_token=SUITE_ACCESS_TOKEN
'
;
const
GET_LOGIN_INFO
=
'
/cgi-bin/service/get_login_info?access_token=PROVIDER_ACCESS_TOKEN
'
;
const
GET_REGISTER_CODE
=
'
/cgi-bin/service/get_register_code?provider_access_token=PROVIDER_ACCESS_TOKEN
'
;
const
GET_REGISTER_INFO
=
'
/cgi-bin/service/get_register_info?provider_access_token=PROVIDER_ACCESS_TOKEN
'
;
const
SET_AGENT_SCOPE
=
'
/cgi-bin/agent/set_scope
'
;
const
SET_CONTACT_SYNC_SUCCESS
=
'
/cgi-bin/sync/contact_sync_success
'
;
protected
function
GetAccessToken
() { }
protected
function
RefreshAccessToken
() { }
protected
function
GetSuiteAccessToken
() { }
protected
function
RefreshSuiteAccessToken
() { }
protected
function
GetProviderAccessToken
() { }
protected
function
RefreshProviderAccessToken
() { }
protected
function
_HttpCall
(
$
url
,
$
method
,
$
args
)
{
if
(
'
POST
'
==
$
method
) {
$
url
= HttpUtils::
MakeUrl
(
$
url
);
$
this
->
_HttpPostParseToJson
(
$
url
,
$
args
);
$
this
->
_CheckErrCode
();
}
else
if
(
'
GET
'
==
$
method
) {
if
(
count
(
$
args
) >
0
) {
foreach
(
$
args
as
$
key
=>
$
value
) {
if
(
$
value
==
null
)
continue
;
if
(
strpos
(
$
url
,
'
?
'
)) {
$
url
.= (
'
&
'
.
$
key
.
'
=
'
.
$
value
);
}
else
{
$
url
.= (
'
?
'
.
$
key
.
'
=
'
.
$
value
);
}
}
}
$
url
= HttpUtils::
MakeUrl
(
$
url
);
$
this
->
_HttpGetParseToJson
(
$
url
);
$
this
->
_CheckErrCode
();
}
else
{
throw
new
QyApiError
(
'
wrong method
'
);
}
}
protected
function
_HttpGetParseToJson
(
$
url
,
$
refreshTokenWhenExpired
=
true
)
{
$
retryCnt
=
0
;
$
this
->
rspJson
=
null
;
$
this
->
rspRawStr
=
null
;
while
(
$
retryCnt
<
2
) {
$
tokenType
=
null
;
$
realUrl
=
$
url
;
if
(
strpos
(
$
url
,
"
SUITE_ACCESS_TOKEN
"
)) {
$
token
=
$
this
->
GetSuiteAccessToken
();
$
realUrl
=
str_replace
(
"
SUITE_ACCESS_TOKEN
"
,
$
token
,
$
url
);
$
tokenType
=
"
SUITE_ACCESS_TOKEN
"
;
}
else
if
(
strpos
(
$
url
,
"
PROVIDER_ACCESS_TOKEN
"
)) {
$
token
=
$
this
->
GetProviderAccessToken
();
$
realUrl
=
str_replace
(
"
PROVIDER_ACCESS_TOKEN
"
,
$
token
,
$
url
);
$
tokenType
=
"
PROVIDER_ACCESS_TOKEN
"
;
}
else
if
(
strpos
(
$
url
,
"
ACCESS_TOKEN
"
)) {
$
token
=
$
this
->
GetAccessToken
();
$
realUrl
=
str_replace
(
"
ACCESS_TOKEN
"
,
$
token
,
$
url
);
$
tokenType
=
"
ACCESS_TOKEN
"
;
}
else
{
$
tokenType
=
"
NO_TOKEN
"
;
}
$
this
->
rspRawStr
= HttpUtils::
httpGet
(
$
realUrl
);
if
( ! Utils::
notEmptyStr
(
$
this
->
rspRawStr
))
throw
new
QyApiError
(
"
empty response
"
);
//
$
this
->
rspJson
=
json_decode
(
$
this
->
rspRawStr
,
true
/*to array*/
);
if
(
strpos
(
$
this
->
rspRawStr
,
"
errcode
"
) !==
false
) {
$
errCode
= Utils::
arrayGet
(
$
this
->
rspJson
,
"
errcode
"
);
if
(
$
errCode
==
40014
||
$
errCode
==
42001
||
$
errCode
==
42007
||
$
errCode
==
42009
) {
// token expired
if
(
"
NO_TOKEN
"
!=
$
tokenType
&&
true
==
$
refreshTokenWhenExpired
) {
if
(
"
ACCESS_TOKEN
"
==
$
tokenType
) {
$
this
->
RefreshAccessToken
();
}
else
if
(
"
SUITE_ACCESS_TOKEN
"
== tokenType) {
$
this
->
RefreshSuiteAccessToken
();
}
else
if
(
"
PROVIDER_ACCESS_TOKEN
"
== tokenType) {
$
this
->
RefreshProviderAccessToken
();
}
$
retryCnt
+=
1
;
continue
;
}
}
}
return
$
this
->
rspRawStr
;
}
}
protected
function
_HttpPostParseToJson
(
$
url
,
$
args
,
$
refreshTokenWhenExpired
=
true
,
$
isPostFile
=
false
)
{
$
postData
=
$
args
;
if
(!
$
isPostFile
) {
if
(!
is_string
(
$
args
)) {
$
postData
= HttpUtils::
Array2Json
(
$
args
);
}
}
$
this
->
rspJson
=
null
;
$
this
->
rspRawStr
=
null
;
$
retryCnt
=
0
;
while
(
$
retryCnt
<
2
) {
$
tokenType
=
null
;
$
realUrl
=
$
url
;
if
(
strpos
(
$
url
,
"
SUITE_ACCESS_TOKEN
"
)) {
$
token
=
$
this
->
GetSuiteAccessToken
();
$
realUrl
=
str_replace
(
"
SUITE_ACCESS_TOKEN
"
,
$
token
,
$
url
);
$
tokenType
=
"
SUITE_ACCESS_TOKEN
"
;
}
else
if
(
strpos
(
$
url
,
"
PROVIDER_ACCESS_TOKEN
"
)) {
$
token
=
$
this
->
GetProviderAccessToken
();
$
realUrl
=
str_replace
(
"
PROVIDER_ACCESS_TOKEN
"
,
$
token
,
$
url
);
$
tokenType
=
"
PROVIDER_ACCESS_TOKEN
"
;
}
else
if
(
strpos
(
$
url
,
"
ACCESS_TOKEN
"
)) {
$
token
=
$
this
->
GetAccessToken
();
$
realUrl
=
str_replace
(
"
ACCESS_TOKEN
"
,
$
token
,
$
url
);
$
tokenType
=
"
ACCESS_TOKEN
"
;
}
else
{
$
tokenType
=
"
NO_TOKEN
"
;
}
$
this
->
rspRawStr
= HttpUtils::
httpPost
(
$
realUrl
,
$
postData
);
if
( ! Utils::
notEmptyStr
(
$
this
->
rspRawStr
))
throw
new
QyApiError
(
"
empty response
"
);
$
json
=
json_decode
(
$
this
->
rspRawStr
,
true
/*to array*/
);
$
this
->
rspJson
=
$
json
;
$
errCode
= Utils::
arrayGet
(
$
this
->
rspJson
,
"
errcode
"
);
if
(
$
errCode
==
40014
||
$
errCode
==
42001
||
$
errCode
==
42007
||
$
errCode
==
42009
) {
// token expired
if
(
"
NO_TOKEN
"
!=
$
tokenType
&&
true
==
$
refreshTokenWhenExpired
) {
if
(
"
ACCESS_TOKEN
"
==
$
tokenType
) {
$
this
->
RefreshAccessToken
();
}
else
if
(
"
SUITE_ACCESS_TOKEN
"
== tokenType) {
$
this
->
RefreshSuiteAccessToken
();
}
else
if
(
"
PROVIDER_ACCESS_TOKEN
"
== tokenType) {
$
this
->
RefreshProviderAccessToken
();
}
$
retryCnt
+=
1
;
continue
;
}
}
return
$
json
;
}
}
protected
function
_CheckErrCode
()
{
$
rsp
=
$
this
->
rspJson
;
$
raw
=
$
this
->
rspRawStr
;
if
(
is_null
(
$
rsp
))
return
;
if
(!
is_array
(
$
rsp
))
throw
new
ParameterError
(
"
invalid type
"
.
gettype
(
$
rsp
));
if
(!
array_key_exists
(
"
errcode
"
,
$
rsp
)) {
return
;
}
$
errCode
=
$
rsp
[
"
errcode
"
];
if
(!
is_int
(
$
errCode
))
throw
new
QyApiError
(
"
invalid errcode type
"
.
gettype
(
$
errCode
) .
"
:
"
.
$
raw
);
if
(
$
errCode
!=
0
)
throw
new
QyApiError
(
"
response error:
"
.
$
raw
);
}
}
Back
|
FazBrowse Home
|
New Git URL