danog/tg-file-decoder
Composer 安装命令:
composer create-project danog/tg-file-decoder
包简介
Decode Telegram bot API file IDs
README 文档
README
Decode and encode Telegram bot API file IDs!
This library was initially created for MadelineProto, an async PHP client API for the telegram MTProto protocol.
Install
composer require danog/tg-file-decoder
Examples:
Decoding bot API file IDs
use danog\Decoder\FileId; use danog\Decoder\UniqueFileId; $fileId = FileId::fromBotAPI('CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ'); $version = $fileId->version; // bot API file ID version, usually 4 $subVersion = $fileId->subVersion; // bot API file ID subversion, equivalent to a specific tdlib version $dcId = $fileId->dcId; // On which datacenter is this file stored $type = $fileId->type; // File type $id = $fileId->id; $accessHash = $fileId->accessHash; $fileReference = $fileId->fileReference; // File reference, https://core.telegram.org/api/file_reference $url = $fileId->url; // URL, file IDs with encoded webLocation // You can also use hasFileReference and hasUrl $fileIdReencoded = $fileId->getBotAPI(); // CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ $fileIdReencoded = (string) $fileId; // CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ // For photos, thumbnails if ($fileId->getType() <= FileIdType::PHOTO->value) $volumeId = $fileId->volumeId; $localId = $fileId->localId; $photoSizeSource = $fileId->photoSizeSource; // PhotoSizeSource object $photoSizeSource->dialogId; $photoSizeSource->stickerSetId; // And more, depending on photosize source
The bot API subversion, present since file IDs v4, is equivalent to the version of tdlib used server-side in the bot API.
For file types, see file types. For photosize source, see here.
Decoding bot API unique file IDs
$uniqueFileId = UniqueFileId::fromUniqueBotAPI('AgADrQEAArE4rFE'); $type = $fileId->type; // Unique file type $id = $uniqueFileId->id; $url = $uniqueFileId->url; // URL, for unique file IDs with encoded webLocation // For photos $volumeId = $uniqueFileId->volumeId; $localId = $uniqueFileId->localId;
For unique file types, see unique types.
Extracting unique file IDs from full file IDs
$full = 'CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ'; $unique = 'AgADrQEAArE4rFE'; $fileId = FileId::fromBotAPI($full); $uniqueFileId = UniqueFileId::fromUniqueBotAPI($unique); $uniqueFileIdExtracted1 = UniqueFileId::fromBotAPI($full); $uniqueFileIdExtracted2 = $fileId->getUniqueBotAPI(); var_dump(((string) $uniqueFileId) === ((string) $uniqueFileIdExtracted1)); // true, always AgADrQEAArE4rFE! var_dump(((string) $uniqueFileId) === ((string) $uniqueFileIdExtracted2)); // true, always AgADrQEAArE4rFE!
Photosize source
$fileId = FileId::fromString('CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ'); $photoSizeSource = $fileId->photoSizeSource; // PhotoSizeSource object $sourceType = $photoSizeSource->type; // If $sourceType === PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL|PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL or // If $photoSizeSource instanceof PhotoSizeSourceDialogPhoto $dialogId = $photoSizeSource->dialogId; $dialogId = $photoSizeSource->sticketSetId;
The PhotoSizeSource abstract base class indicates the source of a specific photosize from a chat photo, photo, stickerset thumbnail, file thumbnail.
Click here » to view the full list of PhotoSizeSource types.
Building custom file IDs
$fileId = new FileId( type: FileIdType::STICKER, id: $id, accessHash: $accessHash, // and so on... ); $encoded = (string) $fileId; // CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ, or something
Bot API file ID types
The file type is a PHP enum indicating the type of file, danog\Decoder\FileIdType.
Click here » to view the full list of file ID types.
The enum also offers a FileIdType::from method that can be used to obtain the correct case, from a string version of the file type, typically the one used in bot API file objects.
Bot API unique file ID types
The unique file type is a PHP enum uniquely indicating the unique file, danog\Decoder\UniqueFileIdType.
Click here » to view the full list of file ID types.
Full API documentation
Click here » to view the full API documentation.
danog/tg-file-decoder 适用场景与选型建议
danog/tg-file-decoder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 740.75k 次下载、GitHub Stars 达 77, 最近一次更新时间为 2020 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「audio」 「video」 「files」 「telegram」 「bot api」 「mtproto」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 danog/tg-file-decoder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 danog/tg-file-decoder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 danog/tg-file-decoder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An HTML5 upload field for the CMS and frontend forms.
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
A very simple yet useful helper class to handle PHP file uploads.
The flysystem adapter for yandex disk rest api.
Library for manipulating audio files (validating, transcoding, and tagging)
The yii2-videojs-widget is a Yii 2 wrapper for the [video.js](http://www.videojs.com/). A JavaScript and CSS library that makes it easier to work with and build on HTML5 video. This is also known as an HTML5 Video Player.
统计信息
- 总下载量: 740.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 77
- 点击次数: 41
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-only
- 更新时间: 2020-02-03