gpt4 book ai didi

php - 苹果推送通知 - PHP

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:06 27 4
gpt4 key购买 nike

<分区>

我在使用推送通知时遇到问题,当我使用开发时它可以工作,但是当我想真正使用它时,它不会工作。

ck 是为生产而制造的。

当我使用它时,结果是:消息成功发送但是我的手机收不到消息

<?php

pushNotification('wow2','DeviceToken');

function pushNotification($theMessage, $theDeviceToken)
{

// Put your device token here (without spaces):
$deviceToken = $theDeviceToken;

// Put your private key's passphrase here:
$passphrase = 'Code';

// Put your alert message here:
$message = $theMessage;

////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$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);
exit("" . PHP_EOL);
//echo 'Connected to APNS\n' . PHP_EOL;

// Create the payload body
$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 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;

fclose($fp);


}
?>

谁能看出哪里出了问题? :)

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com