feat(wechat): 微信机器人全链路集成与稳定性修复
- 新增:管理员后台的微信机器人双向收发参数设置页面及扫码绑定能力。 - 新增:WechatBotApiService 与 KafkaConsumerService 模块打通过往僵尸进程导致的拒绝连接问题。 - 新增:下发所有群发/私聊通知时统一带上「[和平聊吧]」标注前缀。 - 优化:前端个人中心绑定逻辑支持一键生成及复制动态口令。 - 修复:闭环联调修补各个模型中产生的变量警告如 stdClass 对象获取等异常预警。
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:异步发送微信机器人消息任务
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\SysParam;
|
||||
use App\Services\WechatBot\WechatBotApiService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SendWechatBotMessage implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var string 目标 wxid 或 群组 ID (@chatroom)
|
||||
*/
|
||||
protected string $target;
|
||||
|
||||
/**
|
||||
* @var string 要发送的消息内容
|
||||
*/
|
||||
protected string $message;
|
||||
|
||||
/**
|
||||
* 队列任务构造函数
|
||||
*
|
||||
* @param string $target 目标用户或群聊
|
||||
* @param string $message 正文内容
|
||||
*/
|
||||
public function __construct(string $target, string $message)
|
||||
{
|
||||
$this->target = $target;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务
|
||||
*/
|
||||
public function handle(WechatBotApiService $apiService): void
|
||||
{
|
||||
if (empty($this->target)) {
|
||||
Log::warning('WechatBot: Target is empty, skipping message dispatch.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$params = SysParam::where('alias', 'wechat_bot_config')->first();
|
||||
if ($params && ! empty($params->body)) {
|
||||
$config = json_decode($params->body, true);
|
||||
$isEnabled = $config['global_enabled'] ?? false;
|
||||
|
||||
if (! $isEnabled) {
|
||||
return; // 全局未开启,直接抛弃不发
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$apiService->sendTextMessage($this->target, $this->message);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('WechatBot: Failed to send message in queue', [
|
||||
'target' => $this->target,
|
||||
'message' => $this->message,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user