From 7938f6de0f190c276f1cd5eb61a065a4b4ac38aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= <4349951+zoujingli@users.noreply.github.com> Date: Mon, 10 May 2021 12:51:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/wechat/command/Auto.php | 20 +++++++++----------- app/wechat/command/Fans.php | 1 - 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/wechat/command/Auto.php b/app/wechat/command/Auto.php index aa9951b06..455b1595a 100644 --- a/app/wechat/command/Auto.php +++ b/app/wechat/command/Auto.php @@ -33,7 +33,6 @@ class Auto extends Command /** * @param Input $input * @param Output $output - * @return void * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException * @throws \think\admin\Exception @@ -54,13 +53,12 @@ class Auto extends Command if (empty($data)) $this->setQueueError("Message Data Query failed"); // 发送微信客服消息 - $this->_buildMessage($data); + $this->buildMessage($data); } /** * 关键字处理 * @param array $data - * @return void * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException * @throws \think\admin\Exception @@ -68,21 +66,21 @@ class Auto extends Command * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - private function _buildMessage(array $data) + private function buildMessage(array $data) { $type = strtolower($data['type']); $result = [0, '待发送的消息不符合规则']; if ($type === 'text' && !empty($data['content'])) { - $result = $this->_sendMessage('text', ['content' => $data['content']]); + $result = $this->sendMessage('text', ['content' => $data['content']]); } if ($type === 'voice' && !empty($data['voice_url'])) { if ($mediaId = MediaService::instance()->upload($data['voice_url'], 'voice')) { - $result = $this->_sendMessage('voice', ['media_id' => $mediaId]); + $result = $this->sendMessage('voice', ['media_id' => $mediaId]); } } if ($type === 'image' && !empty($data['image_url'])) { if ($mediaId = MediaService::instance()->upload($data['image_url'], 'image')) { - $result = $this->_sendMessage('image', ['media_id' => $mediaId]); + $result = $this->sendMessage('image', ['media_id' => $mediaId]); } } if ($type === 'news') { @@ -93,12 +91,12 @@ class Auto extends Command 'url' => url("@wechat/api.view/item/id/{$vo['id']}", [], false, $host)->build(), 'title' => $vo['title'], 'picurl' => $vo['local_url'], 'description' => $vo['digest'], ]); - $result = $this->_sendMessage('news', ['articles' => $news]); + $result = $this->sendMessage('news', ['articles' => $news]); } } if ($type === 'music' && !empty($data['music_url']) && !empty($data['music_title']) && !empty($data['music_desc'])) { $mediaId = $data['music_image'] ? MediaService::instance()->upload($data['music_image'], 'image') : ''; - $result = $this->_sendMessage('music', [ + $result = $this->sendMessage('music', [ 'hqmusicurl' => $data['music_url'], 'musicurl' => $data['music_url'], 'description' => $data['music_desc'], 'title' => $data['music_title'], 'thumb_media_id' => $mediaId, ]); @@ -106,7 +104,7 @@ class Auto extends Command if ($type === 'video' && !empty($data['video_url']) && !empty($data['video_desc']) && !empty($data['video_title'])) { $video = ['title' => $data['video_title'], 'introduction' => $data['video_desc']]; if ($mediaId = MediaService::instance()->upload($data['video_url'], 'video', $video)) { - $result = $this->_sendMessage('video', ['media_id' => $mediaId, 'title' => $data['video_title'], 'description' => $data['video_desc']]); + $result = $this->sendMessage('video', ['media_id' => $mediaId, 'title' => $data['video_title'], 'description' => $data['video_desc']]); } } if (empty($result[0])) { @@ -122,7 +120,7 @@ class Auto extends Command * @param array $data 消息对象 * @return array */ - private function _sendMessage(string $type, array $data): array + private function sendMessage(string $type, array $data): array { try { WechatService::WeChatCustom()->send([ diff --git a/app/wechat/command/Fans.php b/app/wechat/command/Fans.php index 8c625aa26..6f484e020 100644 --- a/app/wechat/command/Fans.php +++ b/app/wechat/command/Fans.php @@ -47,7 +47,6 @@ class Fans extends Command * 执行指令 * @param Input $input * @param Output $output - * @return void * @throws \think\admin\Exception */ protected function execute(Input $input, Output $output)