PHP code example of nomedia / yii2-easemob-sdk-2020

1. Go to this page and download the library: Download nomedia/yii2-easemob-sdk-2020 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nomedia / yii2-easemob-sdk-2020 example snippets


// 全局使用
// 在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');

$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');