-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWork.php
2215 lines (1840 loc) · 60.9 KB
/
Work.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace dovechen\yii2\weWork;
require_once "components/errorInc/error.inc.php";
use dovechen\yii2\weWork\components\BaseWork;
use dovechen\yii2\weWork\src\dataStructure\Agent;
use dovechen\yii2\weWork\src\dataStructure\Batch;
use dovechen\yii2\weWork\src\dataStructure\BatchJobArgs;
use dovechen\yii2\weWork\src\dataStructure\Department;
use dovechen\yii2\weWork\src\dataStructure\ExternalContact;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactBatchGetByUser;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactBehavior;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactGroupChat;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactMsgTemplate;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactRemark;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactTag;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactTagGroup;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactUnAssignUser;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactWay;
use dovechen\yii2\weWork\src\dataStructure\LinkedcorpMessage;
use dovechen\yii2\weWork\src\dataStructure\Message;
use dovechen\yii2\weWork\src\dataStructure\MsgAuditCheckAgree;
use dovechen\yii2\weWork\src\dataStructure\Tag;
use dovechen\yii2\weWork\src\dataStructure\User;
use dovechen\yii2\weWork\src\dataStructure\UserDetailByUserTicket;
use dovechen\yii2\weWork\src\dataStructure\UserInfoByCode;
use dovechen\yii2\weWork\components\HttpUtils;
use dovechen\yii2\weWork\components\Utils;
use yii\base\Event;
use yii\base\InvalidParamException;
class Work extends BaseWork
{
/**
* 每个企业都拥有唯一的corpid,获取此信息可在管理后台“我的企业”-“企业信息”下查看“企业ID”(需要有管理员权限)
*
* @var string
*/
public $corpid;
/**
* secret是企业应用里面用于保障数据安全的“钥匙”,每一个应用都有一个独立的访问密钥,为了保证数据的安全,secret务必不能泄漏。
* 自建应用secret。在管理后台->“应用与小程序”->“应用”->“自建”,点进某个应用,即可看到。
* 基础应用secret。某些基础应用(如“审批”“打卡”应用),支持通过API进行操作。在管理后台->“应用与小程序”->“应用->”“基础”,点进某个应用,点开“API”小按钮,即可看到。
* 通讯录管理secret。在“管理工具”-“通讯录同步”里面查看(需开启“API接口同步”);
* 外部联系人管理secret。在“客户联系”栏,点开“API”小按钮,即可看到。
*
* @var string
*/
public $secret;
/**
* access_token是企业后台去企业微信的后台获取信息时的重要票据,由corpid和secret产生。所有接口在通信时都需要携带此信息用于验证接口的访问权限
*
* @var string
*/
public $access_token;
/**
* 凭证的有效时间(秒)
*
* @var string
*/
public $access_token_expire;
/**
* 用于计算签名,由英文或数字组成且长度不超过32位的自定义字符串。
*
* @var string
*/
protected $token;
/**
* 用于消息内容加密,由英文或数字组成且长度为43位的自定义字符串。
*
* @var string
*/
protected $encodingAesKey;
/**
* 数据缓存前缀
*
* @var string
*/
protected $cachePrefix = 'cache_work_wx';
/**
* 企业进行自定义开发调用, 请传参 corpid + secret, 不用关心accesstoken,本类会自动获取并刷新
*
* @throws \ParameterError
*/
public function init ()
{
Utils::checkNotEmptyStr($this->corpid, 'corpid');
Utils::checkNotEmptyStr($this->secret, 'secret');
}
/**
* 获取缓存键值
*
* @param $name
*
* @return string
*/
protected function getCacheKey ($name)
{
return $this->cachePrefix . '_' . $this->corpid . '_' . $name;
}
/**
* 获取 accesstoken 不用主动调用
*
* @param bool $force
*
* @return string|void
*
* @throws \ParameterError
* @throws \QyApiError
*/
public function GetAccessToken ($force = false)
{
$time = time();
if (!Utils::notEmptyStr($this->access_token) || $this->access_token_expire < $time || $force) {
$result = !Utils::notEmptyStr($this->access_token) && !$force ? $this->getCache("access_token", false) : false;
if ($result === false) {
$result = $this->RefreshAccessToken();
} else {
if ($result['expire'] < $time) {
$result = $this->RefreshAccessToken();
}
}
$this->SetAccessToken($result);
}
return $this->access_token;
}
/**
* 更新 accesstoken
*
* @throws \ParameterError
* @throws \QyApiError
*/
protected function RefreshAccessToken ()
{
if (!Utils::notEmptyStr($this->corpid) || !Utils::notEmptyStr($this->secret)) {
throw new \ParameterError("invalid corpid or secret");
}
$time = time();
$this->_HttpCall(self::GET_TOKEN, 'GET', ['corpid' => $this->corpid, 'corpsecret' => $this->secret]);
$this->repJson['expire'] = $time + $this->repJson["expires_in"];
$this->setCache('access_token', $this->repJson, $this->repJson['expires_in']);
return $this->repJson;
}
/**
* 设置 accesstoken
*
* @param array $accessToken
*
* @throws InvalidParamException
*/
public function SetAccessToken (array $accessToken)
{
if (!isset($accessToken['access_token'])) {
throw new InvalidParamException('The work access_token must be set.');
} elseif (!isset($accessToken['expire'])) {
throw new InvalidParamException('Work access_token expire time must be set.');
}
$this->access_token = $accessToken['access_token'];
$this->access_token_expire = $accessToken['expire'];
}
protected function GetOauth2Url ($appid, $redirectUri, $state, $scope = self::SNSAPI_BASE)
{
return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$redirectUri}&response_type=code&scope={$scope}&state={$state}#wechat_redirect";
}
/* 成员管理 */
/**
* 创建成员
*
* @link https://work.weixin.qq.com/api/doc/90000/90135/90195
*
* @param User $user
*
* @return array|null
*
* @throws \ParameterError
* @throws \QyApiError
*/
public function userCreate (User $user)
{
User::CheckUserCreateArgs($user);
$args = Utils::Object2Array($user);
self::_HttpCall(self::USER_CREATE, 'POST', $args);
return $this->repJson;
}
/**
* 读取成员
*
* @link https://work.weixin.qq.com/api/doc/90000/90135/90196
*
* @param string $userId
*
* @return User
*
* @throws \ParameterError
* @throws \QyApiError
*/
public function userGet ($userId)
{
Utils::checkNotEmptyStr($userId, 'userid');
self::_HttpCall(self::USER_GET, 'GET', ['userid' => $userId]);
return User::parseFromArray($this->repJson);
}
/**
* 更新成员
*
* @link https://work.weixin.qq.com/api/doc/90000/90135/90197
*
* @param User $user
*
* @return array|null
*
* @throws \ParameterError
* @throws \QyApiError
*/
public function userUpdata (User $user)
{
User::CheckUserUpdateArgs($user);
$args = Utils::Object2Array($user);
self::_HttpCall(self::USER_UPDATE, 'POST', $args);
return $this->repJson;
}
/**
* 删除成员
*
* @link https://work.weixin.qq.com/api/doc/90000/90135/90198
*
* @param string $userId
*
* @return array|null
*
* @throws \ParameterError
* @throws \QyApiError
*/
public function userDelete ($userId)
{
Utils::checkNotEmptyStr($userId, 'userid');
self::_HttpCall(self::USER_DELETE, 'GET', ['userid' => $userId]);
return $this->repJson;
}
public function userBatchDelete (array $userIdList)
{
User::CheckUserBatchDeleteArgs($userIdList);
self::_HttpCall(self::USER_BATCH_DELETE, 'POST', ['useridlist' => $userIdList]);
return $this->repJson;
}
public function userSimpleList ($deparmentId, $fetchChild = 0)
{
self::_HttpCall(self::USER_SIMPLE_LIST, 'GET', ['department_id' => $deparmentId, 'fetch_child' => $fetchChild]);
return User::Array2UserList($this->repJson);
}
public function userList ($deparmentId, $fetchChild = 0)
{
self::_HttpCall(self::USER_LIST, 'GET', ['department_id' => $deparmentId, 'fetch_child' => $fetchChild]);
return User::Array2UserList($this->repJson);
}
public function userConvertToOpenid ($userId, &$openid)
{
Utils::checkNotEmptyStr($userId, 'userid');
self::_HttpCall(self::USER_CONVERT_TO_OPENID, 'POST', ['userid' => $userId]);
$openid = Utils::arrayGet($this->repJson, 'openid');
}
public function userConvertTouserId ($openid, &$userId)
{
Utils::checkNotEmptyStr($openid, 'openid');
self::_HttpCall(self::USER_CONVERT_TO_USERID, 'POST', ['openid' => $openid]);
$userId = Utils::arrayGet($this->repJson, 'userid');
}
public function externalConvertToOpenid ($externalUserid, &$openid)
{
Utils::checkNotEmptyStr($externalUserid, 'external_userid');
self::_HttpCall(self::EXTERNAL_CONTACT_CONVER_TO_OPENID, 'POST', ['external_userid' => $externalUserid]);
$openid = Utils::arrayGet($this->repJson, 'openid');
}
public function userAuthSuccess ($userId)
{
Utils::checkNotEmptyStr($userId, 'userid');
self::_HttpCall(self::USER_AUTHSUCC, 'GET', ['userid' => $userId]);
return $this->repJson;
}
private function getInvalidList (&$invalidUserIdList, &$invalidPartyIdList, &$invalidTagIdList)
{
$invalidUserIdList = Utils::arrayGet($this->repJson, "invaliduser");
if (strpos($invalidUserIdList, '|') !== false) {
$invalidUserIdList = explode('|', $invalidUserIdList);
}
$invalidPartyIdList = Utils::arrayGet($this->repJson, "invalidparty");
if (strpos($invalidPartyIdList, '|') !== false) {
$invalidPartyIdList = explode('|', $invalidPartyIdList);
}
$invalidTagIdList = Utils::arrayGet($this->repJson, "invalidtag");
if (strpos($invalidTagIdList, '|') !== false) {
$invalidTagIdList = explode('|', $invalidTagIdList);
}
}
public function batchInvite ($userIdList = NULL, $partyIdList = NULL, $tagIdList = NULL, &$invalidUserIdList, &$invalidPartyIdList, &$invalidTagIdList)
{
if (!Utils::notEmptyArray($userIdList) && !Utils::notEmptyArray($partyIdList) && !Utils::notEmptyArray($tagIdList)) {
throw new \QyApiError('input can not be all null');
}
$args = [];
if (Utils::notEmptyArray($userIdList)) {
$args['user'] = $userIdList;
}
if (Utils::notEmptyArray($partyIdList)) {
$args['party'] = $partyIdList;
}
if (Utils::notEmptyArray($tagIdList)) {
$args['tag'] = $tagIdList;
}
self::_HttpCall(self::BATCH_INVITE, 'POST', $args);
$this->getInvalidList($invalidUserIdList, $invalidPartyIdList, $invalidTagIdList);
}
public function corpGetJoinQrcode (&$joinQrcode, $sizeType = NULL)
{
$args = [];
if (!is_null($sizeType)) {
$args['size_type'] = $sizeType;
}
self::_HttpCall(self::CORP_GET_JOIN_QECODE, 'GET', $args);
$joinQrcode = Utils::arrayGet($this->repJson, 'join_qrcode');
}
public function getMobileHashcode (&$mobile, $state = '')
{
Utils::checkIsUInt($mobile, 'mobile');
self::_HttpCall(self::GET_MOBILE_HASHCODE, 'POST', ['mobile' => $mobile, 'state' => $state]);
$mobile = Utils::arrayGet($this->repJson, 'hashcode');
}
/* 部门管理 */
public function departmentCreate (Department $department, &$departmentId)
{
Department::CheckDepartmentCreateArgs($department);
$args = Department::department2Array($department);
self::_HttpCall(self::DEPARTMENT_CREATE, 'POST', $args);
$departmentId = Utils::arrayGet($this->repJson, 'id');
}
public function departmentUpdate (Department $department)
{
Department::CheckDepartmentUpdateArgs($department);
$args = Department::department2Array($department);
self::_HttpCall(self::DEPARTMENT_UPDATE, 'POST', $args);
return $this->repJson;
}
public function departmentDelete ($departmentId)
{
Utils::checkIsUInt($departmentId, 'departmentid');
self::_HttpCall(self::DEPARTMENT_DELETE, 'GET', ['id' => $departmentId]);
return $this->repJson;
}
public function departmentList ($departmentId = NULL)
{
$args = [];
if (!is_null($departmentId)) {
$args['id'] = $departmentId;
}
self::_HttpCall(self::DEPARTMENT_LIST, 'GET', $args);
return Department::Array2DepartmentList($this->repJson);
}
/* 标签管理 */
public function tagCreate (Tag $tag, &$tagId)
{
Tag::CheckTagCreateArgs($tag);
$args = Tag::Tag2Array($tag);
self::_HttpCall(self::TAG_CREATE, 'POST', $args);
$tagId = Utils::arrayGet($this->repJson, 'tagid');
}
public function tagUpdate (Tag $tag)
{
Tag::CheckTagUpdateArgs($tag);
$args = Tag::Tag2Array($tag);
self::_HttpCall(self::TAG_UPDATE, 'POST', $args);
return $this->repJson;
}
public function tagDelete ($tagId)
{
Utils::checkIsUInt($tagId, 'tagid');
self::_HttpCall(self::TAG_DELETE, 'GET', ['tagid' => $tagId]);
return $this->repJson;
}
public function tagGet ($tagId)
{
Utils::checkIsUInt($tagId, 'tagid');
self::_HttpCall(self::TAG_GET, 'GET', ['tagid' => $tagId]);
return Tag::parseFromArray($this->repJson);
}
public function tagAddTagUsers ($tagId, $userIdList = [], $partyIdList = [])
{
Tag::CheckTagADUserArgs($tagId, $userIdList, $partyIdList);
$args = Tag::ToTagADUserArray($tagId, $userIdList, $partyIdList);
self::_HttpCall(self::TAG_ADD_TAG_USERS, 'POST', $args);
return $this->repJson;
}
public function tagDelTagUsers ($tagId, $userIdList = [], $partyIdList = [])
{
Tag::CheckTagADUserArgs($tagId, $userIdList, $partyIdList);
$args = Tag::ToTagADUserArray($tagId, $userIdList, $partyIdList);
self::_HttpCall(self::TAG_DEL_TAG_USERS, 'POST', $args);
return $this->repJson;
}
public function tagList ()
{
self::_HttpCall(self::TAG_LIST);
return Tag::Array2TagList($this->repJson);
}
/* 异步批量接口 */
private function batchJob (BatchJobArgs $batchJobArgs, $jobType)
{
Batch::CheckBatchJobArgs($batchJobArgs);
$args = Utils::Object2Array($batchJobArgs);
$url = '';
switch ($jobType) {
case 'syncsuser':
$url = self::BATCH_SYNC_USER;
break;
case 'replaceuser':
$url = self::BATCH_REPLACE_USER;
break;
case 'replaceparty':
$url = self::BATCH_REPLACE_PARTY;
break;
default:
break;
}
if (!Utils::notEmptyStr($url)) {
throw new \QyApiError('job type not invlide.');
}
self::_HttpCall($url, 'POST');
return Utils::arrayGet($this->repJson, 'jobid');
}
public function batchSyncUser (BatchJobArgs $batchJobArgs)
{
return self::batchJob($batchJobArgs, 'syncuser');
}
public function batchReplaceUser (BatchJobArgs $batchJobArgs)
{
return self::batchJob($batchJobArgs, 'replaceuser');
}
public function batchReplaceParty (BatchJobArgs $batchJobArgs)
{
return self::batchJob($batchJobArgs, 'replaceparty');
}
public function batchGetResult ($jobId)
{
Utils::checkNotEmptyStr($jobId, 'jobid');
self::_HttpCall(self::BATCH_GET_RESULT, 'GET', ['jobid' => $jobId]);
return Batch::parseFromArray($this->repJson);
}
/* 企业服务人员管理 */
public function ECGetFollowUserList ()
{
self::_HttpCall(self::EXTERNAL_CONTACT_GET_FOLLOW_USER_LIST);
return $this->repJson;
}
public function ECAddContactWay (ExternalContactWay $externalContactWay)
{
ExternalContactWay::CheckExternalContactWayAddArgs($externalContactWay);
$args = Utils::Object2EmptyArray($externalContactWay);
self::_HttpCall(self::EXTERNAL_CONTACT_ADD_CONTACT_WAY, 'POST', $args);
return $this->repJson;
}
public function ECGetContactWay ($configId)
{
Utils::checkNotEmptyStr($configId, 'config_id');
self::_HttpCall(self::EXTERNAL_CONTACT_GET_CONTACT_WAY, 'POST', ['config_id' => $configId]);
return ExternalContact::wayParseFromArray($this->repJson);
}
public function ECGetUserInfo ($userId)
{
Utils::checkNotEmptyStr($userId, 'userid');
self::_HttpCall(self::USER_GET, 'GET', ['userid' => $userId]);
return $this->repJson;
}
public function ECUpdateContactWay (ExternalContactWay $externalContactWay)
{
ExternalContactWay::CheckExternalContactWayUpdateArgs($externalContactWay);
$args = Utils::Object2EmptyArray($externalContactWay);
self::_HttpCall(self::EXTERNAL_CONTACT_UPDATE_CONTACT_WAY, 'POST', $args);
return $this->repJson;
}
public function ECDelContactWay ($configId)
{
Utils::checkNotEmptyStr($configId, 'config_id');
self::_HttpCall(self::EXTERNAL_CONTACT_DEL_CONTACT_WAY, 'POST', ['config_id' => $configId]);
return $this->repJson;
}
/* 客户管理 */
public function ECList ($userId)
{
Utils::checkNotEmptyStr($userId, 'userid');
self::_HttpCall(self::EXTERNAL_CONTACT_LIST, 'GET', ['userid' => $userId]);
return $this->repJson;
}
public function ECGet ($externalUserId)
{
Utils::checkNotEmptyStr($externalUserId, 'external userid');
self::_HttpCall(self::EXTERNAL_CONTACT_GET, 'GET', ['external_userid' => $externalUserId]);
$externalContact = Utils::arrayGet($this->repJson, 'external_contact');
$externalContact['follow_user'] = Utils::arrayGet($this->repJson, 'follow_user');
return ExternalContact::parseFromArray($externalContact);
}
public function ECBatchGetByUser (ExternalContactBatchGetByUser $batchGetByUser)
{
ExternalContactBatchGetByUser::CheckExternalContactBatchGetByUserArgs($batchGetByUser);
$args = Utils::Object2EmptyArray($batchGetByUser);
self::_HttpCall(self::EXTERNAL_CONTACT_BATCH_GET_BY_USER, 'POST', $args);
$externalContactListInfo = [
'external_contact_list' => Utils::arrayGet($this->repJson, 'external_contact_list'),
'next_cursor' => Utils::arrayGet($this->repJson, 'next_cursor')
];
return $externalContactListInfo;
}
public function ECRemark (ExternalContactRemark $externalContactRemark)
{
ExternalContactRemark::CheckExternalContactRmarkArgs($externalContactRemark);
$args = Utils::Object2EmptyArray($externalContactRemark);
self::_HttpCall(self::EXTERNAL_CONTACT_REMARK, 'POST', $args);
return $this->repJson;
}
/* 客户标签管理 */
public function ECGetCorpTagList ($tagIdList = NULL)
{
$args = [];
if (!is_null($tagIdList)) {
Utils::checkNotEmptyArray($tagIdList, 'tag id list');
$args['tag_id'] = $tagIdList;
}
self::_HttpCall(self::EXTERNAL_CONTACT_GET_CORP_TAG_LIST, 'POST', $args);
return ExternalContactTagGroup::arrayToTagGroup($this->repJson);
}
public function ECAddCorpTag (ExternalContactTagGroup $tagGroup)
{
ExternalContactTagGroup::checkExternalContactTagGroupAddArgs($tagGroup);
$args = Utils::Object2Array($tagGroup);
self::_HttpCall(self::EXTERNAL_CONTACT_ADD_CORP_TAG, 'POST', $args);
return ExternalContactTagGroup::parseFromArray(Utils::arrayGet($this->repJson, 'tag_group'));
}
public function ECEditCorpTag (ExternalContactTag $tag)
{
ExternalContactTag::checkExternalContactTagEditArgs($tag);
$args = Utils::Object2Array($tag);
self::_HttpCall(self::EXTERNAL_CONTACT_EDIT_CORP_TAG, 'POST', $args);
return $this->repJson;
}
public function ECDelCorpTag ($tagIdList = [], $groupIdList = [])
{
if (!Utils::notEmptyArray($tagIdList) && !Utils::notEmptyArray($groupIdList)) {
throw new \QyApiError('input error paramter.');
}
$args = [];
if (Utils::notEmptyArray($tagIdList)) {
$args['tag_id'] = $tagIdList;
}
if (Utils::notEmptyArray($groupIdList)) {
$args['group_id'] = $groupIdList;
}
self::_HttpCall(self::EXTERNAL_CONTACT_DEL_CORP_TAG, 'POST', $args);
return $this->repJson;
}
public function ECMarkTag ($userId, $externalUserId, $addTagList = [], $removeTagList = [])
{
Utils::checkNotEmptyStr($userId, 'user id');
Utils::checkNotEmptyStr($externalUserId, 'external user id');
if (!Utils::notEmptyArray($addTagList) && !Utils::notEmptyArray($removeTagList)) {
throw new \QyApiError('input error paramter.');
}
$args = [
'userid' => $userId,
'external_userid' => $externalUserId
];
if (Utils::notEmptyArray($addTagList)) {
$args['add_tag'] = $addTagList;
}
if (Utils::notEmptyArray($removeTagList)) {
$args['remove_tag'] = $removeTagList;
}
self::_HttpCall(self::EXTERNAL_CONTACT_MARK_TAG, 'POST', $args);
return $this->repJson;
}
//获取规则组列表
public function ECStrategyList ($limit = 1000, $cursor = '')
{
$args = [
'cursor' => $cursor,
'limit' => $limit,
];
self::_HttpCall(self::EXTERNAL_CONTACT_STRATEGY_LIST, 'POST', $args);
return $this->repJson;
}
//获取规则组详情
public function ECStrategyGet ($strategyId)
{
$args = [
'strategy_id' => $strategyId
];
self::_HttpCall(self::EXTERNAL_CONTACT_STRATEGY_GET, 'POST', $args);
return $this->repJson;
}
//获取规则组管理范围
public function ECStrategyGetRange ($strategyId, $limit = 1000, $cursor = '')
{
$args = [
'strategy_id' => $strategyId,
'cursor' => $cursor,
'limit' => $limit,
];
self::_HttpCall(self::EXTERNAL_CONTACT_STRATEGY_GET_RANGE, 'POST', $args);
return $this->repJson;
}
//创建新的规则组
public function ECStrategyCreate ($args)
{
self::_HttpCall(self::EXTERNAL_CONTACT_STRATEGY_CREATE, 'POST', $args);
return $this->repJson;
}
//编辑规则组及其管理范围
public function ECStrategyEdit ($args)
{
self::_HttpCall(self::EXTERNAL_CONTACT_STRATEGY_EDIT, 'POST', $args);
return $this->repJson;
}
//删除规则组
public function ECStrategyDel ($strategyId)
{
$args = [
'strategy_id' => $strategyId
];
self::_HttpCall(self::EXTERNAL_CONTACT_STRATEGY_DEL, 'POST', $args);
return $this->repJson;
}
// TODO: 还需要优化
public function ECGroupChatList ($offset = 0, $limit = 100, $statusFilter = 0, $ownerFilter = [])
{
$args = [
'status_filter' => $statusFilter,
'offset' => $offset,
'limit' => $limit,
];
if (Utils::notEmptyArray($ownerFilter)) {
$args['owner_filter'] = $ownerFilter;
}
self::_HttpCall(self::EXTERNAL_CONTACT_GROUP_CHAT_LIST, 'POST', $args);
return $this->repJson;
}
public function ECGroupChatStaticTime ($s_time, $e_time, $ownerIds)
{
$args = [
'day_begin_time' => $s_time,
'day_end_time' => $e_time,
'owner_filter' => [
"userid_list" => $ownerIds
],
];
Utils::checkNotEmptyArray($ownerIds, 'userid_list');
self::_HttpCall(self::EXTERNAL_CONTACT_GROUP_CHAT_STATIC_GET, 'POST', $args);
return $this->repJson;
}
public function ECGroupChatGet ($chatId, $needName = 0)
{
Utils::checkNotEmptyStr($chatId, 'chat_id');
self::_HttpCall(self::EXTERNAL_CONTACT_GROUP_CHAT_GET, 'POST', ['chat_id' => $chatId, 'need_name' => $needName]);
return ExternalContactGroupChat::parseFromArray(Utils::arrayGet($this->repJson, 'group_chat'));
}
public function ECAddMsgTemplate (ExternalContactMsgTemplate $msgTemplate)
{
ExternalContactMsgTemplate::checkMsgTemplateAddArgs($msgTemplate);
$args = Utils::Object2Array($msgTemplate);
self::_HttpCall(self::EXTERNAL_CONTACT_ADD_MSG_TEMPLATE, "POST", $args);
return $this->repJson;
}
public function ECGetGroupMsgResult ($msgId)
{
Utils::checkNotEmptyStr($msgId, 'msgid');
self::_HttpCall(self::EXTERNAL_CONTACT_GET_GROUP_MSG_RESULT, 'POST', ['msgid' => $msgId]);
return $this->repJson;
}
public function ECGetGroupMsgTask ($sendData)
{
Utils::checkNotEmptyStr($sendData['msgid'] ?? '', 'msgid');
self::_HttpCall(self::EXTERNAL_CONTACT_GET_GROUP_MSG_TASK, 'POST', $sendData);
return $this->repJson;
}
public function ECGetGroupmsgSendResult ($sendData)
{
Utils::checkNotEmptyStr($sendData['msgid'] ?? '', 'msgid');
Utils::checkNotEmptyStr($sendData['userid'] ?? '', 'userid');
self::_HttpCall(self::EXTERNAL_CONTACT_GET_GROUPMSG_SEND_RESULT, 'POST', $sendData);
return $this->repJson;
}
public function ECRemindGroupmsgSend ($sendData)
{
Utils::checkNotEmptyStr($sendData['msgid'] ?? '', 'msgid');
self::_HttpCall(self::EXTERNAL_CONTACT_REMIND_GROUPMSG_SEND, 'POST', $sendData);
return $this->repJson;
}
public function ECCancelGroupmsgSend ($sendData)
{
Utils::checkNotEmptyStr($sendData['msgid'] ?? '', 'msgid');
self::_HttpCall(self::EXTERNAL_CONTACT_CANCEL_GROUPMSG_SEND, 'POST', $sendData);
return $this->repJson;
}
public function ECSendWelcomeMsg (ExternalContactMsgTemplate $msgTemplate)
{
ExternalContactMsgTemplate::checkMsgTemplateSendArgs($msgTemplate);
$args = Utils::Object2Array($msgTemplate);
self::_HttpCall(self::EXTERNAL_CONTACT_SEND_WELCOME_MSG, "POST", $args);
return $this->repJson;
}
public function ECGroupWelcomeTemplateAdd (ExternalContactMsgTemplate $msgTemplate)
{
ExternalContactMsgTemplate::checkGroupWelcomeTemplateAddArgs($msgTemplate);
if (isset($msgTemplate->notify)) {
$notify = $msgTemplate->notify;
}
$args = Utils::Object2Array($msgTemplate);
if (isset($notify)) {
$args['notify'] = $notify;
}
self::_HttpCall(self::EXTERNAL_CONTACT_GROUP_WELCOME_TEMPLATE_ADD, "POST", $args);
return $this->repJson;
}
public function ECGroupWelcomeTemplateEdit (ExternalContactMsgTemplate $msgTemplate)
{
ExternalContactMsgTemplate::checkGroupWelcomeTemplateEditArgs($msgTemplate);
$args = Utils::Object2Array($msgTemplate);
self::_HttpCall(self::EXTERNAL_CONTACT_GROUP_WELCOME_TEMPLATE_EDIT, "POST", $args);
return $this->repJson;
}
public function ECGroupWelcomeTemplateGet ($templateId)
{
Utils::checkNotEmptyStr($templateId, 'template_id');
self::_HttpCall(self::EXTERNAL_CONTACT_GROUP_WELCOME_TEMPLATE_GET, "POST", ['template_id' => $templateId]);
return ExternalContactMsgTemplate::parseFromArray($this->repJson);
}
public function ECGroupWelcomeTemplateDel ($templateId)
{
Utils::checkNotEmptyStr($templateId, 'template_id');
self::_HttpCall(self::EXTERNAL_CONTACT_GROUP_WELCOME_TEMPLATE_DEL, "POST", ['template_id' => $templateId]);
return $this->repJson;
}
public function ECGetUnAssignedList ($pageId = 0, $pageSize = 1000)
{
self::_HttpCall(self::EXTERNAL_CONTACT_GET_UNASSIGNED_LIST, 'POST', ['page_id' => $pageId, 'page_size' => $pageSize]);
return ExternalContactUnAssignUser::arrayToUnAssignUserInfo($this->repJson);
}
public function ECGetUnAssignedListPage ($pageId = 0, $pageSize = 1000, $cursor = '')
{
$params['page_size'] = $pageSize;
if (!empty($cursor)) {
mb_strlen($cursor) > 1 && $params['cursor'] = $cursor;
} else {
$params['page_id'] = $pageId;
}
self::_HttpCall(self::EXTERNAL_CONTACT_GET_UNASSIGNED_LIST, 'POST', $params);
return $this->repJson;
}
public function ECCalendarAdd ($params)
{
self::_HttpCall(self::CALENDAR_ADD, 'POST', $params);
return $this->repJson;
}
public function ECCalendarGet ($params)
{
self::_HttpCall(self::CALENDAR_GET, 'POST', $params);
return $this->repJson;
}
public function ECScheduleAdd ($params)
{
self::_HttpCall(self::OA_SCHEDULE_ADD, 'POST', $params);
return $this->repJson;
}
public function ECScheduleGet ($params)
{
self::_HttpCall(self::OA_SCHEDULE_GET, 'POST', $params);
return $this->repJson;
}
public function ECAddJoinWay ($params)
{
self::_HttpCall(self::ADD_JOIN_WAY, 'POST', $params);
return $this->repJson;
}
public function ECGetJoinWay ($params)
{
self::_HttpCall(self::GET_JOIN_WAY, 'POST', $params);
return $this->repJson;
}
public function ECUpdateJoinWay ($params)
{
self::_HttpCall(self::UPDATE_JOIN_WAY, 'POST', $params);
return $this->repJson;
}
public function getSpModuleDetail ($t_id)
{
$args = [
'template_id' => $t_id,
];
self::_HttpCall(self::SERVICE_GET_SP_MODULE_DETAIL, 'POST', $args);
return $this->repJson;
}
public function getApprovalList ($data)
{
$args = [
'starttime' => $data['startTime'],
'endtime' => $data['endTime'],
'cursor' => $data['cursor'],
'size' => $data['size'],
];
self::_HttpCall(self::OA_GET_APPROVAL_INFO, 'POST', $args);