SDK使用指南
初始化
PHP
use GeekIM\SDK\GeekIMClient;
$client = new GeekIMClient([
'app_id' => 'your_app_id',
'app_secret' => 'your_app_secret',
'base_url' => 'https://your-domain.com/api'
]);
视频通话
PHP
// 创建视频通话房间
$room = $client->createRoom('video', 2);
echo '房间ID: ' . $room['room_id'];
echo '加入令牌: ' . $room['token'];
// 加入房间
$client->joinRoom($room['room_id'], $userId);
// 结束通话
$result = $client->leaveRoom($room['room_id'], $userId);
echo '通话时长: ' . $result['duration'] . '秒';
echo '费用: ¥' . $result['cost'];
语音通话
PHP
// 创建语音通话房间
$room = $client->createRoom('voice', 2);
// 发送语音消息
$audioBase64 = base64_encode(file_get_contents('voice.mp3'));
$client->sendVoiceMessage('user_123', $audioBase64, 15);
即时消息
PHP
// 发送文本消息
$result = $client->sendMessage($userId, 'target_user', 'text', [
'content' => 'Hello, GeekIM!'
]);
// 发送图片消息
$result = $client->sendMessage($userId, 'target_user', 'image', [
'url' => 'https://example.com/image.jpg',
'width' => 800,
'height' => 600
]);
极客通讯 GeekIM — 极客工作室出品 · 文档版本 v1.0