tao.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * The tao file of webhook module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2021 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  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@easycorp.ltd>
  8. * @package kanban
  9. * @version $Id: model.php 5118 2021-10-22 10:18:41Z $
  10. * @link https://www.zentao.net
  11. */
  12. class webhookTao extends webhookModel
  13. {
  14. /**
  15. * 获取钉钉的密钥。
  16. * Get the secret of dingding.
  17. *
  18. * @param object $webhook
  19. * @access public
  20. * @return object|false
  21. */
  22. protected function getDingdingSecret($webhook)
  23. {
  24. $webhook->secret = array();
  25. $webhook->secret['agentId'] = $webhook->agentId;
  26. $webhook->secret['appKey'] = $webhook->appKey;
  27. $webhook->secret['appSecret'] = $webhook->appSecret;
  28. if(empty($webhook->agentId)) dao::$errors['agentId'] = sprintf($this->lang->error->notempty, $this->lang->webhook->dingAgentId);
  29. if(empty($webhook->appKey)) dao::$errors['appKey'] = sprintf($this->lang->error->notempty, $this->lang->webhook->dingAppKey);
  30. if(empty($webhook->appSecret)) dao::$errors['appSecret'] = sprintf($this->lang->error->notempty, $this->lang->webhook->dingAppSecret);
  31. if(dao::isError()) return false;
  32. $webhook->secret = json_encode($webhook->secret);
  33. $webhook->url = $this->config->webhook->dingapiUrl;
  34. return $webhook;
  35. }
  36. /**
  37. * 获取微信的密钥。
  38. * Get the secret of wechat.
  39. *
  40. * @param object $webhook
  41. * @access public
  42. * @return object|false
  43. */
  44. protected function getWeixinSecret($webhook)
  45. {
  46. $webhook->secret = array();
  47. $webhook->secret['agentId'] = $webhook->wechatAgentId;
  48. $webhook->secret['appKey'] = $webhook->wechatCorpId;
  49. $webhook->secret['appSecret'] = $webhook->wechatCorpSecret;
  50. if(empty($webhook->wechatCorpId)) dao::$errors['wechatCorpId'] = sprintf($this->lang->error->notempty, $this->lang->webhook->wechatCorpId);
  51. if(empty($webhook->wechatCorpSecret)) dao::$errors['wechatCorpSecret'] = sprintf($this->lang->error->notempty, $this->lang->webhook->wechatCorpSecret);
  52. if(empty($webhook->wechatAgentId)) dao::$errors['wechatAgentId'] = sprintf($this->lang->error->notempty, $this->lang->webhook->wechatAgentId);
  53. if(dao::isError()) return false;
  54. $webhook->secret = json_encode($webhook->secret);
  55. $webhook->url = $this->config->webhook->wechatApiUrl;
  56. return $webhook;
  57. }
  58. /**
  59. * 获取飞书的密钥。
  60. * Get the secret of feishu.
  61. *
  62. * @param object $webhook
  63. * @access public
  64. * @return object|false
  65. */
  66. protected function getFeishuSecret($webhook)
  67. {
  68. $webhook->secret = array();
  69. $webhook->secret['appId'] = $webhook->feishuAppId;
  70. $webhook->secret['appSecret'] = $webhook->feishuAppSecret;
  71. if(empty($webhook->feishuAppId)) dao::$errors['feishuAppId'] = sprintf($this->lang->error->notempty, $this->lang->webhook->feishuAppId);
  72. if(empty($webhook->feishuAppSecret)) dao::$errors['feishuAppSecret'] = sprintf($this->lang->error->notempty, $this->lang->webhook->feishuAppSecret);
  73. if(dao::isError()) return false;
  74. $webhook->secret = json_encode($webhook->secret);
  75. $webhook->url = $this->config->webhook->feishuApiUrl;
  76. return $webhook;
  77. }
  78. /**
  79. * 获取动作的文本。
  80. * Get the text of action.
  81. *
  82. * @param object $data
  83. * @param object $action
  84. * @param object $object
  85. * @param array $users
  86. * @access public
  87. * @return string
  88. */
  89. protected function getActionText($data, $action, $object, $users)
  90. {
  91. $text = '';
  92. if(isset($data->markdown->text))
  93. {
  94. $text = substr($data->markdown->text, 0, strpos($data->markdown->text, '(http'));
  95. }
  96. elseif(isset($data->markdown->content))
  97. {
  98. $text = substr($data->markdown->content, 0, strpos($data->markdown->content, '(http'));
  99. }
  100. elseif(isset($data->text->content))
  101. {
  102. $text = substr($data->text->content, 0, strpos($data->text->content, '(http'));
  103. }
  104. elseif(isset($data->card->elements))
  105. {
  106. $text = $data->card->elements[0]->content;
  107. $text = substr($text, 0, strpos($text, '(http')) ? substr($text, 0, strpos($text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]";
  108. }
  109. elseif(isset($data->content))
  110. {
  111. $text = empty($data->content->text) ? '' : (string)$data->content->text;
  112. $text = substr($text, 0, strpos($text, '(http')) ? substr($text, 0, strpos($text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]";
  113. }
  114. else
  115. {
  116. $text = substr($data->text, 0, strpos($data->text, '(http')) ? substr($data->text, 0, strpos($data->text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]";
  117. }
  118. return $text;
  119. }
  120. }