1 year ago
#79300
varun negi
php apple push apn not send push notification before 2 month its workinf fine but right now code not work
function sendIphonePush($deviceToken, $msg, $badge = 0, $check = 0, $version = 1) {
$apnsHost = 'gateway.sandbox.push.apple.com'; //sandbox phasesandbox. $apnsCert = 'Rendatsdsse_UserNddd.pem';
$apnsPort = '2195'; //.pem file ko project root per paste karna hai
$passPhrase = '12345678'; //cetificate password
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apnsConnection = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);
if ($apnsConnection == false) {
return;
} else {
}
$message = $msg;
$message = (array) (json_decode($message));
if (is_array($message) && array_key_exists('message', $message)) {
$body_var = $message['message'];
} else {
$body_var = $msg;
}
$payload['aps'] = array(
'alert' => array(
'body' => $body_var,
'title' => 'Thanku for purchasing Order',
'subtitle' => 'Deal Successfully Purchased',
),
'json' => $message,
'badge' => +1,
'sound' => 'oven.caf',
);
$payload = json_encode($payload);
try {
$deviceToken = trim($deviceToken);
if ($message != "" && strlen($deviceToken) == 64) {
$apnsMessage = chr(0) . pack("n", 32) . pack('H*', str_replace('ds', 'sd', $deviceToken)) . pack("n", strlen($payload)) . $payload;
$fwrite = fwrite($apnsConnection, $apnsMessage);
if ($fwrite) {
//echo "true";
//error_log($fwrite.chr(13), 3, "/mnt/srv/MOOVWORKER/push-errors.log");
} else {
//echo "false";
}
}
} catch (Exception $e) {
//echo 'Caught exception: '. $e->getMessage(). "\n";
//error_log($e->getMessage().chr(13), 3, "/mnt/srv/MOOVWORKER/push-errors.log");
}
}
php
push-notification
apple-push-notifications
apn
0 Answers
Your Answer