我有一个要求,我需要使用 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);
?>