You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PatientApp-KKUMC/lib/pages/webRTC/fcm/FCMSendNotification.dart

86 lines
3.0 KiB
Dart

import 'dart:convert';
import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart';
import 'package:http/http.dart' as http;
const _serverFCMToken = 'ya29.a0ARrdaM9U7fZtxF64ntg2Y1Nve-cd4rPazyGcWN69cQmOsddUqxAL1X8GUQ8V6sW2gWxM8ln1BIbmh0OrzQtCiTGrsmcL3jZlGXoQhZN51nX3O7F3g1AXCW_Zt_pjiworCJEGSRkl7QirxE7RFzlwBONsOuft';
const doctorID = '12345';
class FCM{
static Future<bool> sendCallNotifcationTo(String token, String patientID, String patientMobile) async{
var headers = {
'Authorization': 'Bearer $_serverFCMToken',
'Content-Type': 'application/json'
};
final body = {
"message": {
"token": token,
"notification": {
"title": "Dr Sulaiman Al Habib",
"body": "Doctor is calling"
},
"apns": {
"payload": {
"aps": {
"sound": "ring_30Sec.mp3",
"token": "466e0f16fecf1e32c51f812cccc84fcbc807f958b15eb55675a5fa971a775829",
"badge": 1
}
},
"headers": {
"apns-priority": "10",
"apns-expiration": "0",
"apns-collapse-id": "2561368006"
}
},
"data": {
"callerID" : doctorID,
"receiverID" : patientID,
"receiverMobile" : patientMobile,
"msgID": "123",
"notfID": "123",
"notification_foreground": "true",
"count": "1",
"message": "Doctor is calling ",
"AppointmentNo": "123",
"title": "Rayyan Hospital",
"ProjectID": "123",
"NotificationType": "10",
"background": "1",
"doctorname": "Dr Sulaiman Al Habib",
"clinicname": "ENT Clinic",
"speciality": "Speciality",
"appointmentdate": "Sun, 15th Dec, 2019",
"appointmenttime": "09:00",
"type": "video",
"session_id": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTS2I2NjYyOWMzN2ZhOTM3YjFjNDI2Zjg1MTgyNWFmN2M0LTE1OTg3NzQ1MDYiLCJpc3MiOiJTS2I2NjYyOWMzN2ZhOTM3YjFjNDI2Zjg1MTgyNWFmN2M0Iiwic3ViIjoiQUNhYWQ1YTNmOGM2NGZhNjczNTY3NTYxNTc0N2YyNmMyYiIsImV4cCI6MTU5ODc3ODEwNiwiZ3JhbnRzIjp7ImlkZW50aXR5IjoiSGFyb29uMSIsInZpZGVvIjp7InJvb20iOiJTbWFsbERhaWx5U3RhbmR1cCJ9fX0.7XUS5uMQQJfkrBZu9EjQ6STL6R7iXkso6BtO1HmrQKk",
"identity": "Haroon1",
"name": "SmallDailyStandup",
"videoUrl": "video",
"picture": "video",
"is_call": "true"
}
}
};
bool success = false;
await BaseAppClient().simplePost('https://fcm.googleapis.com/v1/projects/api-project-815750722565/messages:send', body: body, headers: headers, onSuccess: (data, statusCode){
success = true;
}, onFailure: (error, statusCode){
success = false;
});
return success;
// final response = await http.post('https://fcm.googleapis.com/v1/projects/api-project-815750722565/messages:send', headers:headers, body: body);
}
}
String toB64(String data){
var bytes = utf8.encode(data);
var base64Str = base64.encode(bytes);
return base64Str;
}