I am sorry if it is a duplicate question but I couldn't found the solution I was looking for.Here is my php service code to send notification on Iphone:
我很抱歉,如果这是一个重复的问题,但我找不到我正在寻找的解决方案。这是我的PHP服务代码发送Iphone通知:
<?php
$data = array();
// Put your device token here (without spaces):
$deviceToken = 'eb9ea0d12eb9a0bae159c7e54fa59baee22329df';
// Put your private key's passphrase here:
$passphrase = 'dell';
$message = 'Push notification service';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'application/controllers/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
// exit("Failed to connect: $err $errstr" . PHP_EOL);
$data['response'] = 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) .$payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
$data['response'] = 'Message not delivered' . PHP_EOL;
else
$data['response'] = 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
$response->skills = $data;
$this->response($response, 200);
?>
I am running above service in php(code Ignitor) to send notification but i am not using code ignitor. Although the above service is running successfully but i am not receiving notification on my phone. Can anybody tell whats the problem.
我在php(代码Ignitor)上运行服务以发送通知但我没有使用代码点火器。虽然上述服务运行成功但我没有收到手机通知。任何人都可以告诉我们这个问题。
1 个解决方案
#1
0
This works for me:
这对我有用:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certFilePath);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
$webServiceLocation = 'tls://gateway.push.apple.com:2195';
$fp = stream_socket_client(
$webServiceLocation, $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp) exit("Failed to connect: $err $errstr" . PHP_EOL);
$body['aps'] = array('alert' => $message, 'sound' => 'default');
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
fclose($fp);
#1
0
This works for me:
这对我有用:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certFilePath);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
$webServiceLocation = 'tls://gateway.push.apple.com:2195';
$fp = stream_socket_client(
$webServiceLocation, $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp) exit("Failed to connect: $err $errstr" . PHP_EOL);
$body['aps'] = array('alert' => $message, 'sound' => 'default');
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
fclose($fp);