PHP code example of tinymeng / tencentyun-im
1. Go to this page and download the library: Download tinymeng/tencentyun-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/ */
tinymeng / tencentyun-im example snippets
{
"From_Account":"id",
"ProfileItem":
[
{
"Tag":"Tag_Profile_IM_Nick",
"Value":"MyNickName"
}
]
}
use tinymeng\TenIm\IM;
$config = [
'sdk_app_id' => '',
'identifier' => '',
'secret_key' => '',
];
$im = new IM($config);
$params = [
'Identifier' => "tinymeng",
'Nick' => 'tinymeng',
'FaceUrl' => '',
];
print_r($im->send('im_open_login_svc','account_import',$params));
$params = [
'To_Account' => ['tinymeng']
];
print_r($im->send('openim','querystate',$params));
{
"ActionStatus": "OK",
"ErrorInfo": "",
"ErrorCode": 0,
"QueryResult": [{
"To_Account": "1",
"State": "Offline"
}]
}
$params = [
'From_Account' => 'tinymeng',
'ProfileItem' => [
['Tag' => 'Tag_Profile_IM_Nick', 'Value' => 'tinymeng'],
['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 artisan vendor:publish --provider="tinymeng\TenIm\ServiceProvider"
use tinymeng\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 tinymeng\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);