1
0
mirror of https://gitee.com/zoujingli/ThinkAdmin.git synced 2025-04-06 03:58:04 +08:00

优化微信自动回复规则

This commit is contained in:
邹景立 2021-04-12 10:21:49 +08:00
parent 395b557835
commit a6c05c859b
6 changed files with 20 additions and 10 deletions

@ -24,7 +24,7 @@ class Auto extends Command
*/ */
protected function configure() protected function configure()
{ {
$this->setName('xadmin:fanauto'); $this->setName('xadmin:fansmsg');
$this->addArgument('openid', Argument::OPTIONAL, 'wechat user openid', ''); $this->addArgument('openid', Argument::OPTIONAL, 'wechat user openid', '');
$this->addArgument('autocode', Argument::OPTIONAL, 'wechat auto message', ''); $this->addArgument('autocode', Argument::OPTIONAL, 'wechat auto message', '');
$this->setDescription('Wechat Users Push AutoMessage for ThinkAdmin'); $this->setDescription('Wechat Users Push AutoMessage for ThinkAdmin');
@ -71,7 +71,7 @@ class Auto extends Command
private function _buildMessage(array $data) private function _buildMessage(array $data)
{ {
$type = strtolower($data['type']); $type = strtolower($data['type']);
$result = [0, '待发的消息不符合规则']; $result = [0, '待发的消息不符合规则'];
if ($type === 'text' && !empty($data['content'])) { if ($type === 'text' && !empty($data['content'])) {
$result = $this->_sendMessage('text', ['content' => $data['content']]); $result = $this->_sendMessage('text', ['content' => $data['content']]);
} }
@ -87,9 +87,9 @@ class Auto extends Command
} }
if ($type === 'news') { if ($type === 'news') {
[$item, $news] = [MediaService::instance()->news($data['news_id']), []]; [$item, $news] = [MediaService::instance()->news($data['news_id']), []];
if (!empty($item['articles'])) { if (isset($item['articles']) && is_array($item['articles'])) {
$host = sysconf('base.site_host'); $host = sysconf('base.site_host') ?: true;
foreach ($item['articles'] as $vo) array_push($news, [ foreach ($item['articles'] as $vo) if (empty($news)) array_push($news, [
'url' => url("@wechat/api.view/item/id/{$vo['id']}", [], false, $host)->build(), 'url' => url("@wechat/api.view/item/id/{$vo['id']}", [], false, $host)->build(),
'title' => $vo['title'], 'picurl' => $vo['local_url'], 'description' => $vo['digest'], 'title' => $vo['title'], 'picurl' => $vo['local_url'], 'description' => $vo['digest'],
]); ]);
@ -128,7 +128,7 @@ class Auto extends Command
WechatService::WeChatCustom()->send([ WechatService::WeChatCustom()->send([
$type => $data, 'touser' => $this->openid, 'msgtype' => $type, $type => $data, 'touser' => $this->openid, 'msgtype' => $type,
]); ]);
return [1, '微信消息推送成功']; return [1, '微信用户推送消息成功'];
} catch (\Exception $exception) { } catch (\Exception $exception) {
return [0, $exception->getMessage()]; return [0, $exception->getMessage()];
} }

@ -24,8 +24,8 @@ class AutoService extends Service
{ {
foreach ($this->app->db->name('WechatAuto')->where(['status' => 1])->order('time asc')->cursor() as $vo) { foreach ($this->app->db->name('WechatAuto')->where(['status' => 1])->order('time asc')->cursor() as $vo) {
$time = $this->parseTimeString($vo['time']); $time = $this->parseTimeString($vo['time']);
$name = "延迟向 {$openid} 推送 {$vo['code']} 客服消息"; $name = "延迟向用户 {$openid} 推送 {$vo['code']} 客服消息";
QueueService::instance()->register($name, "xadmin:fanauto {$openid} {$vo['code']}", $time); QueueService::instance()->register($name, "xadmin:fansmsg {$openid} {$vo['code']}", $time);
} }
} }

@ -11,7 +11,11 @@
{/block} {/block}
{block name='content'} {block name='content'}
<div class="think-box-shadow"> <div class="layui-badge think-bg-violet text-left notselect block shadow margin-0 padding-10 padding-left-20 border-radius-5 font-s15">
特别注意:关注自动回复使用微信客服消息接口发送,因此多图文只能发送每一篇文章,另外还需要开启系统任务功能。
</div>
<div class="think-box-shadow margin-top-10">
{include file='auto/index_search'} {include file='auto/index_search'}
<table class="layui-table margin-top-10" lay-skin="line"> <table class="layui-table margin-top-10" lay-skin="line">
{notempty name='list'} {notempty name='list'}

@ -258,7 +258,9 @@ return array(
'app\\data\\service\\payment\\VoucherPaymentService' => $baseDir . '/app/data/service/payment/VoucherPaymentService.php', 'app\\data\\service\\payment\\VoucherPaymentService' => $baseDir . '/app/data/service/payment/VoucherPaymentService.php',
'app\\data\\service\\payment\\WechatPaymentService' => $baseDir . '/app/data/service/payment/WechatPaymentService.php', 'app\\data\\service\\payment\\WechatPaymentService' => $baseDir . '/app/data/service/payment/WechatPaymentService.php',
'app\\index\\controller\\Index' => $baseDir . '/app/index/controller/Index.php', 'app\\index\\controller\\Index' => $baseDir . '/app/index/controller/Index.php',
'app\\wechat\\command\\Auto' => $baseDir . '/app/wechat/command/Auto.php',
'app\\wechat\\command\\Fans' => $baseDir . '/app/wechat/command/Fans.php', 'app\\wechat\\command\\Fans' => $baseDir . '/app/wechat/command/Fans.php',
'app\\wechat\\controller\\Auto' => $baseDir . '/app/wechat/controller/Auto.php',
'app\\wechat\\controller\\Config' => $baseDir . '/app/wechat/controller/Config.php', 'app\\wechat\\controller\\Config' => $baseDir . '/app/wechat/controller/Config.php',
'app\\wechat\\controller\\Fans' => $baseDir . '/app/wechat/controller/Fans.php', 'app\\wechat\\controller\\Fans' => $baseDir . '/app/wechat/controller/Fans.php',
'app\\wechat\\controller\\Keys' => $baseDir . '/app/wechat/controller/Keys.php', 'app\\wechat\\controller\\Keys' => $baseDir . '/app/wechat/controller/Keys.php',
@ -269,6 +271,7 @@ return array(
'app\\wechat\\controller\\api\\Push' => $baseDir . '/app/wechat/controller/api/Push.php', 'app\\wechat\\controller\\api\\Push' => $baseDir . '/app/wechat/controller/api/Push.php',
'app\\wechat\\controller\\api\\Test' => $baseDir . '/app/wechat/controller/api/Test.php', 'app\\wechat\\controller\\api\\Test' => $baseDir . '/app/wechat/controller/api/Test.php',
'app\\wechat\\controller\\api\\View' => $baseDir . '/app/wechat/controller/api/View.php', 'app\\wechat\\controller\\api\\View' => $baseDir . '/app/wechat/controller/api/View.php',
'app\\wechat\\service\\AutoService' => $baseDir . '/app/wechat/service/AutoService.php',
'app\\wechat\\service\\FansService' => $baseDir . '/app/wechat/service/FansService.php', 'app\\wechat\\service\\FansService' => $baseDir . '/app/wechat/service/FansService.php',
'app\\wechat\\service\\MediaService' => $baseDir . '/app/wechat/service/MediaService.php', 'app\\wechat\\service\\MediaService' => $baseDir . '/app/wechat/service/MediaService.php',
'app\\wechat\\service\\WechatService' => $baseDir . '/app/wechat/service/WechatService.php', 'app\\wechat\\service\\WechatService' => $baseDir . '/app/wechat/service/WechatService.php',

@ -387,7 +387,9 @@ class ComposerStaticInit6dcb8a18f830adceacf76408fbd14a53
'app\\data\\service\\payment\\VoucherPaymentService' => __DIR__ . '/../..' . '/app/data/service/payment/VoucherPaymentService.php', 'app\\data\\service\\payment\\VoucherPaymentService' => __DIR__ . '/../..' . '/app/data/service/payment/VoucherPaymentService.php',
'app\\data\\service\\payment\\WechatPaymentService' => __DIR__ . '/../..' . '/app/data/service/payment/WechatPaymentService.php', 'app\\data\\service\\payment\\WechatPaymentService' => __DIR__ . '/../..' . '/app/data/service/payment/WechatPaymentService.php',
'app\\index\\controller\\Index' => __DIR__ . '/../..' . '/app/index/controller/Index.php', 'app\\index\\controller\\Index' => __DIR__ . '/../..' . '/app/index/controller/Index.php',
'app\\wechat\\command\\Auto' => __DIR__ . '/../..' . '/app/wechat/command/Auto.php',
'app\\wechat\\command\\Fans' => __DIR__ . '/../..' . '/app/wechat/command/Fans.php', 'app\\wechat\\command\\Fans' => __DIR__ . '/../..' . '/app/wechat/command/Fans.php',
'app\\wechat\\controller\\Auto' => __DIR__ . '/../..' . '/app/wechat/controller/Auto.php',
'app\\wechat\\controller\\Config' => __DIR__ . '/../..' . '/app/wechat/controller/Config.php', 'app\\wechat\\controller\\Config' => __DIR__ . '/../..' . '/app/wechat/controller/Config.php',
'app\\wechat\\controller\\Fans' => __DIR__ . '/../..' . '/app/wechat/controller/Fans.php', 'app\\wechat\\controller\\Fans' => __DIR__ . '/../..' . '/app/wechat/controller/Fans.php',
'app\\wechat\\controller\\Keys' => __DIR__ . '/../..' . '/app/wechat/controller/Keys.php', 'app\\wechat\\controller\\Keys' => __DIR__ . '/../..' . '/app/wechat/controller/Keys.php',
@ -398,6 +400,7 @@ class ComposerStaticInit6dcb8a18f830adceacf76408fbd14a53
'app\\wechat\\controller\\api\\Push' => __DIR__ . '/../..' . '/app/wechat/controller/api/Push.php', 'app\\wechat\\controller\\api\\Push' => __DIR__ . '/../..' . '/app/wechat/controller/api/Push.php',
'app\\wechat\\controller\\api\\Test' => __DIR__ . '/../..' . '/app/wechat/controller/api/Test.php', 'app\\wechat\\controller\\api\\Test' => __DIR__ . '/../..' . '/app/wechat/controller/api/Test.php',
'app\\wechat\\controller\\api\\View' => __DIR__ . '/../..' . '/app/wechat/controller/api/View.php', 'app\\wechat\\controller\\api\\View' => __DIR__ . '/../..' . '/app/wechat/controller/api/View.php',
'app\\wechat\\service\\AutoService' => __DIR__ . '/../..' . '/app/wechat/service/AutoService.php',
'app\\wechat\\service\\FansService' => __DIR__ . '/../..' . '/app/wechat/service/FansService.php', 'app\\wechat\\service\\FansService' => __DIR__ . '/../..' . '/app/wechat/service/FansService.php',
'app\\wechat\\service\\MediaService' => __DIR__ . '/../..' . '/app/wechat/service/MediaService.php', 'app\\wechat\\service\\MediaService' => __DIR__ . '/../..' . '/app/wechat/service/MediaService.php',
'app\\wechat\\service\\WechatService' => __DIR__ . '/../..' . '/app/wechat/service/WechatService.php', 'app\\wechat\\service\\WechatService' => __DIR__ . '/../..' . '/app/wechat/service/WechatService.php',

2
vendor/services.php vendored

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2021-04-08 14:28:47 // This file is automatically generated at:2021-04-12 10:21:13
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\admin\\Library', 0 => 'think\\admin\\Library',