diff --git a/module/webhook/tao.php b/module/webhook/tao.php new file mode 100644 index 0000000000..4cb1c4b938 --- /dev/null +++ b/module/webhook/tao.php @@ -0,0 +1,90 @@ + + * @package kanban + * @version $Id: model.php 5118 2021-10-22 10:18:41Z $ + * @link https://www.zentao.net + */ +class webhookTao extends webhookModel +{ + /** + * 获取钉钉的密钥。 + * Get the secret of dingding. + * + * @param object $webhook + * @access public + * @return object|false + */ + protected function getDingdingSecret(object $webhook): object|false + { + $webhook->secret = array(); + $webhook->secret['agentId'] = $webhook->agentId; + $webhook->secret['appKey'] = $webhook->appKey; + $webhook->secret['appSecret'] = $webhook->appSecret; + + if(empty($webhook->agentId)) dao::$errors['agentId'] = sprintf($this->lang->error->notempty, $this->lang->webhook->dingAgentId); + if(empty($webhook->appKey)) dao::$errors['appKey'] = sprintf($this->lang->error->notempty, $this->lang->webhook->dingAppKey); + if(empty($webhook->appSecret)) dao::$errors['appSecret'] = sprintf($this->lang->error->notempty, $this->lang->webhook->dingAppSecret); + if(dao::isError()) return false; + + $webhook->secret = json_encode($webhook->secret); + $webhook->url = $this->config->webhook->dingapiUrl; + + return $webhook; + } + + /** + * 获取微信的密钥。 + * Get the secret of wechat. + * + * @param object $webhook + * @access public + * @return object|false + */ + protected function getWechatSecret(object $webhook): object|false + { + $webhook->secret = array(); + $webhook->secret['agentId'] = $webhook->wechatAgentId; + $webhook->secret['appKey'] = $webhook->wechatCorpId; + $webhook->secret['appSecret'] = $webhook->wechatCorpSecret; + + if(empty($webhook->wechatCorpId)) dao::$errors['wechatCorpId'] = sprintf($this->lang->error->notempty, $this->lang->webhook->wechatCorpId); + if(empty($webhook->wechatCorpSecret)) dao::$errors['wechatCorpSecret'] = sprintf($this->lang->error->notempty, $this->lang->webhook->wechatCorpSecret); + if(empty($webhook->wechatAgentId)) dao::$errors['wechatAgentId'] = sprintf($this->lang->error->notempty, $this->lang->webhook->wechatAgentId); + if(dao::isError()) return false; + + $webhook->secret = json_encode($webhook->secret); + $webhook->url = $this->config->webhook->wechatApiUrl; + + return $webhook; + } + + /** + * 获取飞书的密钥。 + * Get the secret of feishu. + * + * @param object $webhook + * @access public + * @return object|false + */ + protected function getFeishuSecret(object $webhook): object|false + { + $webhook->secret = array(); + $webhook->secret['appId'] = $webhook->feishuAppId; + $webhook->secret['appSecret'] = $webhook->feishuAppSecret; + + if(empty($webhook->feishuAppId)) dao::$errors['feishuAppId'] = sprintf($this->lang->error->notempty, $this->lang->webhook->feishuAppId); + if(empty($webhook->feishuAppSecret)) dao::$errors['feishuAppSecret'] = sprintf($this->lang->error->notempty, $this->lang->webhook->feishuAppSecret); + if(dao::isError()) return false; + + $webhook->secret = json_encode($webhook->secret); + $webhook->url = $this->config->webhook->feishuApiUrl; + + return $webhook; + } +} diff --git a/module/webhook/test/model/create.php b/module/webhook/test/model/create.php index 2d67438920..508f22f915 100755 --- a/module/webhook/test/model/create.php +++ b/module/webhook/test/model/create.php @@ -4,83 +4,84 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/webhook.class.php'; su('admin'); +zdTable('webhook')->gen(7); + /** title=测试 webhookModel->create(); +timeout=0 cid=1 -pid=1 -测试全部传入的正常创建 >> 8 -测试不传type的情况 >> 9 -测试不传name的情况 >> 『名称』不能为空。 -测试不传url的情况 >> 『Hook地址』不能为空。 -测试不传secret的情况 >> 10 -测试不传domain的情况 >> 11 -测试不传sendType的情况 >> 『发送方式』不符合格式,应当为:『/sync|async/』。 -测试不传products的情况 >> 12 -测试不传executions的情况 >> 13 -测试不传desc的情况 >> 14 +- 测试全部传入的正常创建 @8 +- 测试不传type的情况 @9 +- 测试不传name的情况第name条的0属性 @『名称』不能为空。 +- 测试不传url的情况第url条的0属性 @『Hook地址』不能为空。 +- 测试不传secret的情况 @10 +- 测试不传domain的情况 @11 +- 测试不传sendType的情况第sendType条的0属性 @『发送方式』不符合格式,应当为:『/sync|async/』。 +- 测试不传products的情况 @12 +- 测试不传executions的情况 @13 */ -$webhook = new webhookTest(); +$webhookTest = new webhookTest(); -$post = array(); -$post['type'] = 'dinggroup'; -$post['name'] = '新加的webhook'; -$post['url'] = 'https://open.feishu.cn/open-apis/bot/v2/hook/173bdc6e-6f37-476d-8134-fd25752f00f3'; -$post['secret'] = 'cs0iInSMVWAqhPPL8BcVjf'; -$post['agentId'] = ''; -$post['appKey'] = ''; -$post['appSecret'] = ''; -$post['wechatCorpId'] = ''; -$post['wechatCorpSecret'] = ''; -$post['wechatAgentId'] = ''; -$post['feishuAppId'] = ''; -$post['feishuAppSecret'] = ''; -$post['domain'] = 'http://www.zentaopms.com'; -$post['sendType'] = 'sync'; -$post['products'] = array('0' => 100); -$post['executions'] = array('0' => 700); -$post['desc'] = '当你老了~~~'; +$webhook = new stdclass(); +$webhook->type = 'dinggroup'; +$webhook->name = '新加的webhook'; +$webhook->url = 'https://open.feishu.cn/open-apis/bot/v2/hook/173bdc6e-6f37-476d-8134-fd25752f00f3'; +$webhook->secret = 'cs0iInSMVWAqhPPL8BcVjf'; +$webhook->agentId = ''; +$webhook->appKey = ''; +$webhook->appSecret = ''; +$webhook->wechatCorpId = ''; +$webhook->wechatCorpSecret = ''; +$webhook->wechatAgentId = ''; +$webhook->feishuAppId = ''; +$webhook->feishuAppSecret = ''; +$webhook->domain = 'http://www.zentaopms.com'; +$webhook->sendType = 'sync'; +$webhook->products = '100'; +$webhook->executions = '700'; +$webhook->desc = '测试描述'; -$post1 = $post; -$post1['type'] = ''; +$webhook1 = clone $webhook; +$webhook1->type = ''; -$post2 = $post; -$post2['name'] = ''; +$webhook2 = clone $webhook; +$webhook2->name = ''; -$post3 = $post; -$post3['url'] = ''; +$webhook3 = clone $webhook; +$webhook3->url = ''; -$post4 = $post; -$post4['secret'] = ''; +$webhook4 = clone $webhook; +$webhook4->secret = ''; -$post5 = $post; -$post5['domain'] = ''; +$webhook5 = clone $webhook; +$webhook5->domain = ''; -$post6 = $post; -$post6['sendType'] = ''; +$webhook6 = clone $webhook; +$webhook6->sendType = ''; -$post7 = $post; -$post7['products'] = ''; +$webhook7 = clone $webhook; +$webhook7->products = ''; -$post8 = $post; -$post8['executions'] = ''; +$webhook8 = clone $webhook; +$webhook8->executions = ''; -$post9 = $post; -$post9['desc'] = ''; +$webhook9 = clone $webhook; +$webhook9->desc = ''; -$result1 = $webhook->createTest($post); -$result2 = $webhook->createTest($post1); -$result3 = $webhook->createTest($post2); -$result4 = $webhook->createTest($post3); -$result5 = $webhook->createTest($post4); -$result6 = $webhook->createTest($post5); -$result7 = $webhook->createTest($post6); -$result8 = $webhook->createTest($post7); -$result9 = $webhook->createTest($post8); -$result10 = $webhook->createTest($post9); +$result1 = $webhookTest->createTest($webhook); +$result2 = $webhookTest->createTest($webhook1); +$result3 = $webhookTest->createTest($webhook2); +$result4 = $webhookTest->createTest($webhook3); +$result5 = $webhookTest->createTest($webhook4); +$result6 = $webhookTest->createTest($webhook5); +$result7 = $webhookTest->createTest($webhook6); +$result8 = $webhookTest->createTest($webhook7); +$result9 = $webhookTest->createTest($webhook8); +$result10 = $webhookTest->createTest($webhook9); r($result1) && p() && e('8'); //测试全部传入的正常创建 r($result2) && p() && e('9'); //测试不传type的情况 @@ -91,4 +92,4 @@ r($result6) && p() && e('11'); r($result7) && p('sendType:0') && e('『发送方式』不符合格式,应当为:『/sync|async/』。'); //测试不传sendType的情况 r($result8) && p() && e('12'); //测试不传products的情况 r($result9) && p() && e('13'); //测试不传executions的情况 -R($result10) && p() && e('14'); //测试不传desc的情况 +R($result10) && p() && e('14'); //测试不传desc的情况 \ No newline at end of file diff --git a/module/webhook/test/webhook.class.php b/module/webhook/test/webhook.class.php index 93bc26c0cd..20fa2e8f58 100644 --- a/module/webhook/test/webhook.class.php +++ b/module/webhook/test/webhook.class.php @@ -126,35 +126,13 @@ class webhookTest return $objects; } - public function createTest($webhooks) + public function createTest($webhook) { - $posts = array(); - $posts['type'] = ''; - $posts['name'] = ''; - $posts['url'] = ''; - $posts['secret'] = ''; - $posts['agentId'] = ''; - $posts['appKey'] = ''; - $posts['appSecret'] = ''; - $posts['wechatCorpId'] = ''; - $posts['wechatCorpSecret'] = ''; - $posts['wechatAgentId'] = ''; - $posts['feishuAppId'] = ''; - $posts['feishuAppSecret'] = ''; - $posts['domain'] = ''; - $posts['sendType'] = ''; - $posts['products'] = array(); - $posts['executions'] = array(); - $posts['desc'] = ''; - - foreach($posts as $field => $defaultvalue) $_POST[$field] = $defaultvalue; - foreach($webhooks as $key => $value) $_POST[$key] = $value; - - $objects = $this->objectModel->create(); + $objectID = $this->objectModel->create($webhook); if(dao::isError()) return dao::getError(); - return $objects; + return $objectID; } /** diff --git a/module/webhook/ui/create.html.php b/module/webhook/ui/create.html.php index 7c3814ef7e..dc213f30cc 100644 --- a/module/webhook/ui/create.html.php +++ b/module/webhook/ui/create.html.php @@ -63,6 +63,7 @@ foreach($fields as $field => $attr) if($field == 'agentId' || $field == 'appKey' || $field == 'appSecret') $required = true; if($field == 'feishuAppId' || $field == 'feishuAppSecret') $required = true; if($field == 'wechatCorpId' || $field == 'wechatCorpSecret' || $field == 'wechatAgentId') $required = true; + if($field == 'type') $required = true; $formItems[] = formRow (