123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Services;
- use App\Models\User;
- use App\Traits\TencentIm;
- use PHPUnit\Util\Exception;
- class TencentImMessage
- {
- use TencentIm;
- //查询单聊消息
- public function getroammsg($from,$to){
- if(empty($from)){
- throw new Exception("参数错误");
- }
- if(empty($to)){
- throw new Exception("参数错误");
- }
- $from = User::query()->find($from,['tencent_im_user_id']);
- $to = User::query()->find($to,['tencent_im_user_id']);
- $this->restApiName = "v4/openim/admin_getroammsg";
- $baseApiHost = $this->getTencentImRestApiBaseHost();
- $params = [
- 'From_Account' => $from->tencent_im_user_id,
- 'To_Account' => $to->tencent_im_user_id,
- 'MaxCnt' => 999,
- 'MinTime' => 1625068800,
- 'MaxTime' => 1751299200,
- ];
- $apiResult = $this->requestApi($baseApiHost, $params);
- self::verifyApiResult($apiResult);
- return $apiResult;
- }
- //单发单聊消息
- public function send_msg($data){
- $this->restApiName = "v4/openim/sendmsg";
- $baseApiHost = $this->getTencentImRestApiBaseHost();
- $content = array();
- $msg['MsgType'] = 'TIMTextElem';
- $msg['MsgContent']['Text'] = $data['msg'];
- $content[]=$msg;
- $params = [
- 'From_Account' => $data['from_user'],
- 'To_Account' => $data['to_user'],
- 'MsgRandom' => rand(100000,999999),
- "MsgBody"=> $content,
- ];
- $apiResult = $this->requestApi($baseApiHost, $params);
- self::verifyApiResult($apiResult);
- return $apiResult;
- }
- }
|