amo-tm/amosdk-php
Composer 安装命令:
composer require amo-tm/amosdk-php
包简介
php sdk for amo | team messenger API
README 文档
README
Requirements
PHP 7.4.0 and later.
Composer
You can install the sdk via Composer. Run the following command:
composer require amo-tm/amosdk-php:"^v1.3@beta
To use the sdk, use Composer's autoload:
require_once('vendor/autoload.php');
Getting Started
Simple usage:
use \Amo\Sdk\AmoClient; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', ]);
Initiate client with access token:
use \Amo\Sdk\AmoClient; use \League\OAuth2\Client\Token\AccessToken; // Token fetch from store /** @var AccessToken $accessToken */ $accessToken = null; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', 'accessToken' => $accessToken, ]);
Receive appToken
This type of tokens issued by client library. Your can issue token on every request or store them in your datastore.
use \Amo\Sdk\AmoClient; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', ]); $appScopedSdk = $sdk->withToken($sdk->getApplicationToken(['teams', 'profiles'])) // store token in database
Create team
REQUIRED: AppToken
SCOPE: teams
use \Amo\Sdk\AmoClient; use \Amo\Sdk\Models\Team; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', ]); $appScopedSdk = $sdk->withToken($sdk->getApplicationToken(['teams', 'profiles'])) $newTeam = $appScopedSdk->team()->create(new Team([ 'title' => 'testTeamName' ])) print "team created with id " . $newTeam->getId();
Create profile
REQUIRED: AppToken
SCOPE: profiles
use \Amo\Sdk\AmoClient; use \Amo\Sdk\Models\Team; $sdk = new AmoClient([ 'clientID' => 'your_client_id', 'clientSecret' => 'your_client_secret', ]); $appScopedSdk = $sdk->withToken($sdk->getApplicationToken(['teams', 'profiles'])) $createdProfile = $appScopedSdk->profile()->create(new Profile([ 'name' => 'Tim', 'email' => 'tim@domain.com', 'external_id' => '7688d6ac-57a1-421e-ac41-a68205d96d4e' ])); print "profile created with id " . $createdTeam->getId();
Invite profile to team
REQUIRED: TeamToken
SCOPE: profiles,teams
/** @var \Amo\Sdk\AmoClient $appScopedSdk */ $teamService = $appScopedSdk->team($newTeam->getId())->scope(); // save team token to datastore $teamToken = $teamService->getAccessToken(); $invitedUser = $teamService->invite($createdProfile->getId(), new TeamProps([ 'is_admin' => true, 'position' => 'CEO' ]));
Kick profile from team
REQUIRED: TeamToken
SCOPE: profiles,teams
/** @var \Amo\Sdk\Service\TeamService $teamService */ $teamService->kick($invitedUser->getId());
Subject create
REQUIRED: TeamToken
/** @var \Amo\Sdk\Service\TeamService $teamService */ $subjectService = $teamService->subject(); $newSubject = $subjectService->create(new Subject([ 'title' => 'Subject Title', 'external_link' => 'https://example.com/', 'author' => Participant::user($createdProfile), 'participants' => new ParticipantCollection([ Participant::user($createdProfile->getId()), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ), 'subscribers' => new ParticipantCollection([ Participant::user('ebfaf836-f07b-4df5-809c-2bedb4a2f924'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ), 'threads' => new SubjectThreadCollection([ new SubjectThread([ 'title' => 'Subject Thread #1', 'avatar_url' => 'https://picsum.photos/600' ]), new SubjectThread([ 'title' => 'Subject Thread #2', 'avatar_url' => 'https://picsum.photos/600' ]), ]), 'status' => new SubjectStatusCollection([ SubjectStatus::status('Status', '#F9F6EE'), SubjectStatus::status('Title', '#CFE1A7'), ]) ])); print "subject created with id " . $newSubject->getId();
Subject participants add
REQUIRED: TeamToken
@var \Amo\Sdk\Service\TeamService $teamService */ $subjectService = $teamService->subject($createdSubject->getId()); $participantsAddResponse = $subjectServie->participantsAdd([ new ParticipantCollection( Participant::user('d31f3f74-6fc0-41ae-b2f9-42eccd4f80b8'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ) ]); print 'count current participants: '. $participantsAddResponse->getCount();
Subject participants remove
REQUIRED: TeamToken
@var \Amo\Sdk\Service\SubjectService $subjectService */ $participantsRemoveResponse = $subjectService->participantsRemove([ new ParticipantCollection( Participant::user('d31f3f74-6fc0-41ae-b2f9-42eccd4f80b8'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ) ]); print 'count current participants: '. $participantsRemoveResponse->getCount();
Subject subscribers add
REQUIRED: TeamToken
@var \Amo\Sdk\Service\SubjectService $subjectService */ $subscriberAddResponse = $subjectService->subscribersAdd([ new ParticipantCollection( Participant::user('d31f3f74-6fc0-41ae-b2f9-42eccd4f80b8'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ) ]); print 'count current subscribers: '. $subscriberAddResponse->getCount();
Subject subscribers remove
REQUIRED: TeamToken
@var \Amo\Sdk\Service\SubjectService $subjectService */ $subscribersRemoveResponse = $subjectService->subscribersRemove([ new ParticipantCollection( Participant::user('d31f3f74-6fc0-41ae-b2f9-42eccd4f80b8'), Participant::department('04469c3e-5f2e-11ec-bf63-0242ac130002'), Participant::accessList('0eba2bd6-5f2e-11ec-bf63-0242ac130002'), Participant::bot('124479fa-5f2e-11ec-bf63-0242ac130002'), ) ]); print 'count current subscribers: '. $subscribersRemoveResponse->getCount();
amo-tm/amosdk-php 适用场景与选型建议
amo-tm/amosdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 426 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 amo-tm/amosdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amo-tm/amosdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 426
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-07