Update: 2026-07-23 16:56:57
This commit is contained in:
@@ -12,10 +12,22 @@ function base64UrlEncode($data) {
|
||||
// ============================================================================
|
||||
// دالة الحصول على Access Token من Google OAuth2
|
||||
// ============================================================================
|
||||
function getFCMAccessToken($serviceAccountPath = null) {
|
||||
if (!$serviceAccountPath) {
|
||||
$serviceAccountPath = __DIR__ . '/service-account.json';
|
||||
function resolveFCMServiceAccountPath($serviceAccountPath = null) {
|
||||
if (!empty($serviceAccountPath) && file_exists($serviceAccountPath)) {
|
||||
return $serviceAccountPath;
|
||||
}
|
||||
$envPath = getenv('FIREBASE_SERVICE_ACCOUNT_PATH') ?: '';
|
||||
if (!empty($envPath) && file_exists($envPath)) {
|
||||
return $envPath;
|
||||
}
|
||||
if (file_exists('/keys/firebase_service_account.json')) {
|
||||
return '/keys/firebase_service_account.json';
|
||||
}
|
||||
return __DIR__ . '/service-account.json';
|
||||
}
|
||||
|
||||
function getFCMAccessToken($serviceAccountPath = null) {
|
||||
$serviceAccountPath = resolveFCMServiceAccountPath($serviceAccountPath);
|
||||
|
||||
if (!file_exists($serviceAccountPath)) {
|
||||
error_log("❌ FCM: service-account.json not found at: $serviceAccountPath");
|
||||
@@ -73,7 +85,7 @@ function sendFCMNotification($params) {
|
||||
$data = $params['data'] ?? [];
|
||||
$tone = $params['tone'] ?? 'default';
|
||||
$isTopic = $params['isTopic'] ?? false;
|
||||
$serviceAccountPath = $params['service_account_path'] ?? __DIR__ . '/service-account.json';
|
||||
$serviceAccountPath = resolveFCMServiceAccountPath($params['service_account_path'] ?? null);
|
||||
|
||||
// التحقق من البيانات الأساسية
|
||||
if (empty($token) || empty($title) || empty($body)) {
|
||||
|
||||
Reference in New Issue
Block a user