zen.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * The zen file of webhook module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Sun Guangming<sunguangming@easysoft.ltd>
  8. * @package webhook
  9. * @link https://www.zentao.net
  10. */
  11. class webhookZen extends webhook
  12. {
  13. /**
  14. * 通过API获取人员列表。
  15. * Get users by API.
  16. *
  17. * @param object $webhook
  18. * @access public
  19. * @return array
  20. */
  21. protected function getResponse($webhook)
  22. {
  23. $response = array();
  24. $selectedDepts = $this->cookie->selectedDepts ? $this->cookie->selectedDepts : '';
  25. if($webhook->type == 'dinguser')
  26. {
  27. $this->app->loadClass('dingapi', true);
  28. $dingapi = new dingapi($webhook->secret->appKey, $webhook->secret->appSecret, $webhook->secret->agentId);
  29. $response = $dingapi->getUsers($selectedDepts);
  30. }
  31. elseif($webhook->type == 'wechatuser')
  32. {
  33. $this->app->loadClass('wechatapi', true);
  34. $wechatApi = new wechatapi($webhook->secret->appKey, $webhook->secret->appSecret, $webhook->secret->agentId);
  35. $response = $wechatApi->getAllUsers();
  36. }
  37. elseif($webhook->type == 'feishuuser')
  38. {
  39. $this->app->loadClass('feishuapi', true);
  40. $feishuApi = new feishuapi($webhook->secret->appId, $webhook->secret->appSecret);
  41. $response = $feishuApi->getAllUsers($selectedDepts);
  42. }
  43. $this->view->selectedDepts = $selectedDepts;
  44. return $response;
  45. }
  46. /**
  47. * 获取已绑定的open_id键值对,并追加未查询出的open_id。
  48. * Get bound open_id and name pairs, and append no fetch oauth users.
  49. *
  50. * @param object $webhook
  51. * @param array $users
  52. * @param array $boundUsers
  53. * @param array $oauthUsers
  54. * @access public
  55. * @return array
  56. */
  57. public function getBoundUseridPairs($webhook, $users, $boundUsers, $oauthUsers)
  58. {
  59. $boundUseridPairs = array();
  60. $useridPairs = array_flip($oauthUsers);
  61. $noFetchOauth = array();
  62. foreach($users as $user)
  63. {
  64. if(isset($boundUsers[$user->account])) $userid = $boundUsers[$user->account];
  65. if(isset($oauthUsers[$user->realname])) $userid = $oauthUsers[$user->realname];
  66. if(!isset($userid)) continue;
  67. if(!isset($useridPairs[$userid])) $noFetchOauth[$userid] = $userid;
  68. $boundUseridPairs[$userid] = zget($useridPairs, $userid);
  69. }
  70. if($noFetchOauth)
  71. {
  72. if($webhook->type == 'dinguser')
  73. {
  74. $this->app->loadClass('dingapi', true);
  75. $dingapi = new dingapi($webhook->secret->appKey, $webhook->secret->appSecret, $webhook->secret->agentId);
  76. foreach($dingapi->batchGetUsers($noFetchOauth) as $userid => $name) $boundUseridPairs[$userid] = $name;
  77. }
  78. elseif($webhook->type == 'feishuuser')
  79. {
  80. $this->app->loadClass('feishuapi', true);
  81. $feishuApi = new feishuapi($webhook->secret->appId, $webhook->secret->appSecret);
  82. foreach($feishuApi->batchGetUsers($noFetchOauth) as $openid => $name) $boundUseridPairs[$openid] = $name;
  83. }
  84. }
  85. return $boundUseridPairs;
  86. }
  87. }