boogiefromzk/agora-token
Composer 安装命令:
composer require boogiefromzk/agora-token
包简介
Intended to make Agora Tools for PHP repository folder as a package installable with Composer.
README 文档
README
Agora token generation library for PHP
As Agora support declined my feature request to do that, had to make Agora Tools for PHP repository folder available as a package, installable with Composer.
https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/php/src
License
ISC license is not confirmed, but inherited from agora-chat npm package:
https://www.npmjs.com/package/agora-chat
Usage
Install the package.
composer require boogiefromzk/agora-token
Agora Chat Token
Create the app token for using REST API to register users.
use BoogieFromZk\AgoraToken\ChatTokenBuilder2;
$appID = ... // App ID from Agora client area.
$appCertificate = ... // App Certificate from Agora client area.
$expiresInSeconds = ... // For how many seconds this token is kept valid.
$appToken = ChatTokenBuilder2::buildAppToken($appID, $appCertificate, $expiresInSeconds);
Then use it for authentication in Agora Chat REST API and register a user.
https://docs.agora.io/en/agora-chat/restful-api/user-system-registration
You will use some field as username when registering a user, save it in a user.
Now you can create a token for this user:
use BoogieFromZk\AgoraToken\ChatTokenBuilder2;
$appID = ... // App ID from Agora client area.
$appCertificate = ... // App Certificate from Agora client area.
$expiresInSeconds = ... // For how many seconds this token is kept valid.
$agoraUsername = ... // Username used for user registration above.
$token = ChatTokenBuilder2::buildUserToken($appID, $appCertificate, $agoraUsername, $expiresInSeconds);
In order to set and retrieve user's presence in Agora Chat please ensure that the feature is enabled from your Agora Chat Console. In order to enable it, from your Agora Chat Console menu, click on Features -> Overview -> Under "Message Feature Configuration" look for "Others" and ensure that Presence is set to enabled.
Agora RTC Token
use BoogieFromZk\AgoraToken\RtcTokenBuilder2;
$appID = ... // App ID from Agora client area.
$appCertificate = ... // App Certificate from Agora client area.
$expiresInSeconds = ... // For how many seconds this token is kept valid.
$channelName = ... // Channel name which should be accessible.
$uid = ... // Identifier of user.
$role = RtcTokenBuilder2::ROLE_PUBLISHER;
$token = RtcTokenBuilder2::buildTokenWithUid($appID, $appCertificate, $channelName, $uid, $role, $expiresInSeconds);
More Examples
More examples you can find in samples folder of Agora Tools project:
https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/php/sample
Update files script
This script is for internal use, - it updates files in /src folder.
rm -rf ./src
git clone git@github.com:AgoraIO/Tools.git /tmp/agora_tools
cp -r /tmp/agora_tools/DynamicKey/AgoraDynamicKey/php/src .
rm -rf /tmp/agora_tools
cd ./src
sed -i 's/<?php/<?php\n\nnamespace BoogieFromZk\\AgoraToken;/' *
Useful links
-
Agora Use cases https://github.com/AgoraIO-usecase
-
Agora examples https://gist.github.com/digitallysavvy
-
Broadcasting RTC demo https://github.com/digitallysavvy/agora-web-broadcast-demo
-
Subscribing RTC channels https://github.com/AgoraIO/API-Examples-Web/blob/main/Demo/joinMutlipleChannel/joinMultipleChannel.js
-
RTC event descriptions https://gist.github.com/digitallysavvy/4ef54c791fe88c668cfe3420d7f6558f
-
RTC test camera and microphone https://docs.agora.io/en/3.x/voice-calling/basic-features/lastmile-quality?platform=web
-
Agora RTM tokens https://docs.agora.io/en/signaling/develop/authentication-workflow
-
RTM example https://github.com/AgoraIO/RTM/blob/master/Agora-RTM-Tutorial-Web/src/rtm-client.js
-
Agora Chat REST API https://docs.agora.io/en/agora-chat/restful-api/user-system-registration
-
Agora Chat Presence https://docs.agora.io/en/agora-chat/restful-api/presence#path-parameter https://docs.agora.io/en/agora-chat/restful-api/presence#status-codes
-
Agora Chat subscription to events example https://github.com/AgoraIO-Usecase/AgoraChat-web/blob/main/src/utils/WebIMListen.js
-
Agora Chat send message example https://docs.agora.io/en/agora-chat/client-api/messages/send-receive-messages#send-a-customized-message
-
Agora Chat set nickname https://docs.agora.io/en/agora-chat/restful-api/offline-push#set-the-display-style-in-push-notifications
boogiefromzk/agora-token 适用场景与选型建议
boogiefromzk/agora-token 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68.44k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2022 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 boogiefromzk/agora-token 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 boogiefromzk/agora-token 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 68.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2022-10-25