- 新增:管理员后台的微信机器人双向收发参数设置页面及扫码绑定能力。 - 新增:WechatBotApiService 与 KafkaConsumerService 模块打通过往僵尸进程导致的拒绝连接问题。 - 新增:下发所有群发/私聊通知时统一带上「[和平聊吧]」标注前缀。 - 优化:前端个人中心绑定逻辑支持一键生成及复制动态口令。 - 修复:闭环联调修补各个模型中产生的变量警告如 stdClass 对象获取等异常预警。
79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:测试发送微信机器人消息
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Models\SysParam;
|
||
use App\Services\WechatBot\WechatBotApiService;
|
||
use Illuminate\Console\Command;
|
||
|
||
class WechatBotTestSend extends Command
|
||
{
|
||
/**
|
||
* @var string
|
||
*/
|
||
protected $signature = 'wechat-bot:test-send';
|
||
|
||
/**
|
||
* @var string
|
||
*/
|
||
protected $description = '测试发送一条消息给管理员设定的微信群群 wxid';
|
||
|
||
/**
|
||
* Execute the console command.
|
||
*/
|
||
public function handle(): int
|
||
{
|
||
$this->info('开始测试微信机器人发送...');
|
||
|
||
$param = SysParam::where('alias', 'wechat_bot_config')->first();
|
||
if (! $param || empty($param->body)) {
|
||
$this->error('错误:未找到 wechat_bot_config 配置,请先在后台保存一次配置。');
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$config = json_decode($param->body, true);
|
||
$targetWxid = $config['group_notify']['target_wxid'] ?? '';
|
||
|
||
if (empty($targetWxid)) {
|
||
$this->error('错误:请于后台填写【目标微信群 Wxid】。');
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
if (empty($config['api']['bot_key'] ?? '')) {
|
||
$this->error('错误:未配置【机器人 Key (必需)】,API请求将被拒绝(返回该链接不存在)。');
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$service = new WechatBotApiService;
|
||
|
||
$this->info("发送目标: {$targetWxid}");
|
||
$this->info('发送 API Base: '.($config['api']['base_url'] ?? ''));
|
||
|
||
$message = "【系统连通性测试】\n发送时间:".now()->format('Y-m-d H:i:s')."\n如果您看到了这条消息,说明 ChatRoom 通知全站群发接口配置正确!";
|
||
|
||
$result = $service->sendTextMessage($targetWxid, $message);
|
||
|
||
if ($result['success']) {
|
||
$this->info('✅ 发送成功!');
|
||
|
||
return self::SUCCESS;
|
||
} else {
|
||
$this->error('❌ 发送失败:'.($result['error'] ?? '未知错误'));
|
||
$this->warn('如果提示『该链接不存在』代表您的基础API URL 或接入 Key 有误。');
|
||
|
||
return self::FAILURE;
|
||
}
|
||
}
|
||
}
|