PHP code example of hedeqiang / ten-im

1. Go to this page and download the library: Download hedeqiang/ten-im 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/ */

    

hedeqiang / ten-im example snippets




use Hedeqiang\TenIM\IM;

$config = [
    'sdk_app_id' => '',
    'identifier' => '',
    'secret_key' => '',
    'region'     => 'zh' // zh、sgp、kr、ger、ind、usa
];

$im = new IM($config);

{
    "From_Account":"id",
    "ProfileItem":
    [
        {
            "Tag":"Tag_Profile_IM_Nick",
            "Value":"MyNickName"
        }
    ]
}

$params = [
    'Identifier' => "hedeqiang",
    'Nick'       => 'hedeqiang',
    'FaceUrl'    => '',
];

print_r($im->send('im_open_login_svc','account_import',$params));


$params = [
    'To_Account' => ['hedeqiang']
];

print_r($im->send('openim','querystate',$params));

{
	"ActionStatus": "OK",
	"ErrorInfo": "",
	"ErrorCode": 0,
	"QueryResult": [{
		"To_Account": "1",
		"State": "Offline"
	}]
}

$params = [
    'From_Account' => 'hedeqiang',
        'ProfileItem' => [
            ['Tag' => 'Tag_Profile_IM_Nick', 'Value' => 'hedeqiang'],
            ['Tag' => 'Tag_Profile_IM_Gender', 'Value' => 'Gender_Type_Male'],
            ['Tag' => 'Tag_Profile_IM_BirthDay', 'Value' => 19940410],
            ['Tag' => 'Tag_Profile_IM_SelfSignature', 'Value' => '程序人生的寂静欢喜'],
            ['Tag' => 'Tag_Profile_IM_Image', 'Value' => 'https://upyun.laravelcode.cn/upload/avatar/1524205770e4fbfbff-86ae-3bf9-b7b8-e0e70ce14553.png'],
        ],
];

print_r($im->send('profile','portrait_set',$params));

{
	"ActionStatus": "OK",
	"ErrorCode": 0,
	"ErrorInfo": "",
	"ErrorDisplay": ""
}

$params = [
    'SyncOtherMachine' => 1, // 消息不同步至发送方
    'From_Account' => '1',
    'To_Account' => '2',
    'MsgRandom' => 1287657,
    'MsgTimeStamp' => 1557387418,
    'MsgBody' => [
        [
            'MsgType' => 'TIMTextElem',
            'MsgContent' => [
                'Text' => '晚上去撸串啊'
            ]
        ]
    ]
];

print_r($im->send('openim','sendmsg',$params));

{
    "ActionStatus":"OK",
    "ErrorInfo":"",
    "ErrorCode":0,
    "MsgTime":1573179125,
    "MsgKey":"748144182_1287657_1573179125"
}

php bin/hyperf.php vendor:publish hedeqiang/ten-im

use Hedeqiang\TenIM\IM;
use Hyperf\Utils\ApplicationContext;

$response = ApplicationContext::getContainer()->get(IM::class)->send($servername,$command,$params);

php artisan vendor:publish --provider="Hedeqiang\TenIM\ServiceProvider"

use Hedeqiang\TenIM\IM;

public function index(IM $im)
{
    $params = [
        'SyncOtherMachine' => 1, // 消息不同步至发送方
        'From_Account' => '1',
        'To_Account' => '2',
        'MsgRandom' => 1287657,
        'MsgTimeStamp' => 1557387418,
        'MsgBody' => [
            [
                'MsgType' => 'TIMTextElem',
                'MsgContent' => [
                    'Text' => '晚上去撸串啊'
                ]
            ]
        ]
    ];
    $response = $im->send('openim','sendmsg',$params);
}

public function index()
{
    $params = [
        'SyncOtherMachine' => 1, // 消息不同步至发送方
        'From_Account' => '1',
        'To_Account' => '2',
        'MsgRandom' => 1287657,
        'MsgTimeStamp' => 1557387418,
        'MsgBody' => [
            [
                'MsgType' => 'TIMTextElem',
                'MsgContent' => [
                    'Text' => '晚上去撸串啊'
                ]
            ]
        ]
    ];
    $response = app('im')->send('openim','sendmsg',$params);
}

use Hedeqiang\TenIM\Facades\IM;

$params = [
        'SyncOtherMachine' => 1, // 消息不同步至发送方
        'From_Account' => '1',
        'To_Account' => '2',
        'MsgRandom' => 1287657,
        'MsgTimeStamp' => 1557387418,
        'MsgBody' => [
            [
                'MsgType' => 'TIMTextElem',
                'MsgContent' => [
                    'Text' => '晚上去撸串啊'
                ]
            ]
        ]
    ];
$response = IM::im()->send('openim','sendmsg',$params);