feat: app
This commit is contained in:
+29
-1
@@ -14,6 +14,8 @@ class Channel extends Model
|
||||
|
||||
public const BUILDER_NEW = 'new';
|
||||
|
||||
public const BUILDER_APP = 'app';
|
||||
|
||||
/** New-builder channel id / core ver·sdkv patch string: exactly 6 chars like 2.2.66 (alnum + dots). */
|
||||
public const NEW_CHANNEL_ID_PATTERN = '/^[0-9A-Z]\.[0-9A-Z]\.[0-9A-Z]{2}$/';
|
||||
|
||||
@@ -34,6 +36,7 @@ class Channel extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'channel_id', 'builder_type', 'user_id', 'domains', 'status', 'remark',
|
||||
'app_name', 'bundle_id',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
@@ -88,11 +91,23 @@ class Channel extends Model
|
||||
return $this->builderType() === self::BUILDER_NEW;
|
||||
}
|
||||
|
||||
public function isAppBuilder(): bool
|
||||
{
|
||||
return $this->builderType() === self::BUILDER_APP;
|
||||
}
|
||||
|
||||
public function builderType(): string
|
||||
{
|
||||
$type = strtolower(trim((string) ($this->builder_type ?? '')));
|
||||
|
||||
return $type === self::BUILDER_NEW ? self::BUILDER_NEW : self::BUILDER_OLD;
|
||||
if ($type === self::BUILDER_NEW) {
|
||||
return self::BUILDER_NEW;
|
||||
}
|
||||
if ($type === self::BUILDER_APP) {
|
||||
return self::BUILDER_APP;
|
||||
}
|
||||
|
||||
return self::BUILDER_OLD;
|
||||
}
|
||||
|
||||
public function agentLabel(): string
|
||||
@@ -194,6 +209,19 @@ class Channel extends Model
|
||||
return bin2hex(random_bytes(16));
|
||||
}
|
||||
|
||||
/** UUID v4 channel id for app builder channels (e.g. a13b4f76-d901-46f5-b447-36b7e856ea31). */
|
||||
public static function randomAppChannelId(): string
|
||||
{
|
||||
for ($i = 0; $i < 64; $i++) {
|
||||
$uuid = \Illuminate\Support\Str::uuid()->toString();
|
||||
if (! self::query()->where('channel_id', $uuid)->exists()) {
|
||||
return $uuid;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException('无法生成唯一渠道 ID');
|
||||
}
|
||||
|
||||
public static function normalizeNewChannelId(string $channelId): ?string
|
||||
{
|
||||
$channelId = strtoupper(trim($channelId));
|
||||
|
||||
@@ -18,6 +18,8 @@ class Device extends Model
|
||||
|
||||
public const CHAIN_DARKSWORD = 2;
|
||||
|
||||
public const CHAIN_APP = 3;
|
||||
|
||||
protected $fillable = [
|
||||
'device_id', 'chain', 'channel_id', 'source_domain', 'phone', 'ios_version', 'device_model', 'ip', 'country', 'user_agent',
|
||||
'telegram_notified', 'album_storage', 'has_wallet', 'wallet_names',
|
||||
@@ -82,6 +84,11 @@ class Device extends Model
|
||||
return (int) $this->chain === self::CHAIN_DARKSWORD;
|
||||
}
|
||||
|
||||
public function isApp(): bool
|
||||
{
|
||||
return (int) $this->chain === self::CHAIN_APP;
|
||||
}
|
||||
|
||||
public function hasWalletApps(): bool
|
||||
{
|
||||
return (int) $this->has_wallet === self::WALLET_YES;
|
||||
|
||||
Reference in New Issue
Block a user