M5: Workerman 常驻服务 + AI 审核/润色插件 + 支付插件(支付宝/微信/沙箱)+ 会员插件(套餐/订阅/付费文章)

This commit is contained in:
ak
2026-08-11 18:29:35 +08:00
parent f77c96d3aa
commit 1d1df43cee
52 changed files with 1914 additions and 20 deletions
@@ -0,0 +1,64 @@
<?php
namespace Plugins\Neatstudio\AiModeration;
use App\Blog\Jobs\AiJob;
use App\Blog\Services\LlmClient;
use App\Blog\Support\WorkermanBroadcaster;
use App\Models\Comment;
use Illuminate\Support\Facades\Log;
class AiModerateCommentJob implements AiJob
{
public function __construct(public int $commentId)
{
}
public function handle(LlmClient $llm): void
{
$comment = Comment::with('post')->find($this->commentId);
if (! $comment || $comment->status !== Comment::STATUS_PENDING) {
return;
}
WorkermanBroadcaster::send('ai.moderation.started', ['comment_id' => $this->commentId]);
$system = (string) blog_setting('ai_moderation_system_prompt', '你是博客评论审核员。判断评论是否包含:广告/垃圾、人身攻击、违法内容、无关灌水。只回复 JSON{"verdict":"approved|rejected|spam","reason":"简短理由"}');
try {
$raw = $llm->chat([
['role' => 'system', 'content' => $system],
['role' => 'user', 'content' => '文章标题:'.($comment->post?->title ?? '')."\n\n评论内容:\n".$comment->content],
], ['max_tokens' => 200]);
$verdict = $this->parseVerdict($raw);
$comment->update([
'status' => $verdict === 'approved' ? Comment::STATUS_PUBLISHED : ($verdict === 'spam' ? Comment::STATUS_SPAM : Comment::STATUS_REJECTED),
'ai_review' => ['source' => 'llm', 'raw' => $raw, 'reviewed_at' => now()->toIso8601String()],
]);
if ($verdict === 'approved') {
$comment->post?->increment('comment_count');
}
WorkermanBroadcaster::send('ai.moderation.finished', [
'comment_id' => $this->commentId,
'verdict' => $verdict,
]);
} catch (\Throwable $e) {
Log::error('AI 评论审核失败', ['comment' => $this->commentId, 'error' => $e->getMessage()]);
WorkermanBroadcaster::send('ai.moderation.failed', ['comment_id' => $this->commentId, 'error' => $e->getMessage()]);
}
}
private function parseVerdict(string $raw): string
{
if (preg_match('/"verdict"\s*:\s*"(approved|rejected|spam)"/', $raw, $m)) {
return $m[1];
}
return 'rejected';
}
}
@@ -0,0 +1,35 @@
<?php
namespace Plugins\Neatstudio\AiModeration;
use App\Blog\Jobs\AiJob;
use App\Blog\Services\LlmClient;
use App\Models\Post;
class AiPolishContentJob implements AiJob
{
public function __construct(public int $postId)
{
}
public function handle(LlmClient $llm): void
{
$post = Post::find($this->postId);
if (! $post) {
return;
}
$source = $post->content_format === 'markdown'
? $post->content
: (new \League\HTMLToMarkdown\HtmlConverter())->convert($post->content);
$polished = $llm->chat([
['role' => 'system', 'content' => '你是中文博客编辑。润色下面的文章,保持原意、事实、Markdown 结构不变,改进表达、语法、可读性。直接输出润色后的完整 Markdown。'],
['role' => 'user', 'content' => $source],
], ['max_tokens' => 4000]);
// 润色结果暂存,后台点击「采纳」时写回
$post->update(['meta' => array_merge($post->meta ?? [], ['ai_polished' => $polished])]);
}
}