nomedia/yii2-easemob-sdk-2020

环信 easemob API for Yii 2.0


Keywords
sdk, im, yii2, easemob
License
MIT

Documentation

yii2-easemob-sdk

基于Yii2实现的环信API SDK(目前开发中)

环境条件

  • = PHP 5.4

  • = Yii 2.0

  • = GuzzleHttp 5.0

安装

添加下列代码在composer.json文件中并执行composer update --no-dev操作

{
    "require": {
       "nomedia/yii2-easemob-sdk": "dev-master"
    }
}

设置方法

// 全局使用
// 在config/main.php配置文件中定义component配置信息
'components' => [
  .....
  'easemob' => [
    'class' => 'nomedia\Easemob\Easemob',
    'orgName' => '企业ID',
    'appName' => '应用名称',
    'clientId' => 'Client Id',
    'clientSecret' => 'Client Secret',
  ]
  ....
]
// 代码中调用
$result = Yii::$app->easemob->getUser('username');
....
// 局部调用
$easemob = Yii::createObject([
    'class' => 'nomedia\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');