From ee3cc5d76b33dfdf9f7980eae422f9dbd65176e8 Mon Sep 17 00:00:00 2001 From: sunguangming Date: Thu, 21 Dec 2023 09:15:29 +0800 Subject: [PATCH] * webhook: refactor update. --- module/webhook/model.php | 55 ++++++++-------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/module/webhook/model.php b/module/webhook/model.php index 068f31c0aa..88f1ebcc35 100644 --- a/module/webhook/model.php +++ b/module/webhook/model.php @@ -212,68 +212,33 @@ class webhookModel extends model } /** + * 编辑webhook。 * Update a webhook. * * @param int $id + * @param object $webhook * @access public * @return bool */ - public function update($id) + public function update(int $id, object $webhook): bool { - $webhook = fixer::input('post') - ->add('editedBy', $this->app->user->account) - ->add('editedDate', helper::now()) - ->setDefault('products', '') - ->setDefault('executions', '') - ->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'; + $webhook->editedBy = $this->app->user->account; + $webhook->editedDate = helper::now(); + $webhook->domain = trim($webhook->domain, '/'); + $webhook->params = $this->post->params ? implode(',', $this->post->params) : 'text'; if(!str_contains($webhook->params, 'text')) $webhook->params .= ',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 = $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 = $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 = $this->webhookTao->getFeishuSecret($webhook); } $this->dao->update(TABLE_WEBHOOK)->data($webhook, 'agentId,appKey,appSecret,wechatCorpId,wechatCorpSecret,wechatAgentId,feishuAppId,feishuAppSecret')