PHP code example of qingze-lab / openim-sdk-php

1. Go to this page and download the library: Download qingze-lab/openim-sdk-php 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/ */

    

qingze-lab / openim-sdk-php example snippets



use QingzeLab\OpenIM\Client\OpenIMClient;
use QingzeLab\OpenIM\Config\OpenIMConfig;
use QingzeLab\OpenIM\Message\Content\TextContent;
use QingzeLab\OpenIM\Message\ContentType;
use QingzeLab\OpenIM\Tests\Support\ArrayCache;

01',
    'u_002',
    ContentType::TEXT,
    (new TextContent())->setContent('hi')->toArray(),
    ['senderPlatformID' => 1]
);

$client->users()->getUserToken('u_001', 1);

$client->users()->updateUserInfoEx(['userID' => 'u_001', 'ex' => 'hello']);

$client->messages()->sendSingle(
    'u_001',
    'u_002',
    ContentType::TEXT,
    (new TextContent())->setContent('hi')->toArray(),
    ['senderPlatformID' => 1]
);

use QingzeLab\OpenIM\Message\Content\TextContent;
use QingzeLab\OpenIM\Message\ContentType;
$client->messages()->sendTextSingle('u_001', 'u_002', (new TextContent())->setContent('hi'), [
    'senderPlatformID' => 1,
    'senderNickname' => '用户001',
]);

$client->groups()->createGroup('u_owner', ['u_001','u_002'], [
    'groupID' => 'g_001',
    'groupName' => '示例群',
    'groupType' => 2,
], []);

use QingzeLab\OpenIM\Support\RedisCache;
$redisClass = '\\Redis';
$redis = new $redisClass();
$redis->connect('127.0.0.1', 6379);
$client = new OpenIMClient(new OpenIMConfig('http://localhost:10002', 'imAdmin', 'openIM123'), new RedisCache($redis, 'openim_token_'));

// 自动模式(默认)
$config = new OpenImConfig('http://localhost:10002', 'imAdmin', 'openIM123'); // 不加 /api
$client = new OpenIMClient($config, new ArrayCache());

// 域名自动加 /api
$config = new OpenImConfig('https://im.example.com', 'imAdmin', 'openIM123'); // 自动加 /api
$client = new OpenIMClient($config, new ArrayCache());

// 显式覆盖:始终加
$config = new OpenImConfig('http://localhost:10002', 'imAdmin', 'openIM123');
$config->setApiPrefixMode('always'); // 强制加 /api

// 自定义前缀
$config->setApiPrefixValue('/v1'); // 路径将以 /v1 开头