This commit is contained in:
Your Name
2026-04-18 15:54:14 +08:00
parent fa3da15228
commit 4097fe0cc6
271 changed files with 1257 additions and 369 deletions
@@ -127,6 +127,25 @@ class WechatWorkService
return [];
}
/**
* 批量获取指定成员添加的客户详情(分页,单次最多 100 条)
*
* @see https://developer.work.weixin.qq.com/document/path/92994
* @return array<string, mixed> 含 errcode、external_contact_list、next_cursor 等
*/
public function batchGetExternalContactByUser(string $userId, string $cursor = '', int $limit = 100): array
{
$accessToken = $this->getAccessToken();
$url = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/batch/get_by_user?access_token=' . urlencode($accessToken);
$body = [
'userid_list' => [$userId],
'cursor' => $cursor,
'limit' => min(100, max(1, $limit)),
];
return $this->httpPostJson($url, $body);
}
/**
* @notes 获取客户详情
* @see https://developer.work.weixin.qq.com/document/path/92114
@@ -215,4 +234,41 @@ class WechatWorkService
return $result;
}
/**
* POST JSON
*/
private function httpPostJson(string $url, array $body): array
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json; charset=UTF-8',
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
Log::error('HTTP POST 失败: ' . $url . ', HTTP Code: ' . $httpCode);
return [];
}
$result = json_decode((string) $response, true);
if (!is_array($result)) {
Log::error('JSON 解析失败: ' . $response);
return [];
}
return $result;
}
}