From 1790aedf9ef3e9a5510e4c3f618b8954ffb1f6e4 Mon Sep 17 00:00:00 2001 From: sunguangming Date: Wed, 20 Dec 2023 19:45:47 +0800 Subject: [PATCH] * webhook: refactor create(). --- module/webhook/model.php | 64 ++++++++++------------------------------ 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/module/webhook/model.php b/module/webhook/model.php index 134cc4de9f..068f31c0aa 100644 --- a/module/webhook/model.php +++ b/module/webhook/model.php @@ -173,74 +173,42 @@ class webhookModel extends model } /** + * 创建webhook。 * Create a webhook. * + * @param object $webhook + * * @access public - * @return bool + * @return int|false */ - public function create() + public function create(object $webhook): int|false { - $webhook = fixer::input('post') - ->add('createdBy', $this->app->user->account) - ->add('createdDate', helper::now()) - ->join('products', ',') - ->join('executions', ',') - ->skipSpecial('url') - ->trim('agentId,appKey,appSecret,wechatAgentId,wechatCorpId,wechatCorpSecret,feishuAppId,feishuAppSecret') - ->remove('allParams, allActions') - ->get(); - $webhook->domain = trim($webhook->domain, '/'); - $webhook->params = $this->post->params ? implode(',', $this->post->params) . ',text' : 'text'; + $webhook->createdBy = $this->app->user->account; + $webhook->createdDate = helper::now(); + $webhook->domain = trim($webhook->domain, '/'); + $webhook->params = $this->post->params ? implode(',', $this->post->params) . ',text' : 'text'; if($webhook->type == 'dinguser') { - $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; + $webhook = $this->webhookTao->getDingdingSecret($webhook); } elseif($webhook->type == 'wechatuser') { - $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; + $webhook = $this->webhookTao->getWeixinSecret($webhook); } elseif($webhook->type == 'feishuuser') { - $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; + $webhook = $this->webhookTao->getFeishuSecret($webhook); } + if(dao::isError()) return false; + $this->dao->insert(TABLE_WEBHOOK)->data($webhook, 'agentId,appKey,appSecret,wechatCorpId,wechatCorpSecret,wechatAgentId,feishuAppId,feishuAppSecret') ->batchCheck($this->config->webhook->create->requiredFields, 'notempty') ->autoCheck() ->exec(); - return $this->dao->lastInsertId(); + + return $this->dao->lastInsertID(); } /**