• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

php - IOS通知批量内部服务器错误500

[复制链接]
菜鸟教程小白 发表于 2022-12-12 19:31:11 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

目前,我们正在尝试使用他们的 UDID 向我们的 iOS 开发人员发送推送通知。在测试以下脚本时,我正确收到了通知,但是在发送批量(比如说 2000)时,我们收到了内部服务器错误 (500) 消息。

我已经阅读了一些内容,例如向许多通知发送真正的管道,这会导致来自 Apple 的连接关闭。

有人知道我做错了什么吗?

include ('functions/functions.php');

function sendNotification($deviceID, $message)
{   
    // Provide the Host Information.
    $tHost = 'gateway.push.apple.com';
    $tPort = 2195;

    // Provide the Certificate and Key Data.
    $tCert = 'pk.pem';

    // Provide the Private Key Passphrase (alternatively you can keep this secrete
    // and enter the key manually on the terminal -> remove relevant line from code).
    // Replace XXXXX with your Passphrase
    $tPassphrase = 'xxx';

    // Provide the Device Identifier (Ensure that the Identifier does not have spaces in it).
    // Replace this token with the token of the iOS device that is to receive the notification.
    //$tToken = $value;

    // The message that is to appear on the dialog.
    $tAlert = $message;

    // The Badge Number for the Application Icon (integer >=0).
    $tBadge = 1;

    // Audible Notification Option.
    $tSound = 'default';

    // The content that is returned by the LiveCode "pushNotificationReceived" message.
    $tPayload = $message;

    // Create the message content that is to be sent to the device.
    $tBody['aps'] = array (
        'alert' => $tAlert,
        'badge' => $tBadge,
        'sound' => $tSound,
        );
    $tBody ['payload'] = $tPayload;

    // Encode the body to JSON.
    $tBody = json_encode ($tBody);

    // Create the Socket Stream.
    $tContext = stream_context_create ();
    stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);

    // Remove this line if you would like to enter the Private Key Passphrase manually.
    stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);

    // Open the Connection to the APNS Server.
    $tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);

    // Check if we were able to open a socket.
    if (!$tSocket)
        exit ("APNS Connection Failed: $error $errstr" . PHP_EOL);

    // Build the Binary Notification.
    $tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $deviceID) . pack ('n', strlen ($tBody)) . $tBody;

    // Send the Notification to the Server.
    $tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));    

    /*if ($tResult)
        echo 'Delivered Message to APNS' . PHP_EOL;
    else
        echo 'Could not Deliver Message to APNS' . PHP_EOL;*/

    // Close the Connection to the Server.
    fclose ($tSocket);
}



Best Answer-推荐答案


假设您有一个带有设备 ID 的数组 $devices。您可以使用重复循环并包含 sleep 功能:

$message = 'Nice to meet you.';
foreach ($devices as $deviceID) {
  sendNotification($deviceID, $message);
  usleep(500000);
}

但是,如果您实际上并未使用 2000 个不同设备进行测试,Apple 仍可能会阻止您的请求。

关于php - IOS通知批量内部服务器错误500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22046027/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap