新增腾讯im。

This commit is contained in:
2023-03-09 16:01:03 +08:00
parent e1a015e960
commit 0850d6e3f3
19 changed files with 1265 additions and 46 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace Extend\TencentIm;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use GuzzleHttp\Exception\GuzzleException;
/**
* 好友
*/
class Friend extends Base
{
private string $version = 'v4';
/**
* 添加好友
* 单个好友添加
* @param string $user_id
* @param string $friend_user_id
* @param string $group_name
* @return array
* @throws GuzzleException
*/
public function addFriend(string $user_id,string $friend_user_id,string $group_name): array
{
try {
$options = [
"json"=> [
"From_Account" => $user_id,
"AddFriendItem" => [
[
"To_Account" => $friend_user_id,
"AddSource" => "AddSource_Type_Applets", // 加好友来源字段
]
],
"ForceAddFlags" => 1, // 管理员强制加好友标记:1表示强制加好友,0表示常规加好友方式
]
];
$path = $this->config['base_url'] . $this->version . "/profile/portrait_set?" . $this->buildRequestParams();
$result = $this->postRequest($path,$options);
if (isset($result['Fail_Account'])){
// 返回处理失败的用户列表,仅当存在失败用户时才返回该字段
throw new BusinessException("添加好友异常,未返回结果:" . json_encode($result['ResultItem'],JSON_UNESCAPED_UNICODE));
}
return $result;
}catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
}