25-12-1/1
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:Intaleq/print.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
@@ -5,11 +6,13 @@ class NotificationService {
|
||||
// استبدل هذا الرابط بالرابط الصحيح لملف PHP على السيرفر الخاص بك
|
||||
static const String _serverUrl =
|
||||
'https://syria.intaleq.xyz/intaleq/fcm/send_fcm.php';
|
||||
|
||||
static const String _batchServerUrl =
|
||||
'https://syria.intaleq.xyz/intaleq/fcm/send_fcm_batch.php';
|
||||
static Future<void> sendNotification({
|
||||
required String target,
|
||||
required String title,
|
||||
required String body,
|
||||
required String? category, // <-- [الإضافة الأولى]
|
||||
String? tone,
|
||||
List<String>? driverList, // <-- [تعديل 1] : إضافة المتغير الجديد
|
||||
bool isTopic = false,
|
||||
@@ -21,7 +24,10 @@ class NotificationService {
|
||||
'body': body,
|
||||
'isTopic': isTopic,
|
||||
};
|
||||
|
||||
if (category != null) {
|
||||
payload['category'] =
|
||||
category; // <-- [الإضافة الثانية] (النص الثابت للتحكم)
|
||||
}
|
||||
// نضيف النغمة فقط إذا لم تكن فارغة
|
||||
if (tone != null) {
|
||||
payload['tone'] = tone;
|
||||
@@ -52,4 +58,56 @@ class NotificationService {
|
||||
print('❌ An error occurred while sending notification: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// [4] !! دالة جديدة مضافة !!
|
||||
/// ترسل إشعاراً "مجمعاً" إلى قائمة من السائقين
|
||||
static Future<void> sendBatchNotification({
|
||||
required List<String> targets, // <-- قائمة التوكينز
|
||||
required String title,
|
||||
required String body,
|
||||
String? tone,
|
||||
List<String>? driverList, // <-- بيانات الرحلة (نفسها للجميع)
|
||||
}) async {
|
||||
// لا ترسل شيئاً إذا كانت القائمة فارغة
|
||||
if (targets.isEmpty) {
|
||||
Log.print('⚠️ [Batch] No targets to send to. Skipped.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final Map<String, dynamic> payload = {
|
||||
// "targets" بدلاً من "target"
|
||||
'targets': jsonEncode(targets), // تشفير قائمة التوكينز
|
||||
'title': title,
|
||||
'body': body,
|
||||
};
|
||||
|
||||
if (tone != null) {
|
||||
payload['tone'] = tone;
|
||||
}
|
||||
|
||||
// بيانات الرحلة (DriverList)
|
||||
if (driverList != null) {
|
||||
payload['driverList'] = jsonEncode(driverList);
|
||||
}
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(_batchServerUrl), // <-- !! تستخدم الرابط الجديد
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(payload),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
Log.print('✅ [Batch] Notifications sent successfully.');
|
||||
Log.print('Server Response: ${response.body}');
|
||||
} else {
|
||||
Log.print('❌ [Batch] Failed to send. Status: ${response.statusCode}');
|
||||
Log.print('Server Error: ${response.body}');
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('❌ [Batch] An error occurred: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user