[英]How to send push notifications using UDID in PHP
I have a requirement where i need to send push notification using UDID instead of Device token, I have a working code which can send push notification using device token but i have to be able to send it using UDID as well 我有一个需要使用UDID而不是设备令牌发送推送通知的要求,我有一个可以使用设备令牌发送推送通知的工作代码,但我也必须能够使用UDID发送推送通知
<?php
$deviceToken = $_POST['devicetoken'];
$passphrase = '***********************';
$message = $_POST['message'];
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'dist.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'date' => date('U')
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
echo $message ;
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . $result;
fclose($fp);
?>
As far as i know, Apple has started rejecting application which uses UDID for Push notifications. 据我所知,苹果已经开始拒绝使用UDID进行推送通知的应用程序。 I recommend reviewing Apple terms before implementing push notification with UDID. 我建议在使用UDID实施推送通知之前先查看Apple条款。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.