新增腾讯im。
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Extend\TencentIm;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use Hyperf\Snowflake\IdGeneratorInterface;
|
||||
use Hyperf\Utils\ApplicationContext;
|
||||
|
||||
class MyStruct{
|
||||
|
||||
}
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
class Message extends Base
|
||||
{
|
||||
private string $version = 'v4';
|
||||
|
||||
// 发送消息参数
|
||||
private array $arg;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->arg = [
|
||||
// 把消息同步到 From_Account 在线终端和漫游上;消息不同步至 From_Account;
|
||||
'SyncOtherMachine' => 1,
|
||||
|
||||
//消息随机数(32位无符号整数)
|
||||
'MsgRandom' => random_int(1, 4292967295),
|
||||
|
||||
/**
|
||||
* 消息回调禁止开关,只对本条消息有效
|
||||
* ForbidBeforeSendMsgCallback 表示禁止发消息前回调
|
||||
* ForbidAfterSendMsgCallback 表示禁止发消息后回调
|
||||
*/
|
||||
'ForbidCallbackControl' => ['ForbidBeforeSendMsgCallback','ForbidAfterSendMsgCallback'],
|
||||
|
||||
/**
|
||||
* 消息发送控制选项,是一个 String 数组,只对本条消息有效。
|
||||
* "NoUnread"表示该条消息不计入未读数。
|
||||
* "NoLastMsg"表示该条消息不更新会话列表。
|
||||
* "WithMuteNotifications"表示该条消息的接收方对发送方设置的免打扰选项生效(默认不生效)
|
||||
*/
|
||||
'SendMsgControl' => ['NoUnread','NoLastMsg','WithMuteNotifications'],
|
||||
|
||||
'MsgBody' => [
|
||||
/**
|
||||
* 消息对象类型
|
||||
* TIMTextElem(文本消息)
|
||||
* TIMLocationElem(位置消息)
|
||||
* TIMFaceElem(表情消息)
|
||||
* TIMCustomElem(自定义消息)
|
||||
* TIMSoundElem(语音消息)
|
||||
* TIMImageElem(图像消息)
|
||||
* TIMFileElem(文件消息)
|
||||
* TIMVideoFileElem(视频消息)
|
||||
*/
|
||||
'MsgType' => "TIMTextElem",
|
||||
|
||||
// 消息内容,对于每种 MsgType 用不同的 MsgContent 格式
|
||||
'MsgContent' => null,
|
||||
],
|
||||
|
||||
/**
|
||||
* 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
|
||||
* 如聊天类型。json格式
|
||||
* order_inquiry_id
|
||||
* inquiry_type
|
||||
*/
|
||||
'CloudCustomData' => "",
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public function sendMessage(array $arg){
|
||||
|
||||
try {
|
||||
// 合并发送参数
|
||||
$arg = array_merge($this->arg,$arg);
|
||||
|
||||
$options = [
|
||||
"json"=> $arg
|
||||
];
|
||||
|
||||
dump($options);
|
||||
$path = $this->config['base_url'] . $this->version . "/openim/sendmsg?" . $this->buildRequestParams();
|
||||
return $this->postRequest($path,$options);
|
||||
}catch (\Exception $e) {
|
||||
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user