62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\GatewayWorker\ImService;
|
|
use App\Services\GatewayWorker\UserService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ImController extends Controller
|
|
{
|
|
//
|
|
private $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = ImService::getInstance();
|
|
}
|
|
public function bind()
|
|
{
|
|
$clientId = request()->input('client_id');
|
|
|
|
try {
|
|
return jok($this->service->bindClientIdByUserId($clientId));
|
|
} catch (\Exception $e) {
|
|
return jerr($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 发送消息
|
|
* @Method POST
|
|
* @return JsonResponse
|
|
*/
|
|
public function sendMessage()
|
|
{
|
|
$messageType = request()->post('message_type');
|
|
$data = request()->post('data');
|
|
$toUserId = request()->post('to_user_id');
|
|
$chatRoomId = request()->post('chat_room_id');
|
|
$replayId = request()->post('replay_id', 0);
|
|
|
|
try {
|
|
return jok($this->service->sendMessage($data, $toUserId, $chatRoomId, $replayId, $messageType));
|
|
} catch (\Exception $e) {
|
|
return jerr($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function getMessageByChatRoomId()
|
|
{
|
|
$chatRoomId = request()->input('chat_room_id');
|
|
try {
|
|
return jok(
|
|
$this->service->getMessageByChatRoomId($chatRoomId)
|
|
);
|
|
} catch (\Exception $e) {
|
|
return jerr($e->getMessage());
|
|
}
|
|
}
|
|
}
|