Send push motification to iphone and android code
function sendIphoneAdminPush($token,$message)
{
$streamContext = stream_context_create();
$badge = 0;
//$message = "Here is the new deal having 50% discount for business ABC.";
//$token = "ghjkghkgkghkghkjghkghkghjkhkghkghjkhkhgjkhgj";
stream_context_set_option($streamContext, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'].'/nodatapp/pem/pushNew.pem');
$apns = stream_socket_client(
//'ssl://gateway.sandbox.push.apple.com:2195',
'ssl://gateway.push.apple.com:2195',
$error,
$errorString,
60,
STREAM_CLIENT_CONNECT, $streamContext);
$load = array(
'aps' => array(
'alert' => $message,
'badge' => $badge,
'sound' => 'default',
'data' => array(
'push_type' => "IphonePush"
)
)
);
$payload = json_encode($load);
$apnsMessage = chr(0) . chr(0) . chr(32);
$apnsMessage .= pack('H*', $token);
$apnsMessage .= chr(0) . chr(strlen($payload)) . $payload;
$bytes = fwrite($apns, $apnsMessage);
$payload = json_encode($load);
//print_r($payload);
fclose($apns);
//return true;
}
function sendAndroidAdminPush($token,$busisId,$message,$msgBody)
{
//Testing
$APIKey= 'AAAAODAx1tY:APA91bG5wfaeghjkghkghjkghk3bt4LLa7p8gJSUBZ0eywiYUbkZPYvckViQeKtOvVkFh4zWo8eqEQurW5Y54rjanV2Jihgjghjkghjkgjkghjkgh5_3Ux_ScSY4YMfkTELwBl';
$fields = array(
'to' => $token,
'notification' => array('title' => $message, 'body' => $msgBody,'business_id' => $busisId,'click_action' => '.activity.HomeActivity'),
'data' => array('title' => $message,'business_id' => $busisId)
);
$headers = array
(
'Authorization: key='. $APIKey,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode($fields) );
$result = curl_exec($ch );
curl_close( $ch );
return true;
}
function sendIphoneAdminPush($token,$message)
{
$streamContext = stream_context_create();
$badge = 0;
//$message = "Here is the new deal having 50% discount for business ABC.";
//$token = "ghjkghkgkghkghkjghkghkghjkhkghkghjkhkhgjkhgj";
stream_context_set_option($streamContext, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'].'/nodatapp/pem/pushNew.pem');
$apns = stream_socket_client(
//'ssl://gateway.sandbox.push.apple.com:2195',
'ssl://gateway.push.apple.com:2195',
$error,
$errorString,
60,
STREAM_CLIENT_CONNECT, $streamContext);
$load = array(
'aps' => array(
'alert' => $message,
'badge' => $badge,
'sound' => 'default',
'data' => array(
'push_type' => "IphonePush"
)
)
);
$payload = json_encode($load);
$apnsMessage = chr(0) . chr(0) . chr(32);
$apnsMessage .= pack('H*', $token);
$apnsMessage .= chr(0) . chr(strlen($payload)) . $payload;
$bytes = fwrite($apns, $apnsMessage);
$payload = json_encode($load);
//print_r($payload);
fclose($apns);
//return true;
}
function sendAndroidAdminPush($token,$busisId,$message,$msgBody)
{
//Testing
$APIKey= 'AAAAODAx1tY:APA91bG5wfaeghjkghkghjkghk3bt4LLa7p8gJSUBZ0eywiYUbkZPYvckViQeKtOvVkFh4zWo8eqEQurW5Y54rjanV2Jihgjghjkghjkgjkghjkgh5_3Ux_ScSY4YMfkTELwBl';
$fields = array(
'to' => $token,
'notification' => array('title' => $message, 'body' => $msgBody,'business_id' => $busisId,'click_action' => '.activity.HomeActivity'),
'data' => array('title' => $message,'business_id' => $busisId)
);
$headers = array
(
'Authorization: key='. $APIKey,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode($fields) );
$result = curl_exec($ch );
curl_close( $ch );
return true;
}
Best article, very useful and explanation. Your post is extremely incredible. Thank you very much for the new information.
ReplyDeleteReact Js course in Hyderabad with placement
React Js course with placement in Hyderabad
React Js Training Center in Hyderabad
Dil Bechara 2020 FHD Download Here
ReplyDeleteSushant Singh Rajput Last Movie Dil Bechara 2020 Download HDRip