基于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');