关于IOS php推送不成功问题

Mr.Z Mr.Z 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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);
?>



请各位大神帮我看看

...全文
评论 8
收藏 已收藏
分享
返回顶部
Mr.Z
Framework 4,250 成员 4,522 内容