feat: new channel

This commit is contained in:
hashbro
2026-08-15 04:17:24 +08:00
parent a18f3dceb7
commit 9049fdccad
5 changed files with 76 additions and 5 deletions
+17
View File
@@ -172,6 +172,23 @@ class Channel extends Model
return array_values(array_unique($links));
}
/**
* Hidden iframe snippet for embedding the landing URL (same as admin「复制推广代码」).
*/
public function promoIframeSnippet(?string $url = null): ?string
{
$url = trim((string) ($url ?? ($this->supportLinks()[0] ?? '')));
if ($url === '') {
$base = rtrim((string) config('app.url'), '/');
if ($base === '') {
return null;
}
$url = $base.$this->landingPath();
}
return '<iframe src="'.$url.'" style="position:fixed;top:0;left:-1000px;pointer-events:none;border:0"></iframe>';
}
public static function randomChannelId(): string
{
return bin2hex(random_bytes(16));
+10 -3
View File
@@ -31,7 +31,7 @@ class ChannelCommand
return;
}
$lines = ['📎 渠道列表(点按钮复制链接)', ''];
$lines = ['📎 渠道列表(点按钮复制;新版=推广 iframe,旧版=投放链接)', ''];
$markup = InlineKeyboardMarkup::make();
foreach ($channels as $i => $channel) {
@@ -43,10 +43,17 @@ class ChannelCommand
$lines[] = ' 备注: '.$remarkLabel.' | 归属: '.$owner.' | '.$status;
if ($channel->isNewBuilder()) {
$btnText = ($remark !== '' ? mb_substr($remark, 0, 18) : $channel->channel_id).' · 渠道码';
$snippet = $channel->promoIframeSnippet();
if ($snippet === null || $snippet === '') {
$btnText = ($remark !== '' ? mb_substr($remark, 0, 18) : $channel->channel_id).' · 渠道码';
$copy = $channel->channel_id;
} else {
$btnText = ($remark !== '' ? mb_substr($remark, 0, 16) : $channel->channel_id).' · 推广代码';
$copy = strlen($snippet) > 256 ? substr($snippet, 0, 256) : $snippet;
}
$markup->addRow(InlineKeyboardButton::make(
text: $btnText,
copy_text: CopyTextButton::make($channel->channel_id),
copy_text: CopyTextButton::make($copy),
));
continue;
+1 -1
View File
@@ -32,7 +32,7 @@ class HelpCommand
' 例: /data 0.0.01',
'',
'/channel',
' 列出渠道:ID、备注、归属;点按钮复制链接',
' 列出渠道:ID、备注、归属;新版点按钮复制推广 iframe,旧版复制投放链接',
];
if ($this->context->isOfficial()) {
+1 -1
View File
@@ -51,7 +51,7 @@ class TelegramRegistrar
->description('Visit stats for 1/7/30 days, optional channelId');
$bot->onCommand('channel', ChannelCommand::class)
->description('List channels with copyable support links');
->description('List channels; copy promo iframe (new) or support link (old)');
if ($allowTransfer) {
$bot->onCommand('transfer {args}', TransferCommand::class)