gpt4 book ai didi

php - 如何在新版本的 ios 中使用 php 从服务器在 ios 中发送推送通知,而不使用 pem 文件

转载 作者:可可西里 更新时间:2023-11-01 03:50:35 25 4
gpt4 key购买 nike

我已经在旧版本的 ios 中发送了通知。但在较新的版本中,我无法创建 .pem 文件。有人告诉我不再需要 pem 文件来从服务器发送通知。但是运气不好,我无法找到与此相关的任何链接。有人请指导我如何在较新版本的 ios 中从服务器发送推送通知。自上周以来,我一直在发送通知。请帮忙。这是我正在使用的代码

private function pushnotification($deviceToken, $message, $type, $badge, $userid, $jobid) {
$passphrase = '123456';

$ctx = stream_context_create();

// $file = base_path(). "/public/WenderCastPush.pem";
//stream_context_set_option($ctx, 'ssl', 'local_cert', $file);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
stream_context_set_option($ctx, 'ssl', 'verify_peer_name', false);
stream_context_set_option($ctx, 'ssl', 'allow_self_signed', true);
//stream_context_set_option($ctx, 'ssl','ciphers', 'TLSv1');
// 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);
$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);

$body['aps'] = array(
//'badge' => +1,
'alert' => $message,
'sound' => 'default',
//'title' => $message,
'type' => $type,
'userid' => $userid ,
'jobid' => $jobid,
);
// Encode the payload as JSON
$payload = json_encode($body);


$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)
$responce = 'Message not delivered' . PHP_EOL;
else
$responce = 'Message successfully delivered' . PHP_EOL;

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

最佳答案

您可以使用 Firebase 发送通知。
您的 iOS 应用应使用 Firebase 进行编译。
并使用 Post 方法调用以下地址

visit this link

这不是很难。

检查 this video .

关于php - 如何在新版本的 ios 中使用 php 从服务器在 ios 中发送推送通知,而不使用 pem 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46474822/

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