开发者社区> 问答> 正文

关于IOS php推送消息始终不成功,但是php程序运行一切正常的问题

关于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);
?>

展开
收起
爵霸 2016-03-06 10:02:15 3835 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    有可能是Provisioning Profiles没有配置.

    2019-07-17 18:54:04
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-直面PHP微服务架构挑战-高驰涛 立即下载
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载