gpt4 book ai didi

php - 在推送通知的有效负载中隐藏 URL

转载 作者:行者123 更新时间:2023-12-04 04:34:03 24 4
gpt4 key购买 nike

我正在将 URL 和一条消息从 PHP 发送到 ios 设备作为推送通知。我想要的是我想发送带有一个 URL 和消息的推送通知,但必须隐藏 URL。当用户将在 ios 设备上看到 PNS 时,他/她只能看到消息而不是那个 URL。like whatsapp messenger

这是我的 PHP 代码

// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.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;
// Create the payload body
$body['aps'] = array(
'badge' => +1,
'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));

最佳答案

您应该将 URL 放在 aps 之外字典:

{

"aps" : {

"alert" : "<Your message>",

"badge" : <your badge>,

"sound" : "default"

},

"url" : "http://www.some.url.com"

}

我不知道 php ,所以我不能给你确切的代码。

关于php - 在推送通知的有效负载中隐藏 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20063820/

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