关于IOS php推送消息始终不成功,但是php程序运行一切正常
推送始终不生效,麻烦各位大神帮我看看
php代码:
<?php
$deviceToken = '70449ecf02f227e29b777baa15a74756e03986493e9b5d20b765df4627bd7afb';
$passphrase = '955999';
$message = 'My first push test!';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
echo "<br/>----------1----------<br/>";
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
echo "<br/>----------2----------<br/>";
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo "<br/>----------3----------<br/>";
echo 'Connected to APNS <br/>' . PHP_EOL .'<br/>';
$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)
echo '<br/>----------4----------Message not delivered-------------------' . PHP_EOL;
else
echo '<br/>----------5----------Message successfully delivered-------------------' . PHP_EOL;
// Close the connection to the server
fclose($fp);
?>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。