2023-03-09 16:01:03 +08:00

54 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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);
}
}
}