chocoboxxf / yii2-easemob-sdk
Easemob API for Yii 2.0
Installs: 93
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 4
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~5.0
- yiisoft/yii2: *
Requires (Dev)
- phpunit/phpunit: >=4.0
This package is not auto-updated.
Last update: 2024-11-09 19:57:59 UTC
README
基于Yii2实现的环信API SDK(目前开发中)
环境条件
-
= PHP 5.4
-
= Yii 2.0
-
= GuzzleHttp 5.0
安装
添加下列代码在composer.json
文件中并执行composer update --no-dev
操作
{ "require": { "chocoboxxf/yii2-easemob-sdk": "dev-master" } }
设置方法
// 全局使用 // 在config/main.php配置文件中定义component配置信息 'components' => [ ..... 'easemob' => [ 'class' => 'chocoboxxf\Easemob\Easemob', 'orgName' => '企业ID', 'appName' => '应用名称', 'clientId' => 'Client Id', 'clientSecret' => 'Client Secret', ] .... ] // 代码中调用 $result = Yii::$app->easemob->getUser('username'); ....
// 局部调用 $easemob = Yii::createObject([ 'class' => 'chocoboxxf\Easemob\Easemob', 'orgName' => '企业ID', 'appName' => '应用名称', 'clientId' => 'Client Id', 'clientSecret' => 'Client Secret', ]); $result = $easemob->getUser('username'); ....
使用示例
创建单个用户
$userInfo = Yii::$app->easemob->createUser('username', 'password', 'nickname');
获取单个用户
$userInfo = Yii::$app->easemob->getUser('username');
获取用户Access Token
$tokenInfo = Yii::$app->easemob->getUserToken('username', 'password');
添加好友
$friendInfo = Yii::$app->easemob->addFriend('username1', 'username2');
导出聊天记录
$data = Yii::$app->easemob->exportChatMessages();
发送透传消息
$data = Yii::$app->easemob->sendCmd('users', ['user1', 'users2'], 'action1', ['key1' => 'value1'], 'admin');