gpt4 book ai didi

ios - 推送通知警报来了两次

转载 作者:行者123 更新时间:2023-11-29 03:01:37 25 4
gpt4 key购买 nike

我做了一个应用程序,因为我已经实现了推送通知,但是当我通过管理面板发送通知时,通知警报在我的设备中出现了两次。我已经创建了单独的配置文件和证书以及 ck.pem 文件。

请帮帮我。

========

function sendnote_ios($message,$registatoin_ids_arr_ios){



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

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

$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.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(
'alert' => $message,
'sound' => 'default'
);
//echo '<pre>';print_r($body);
// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
foreach($registatoin_ids_arr_ios as $token){
$msg = chr(0) . pack('n', 32) . pack('H*', trim($token)) . pack('n', strlen($payload)) . $payload;
//$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
}

// 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;
*/
// Close the connection to the server
fclose($fp);
}

最佳答案

让我们试试:

<?php
//your device token
$deviceToken = '';

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

// Put your alert message here:
$message = 'My first push notification!';

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

$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.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(
'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;

// Close the connection to the server
fclose($fp);

关于ios - 推送通知警报来了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23234822/

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