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

88 lines
2.6 KiB
PHP

<?php
namespace Extend\TencentIm;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use GuzzleHttp\Exception\GuzzleException;
/**
* 分组
*/
class Group extends Base
{
private string $version = 'v4';
/**
* 添加用户好友分组
* @param string $user_id
* @param array $group_name 分组名称
* @return array
* @throws GuzzleException
*/
public function addUserGroup(string $user_id,array $group_name = ["专家问诊","快速问诊","快速问诊","问诊购药"]): array
{
try {
$options = [
"json"=> [
"From_Account" => $user_id,
"GroupName" => $group_name,
]
];
$path = $this->config['base_url'] . $this->version . "/sns/group_add?" . $this->buildRequestParams();
return $this->postRequest($path,$options);
}catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
/**
* 获取用户好友分组
* @param string $user_id
* @return array
* @throws GuzzleException
*/
public function getUserGroup(string $user_id): array
{
try {
$options = [
"json"=> [
"From_Account" => $user_id,
"NeedFriend" => "Need_Friend_Type_Yes",
]
];
$path = $this->config['base_url'] . $this->version . "/sns/group_get?" . $this->buildRequestParams();
$result = $this->postRequest($path,$options);
return $result['ResultItem'];
}catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
/**
* 删除用户好友分组
* @param string $user_id
* @param array $group_name 分组名称
* @return array
* @throws GuzzleException
*/
public function deleteUserGroup(string $user_id,array $group_name = ["专家问诊","快速问诊","快速问诊","问诊购药"]): array
{
try {
$options = [
"json"=> [
"From_Account" => $user_id,
"NeedFriend" => "Need_Friend_Type_Yes",
]
];
$path = $this->config['base_url'] . $this->version . "/sns/group_get?" . $this->buildRequestParams();
$result = $this->postRequest($path,$options);
return $result['ResultItem'];
}catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
}