fix: 修复多公司多飞书应用消息卡片更新失败问题
- feishu_message 表新增 company_id 和 feishu_app_id 字段追踪消息发送者 - 修改 FeishuMessage::saveMessage() 支持保存公司和飞书应用信息 - 修改 FeishuNotificationService 使用原始发送者的飞书应用配置更新消息 - 新增 HttpClient::httpPatchJson() 方法支持 PATCH 请求 - 文档更新:PROJECT_ISSUES.md 添加问题31,APPROVAL_NOTIFICATION_ARCHITECTURE.md 添加多公司架构说明 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -242,4 +242,75 @@ class HttpClient
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 HTTP PATCH JSON 请求
|
||||
*
|
||||
* @param string $url 请求URL
|
||||
* @param array $data 请求数据(将被编码为 JSON)
|
||||
* @param array $preencodedKeys 需要预编码的字段名列表(这些字段的值已经是 JSON 字符串)
|
||||
* @param array $headers 额外的请求头
|
||||
* @param int $timeout 超时时间(秒)
|
||||
* @return array 响应数据(JSON解码后的数组)
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function httpPatchJson(
|
||||
string $url,
|
||||
array $data,
|
||||
array $preencodedKeys = [],
|
||||
array $headers = [],
|
||||
int $timeout = 0
|
||||
): array {
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
|
||||
|
||||
// 手动构建 JSON,预编码字段作为字符串值直接插入
|
||||
$jsonParts = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$keyJson = json_encode($key, JSON_UNESCAPED_UNICODE);
|
||||
if (in_array($key, $preencodedKeys)) {
|
||||
$jsonParts[] = $keyJson . ':' . json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
} else {
|
||||
$jsonParts[] = $keyJson . ':' . json_encode($value, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
$jsonPayload = '{' . implode(',', $jsonParts) . '}';
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonPayload);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ?: self::$defaultTimeout);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
||||
$defaultHeaders = [
|
||||
'Content-Type: application/json',
|
||||
];
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($defaultHeaders, $headers));
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
|
||||
// PHP 8.0+ curl 资源自动关闭,无需 curl_close()
|
||||
|
||||
self::logRequest('PATCH', $url, $data, $response, $httpCode);
|
||||
|
||||
if ($error) {
|
||||
throw new Exception("HTTP PATCH 请求失败: {$error}");
|
||||
}
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
throw new Exception("HTTP PATCH 请求失败: HTTP {$httpCode}, Response: {$response}");
|
||||
}
|
||||
|
||||
$result = json_decode($response, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new Exception('JSON 解析失败: ' . $response);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user