Update: 2026-07-23 16:56:57

This commit is contained in:
Hamza-Ayed
2026-07-23 16:56:58 +03:00
parent 1cef598fc5
commit c35b350b31
9 changed files with 55 additions and 49 deletions
+16 -4
View File
@@ -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)) {
+14 -3
View File
@@ -2,16 +2,27 @@
// send_fcm.php - FCM HTTP v1 Sender (Internal use only)
header('Content-Type: application/json; charset=utf-8');
// 🔐 Require internal API key for authentication
// 🔐 Require internal API key for authentication if set
$apiKey = $_SERVER['HTTP_X_API_KEY'] ?? '';
$expectedKey = getenv('FCM_INTERNAL_API_KEY');
if (empty($expectedKey) || !hash_equals($expectedKey, $apiKey)) {
if (!empty($expectedKey) && !hash_equals($expectedKey, $apiKey)) {
http_response_code(403);
echo json_encode(['status' => 'error', 'message' => 'Unauthorized']);
exit;
}
$serviceAccountFile = __DIR__ . '/service-account.json';
function resolveServiceAccountPath(): string {
$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';
}
$serviceAccountFile = resolveServiceAccountPath();
// السماح فقط بـ POST
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {