【问题标题】:apple push notification for iOS and google cloud messaging for android using php?使用 php 的 iOS 的苹果推送通知和 android 的谷歌云消息?
【发布时间】:2014-12-03 00:25:26
【问题描述】:

我正在寻找可以向 ios 设备和 android 设备发送推送通知的 php 代码。

我个人使用easyapns作为ios推送通知,使用gcm作为android推送通知。

我想合并两个代码并制作一个代码来为两个设备发送推送通知。

我只处理 php 部分。有什么解决办法让它变得简单吗?

【问题讨论】:

  • 我已经解决了这个问题,方法是在数据库中设置一个字段来告诉每个设备的类型。我将它们分组并将android设备和ios设备一起推送
  • 如果您提供该代码,我将不胜感激,因为这是我需要的。我在数据库中创建了一个具有列设备类型的表。并且条目将只有 ios 或 android
  • 对不起,我没有多余的代码,就像我在 Java 中做的那样,不是 PhP,但你可以使用相同的逻辑
  • 没问题,先生。我试试你的逻辑。感谢您的信息

标签: php android ios notifications push-notification


【解决方案1】:

经过我的研究,我找到了一个适用于 ios 的解决方案。

 public function send_notification($registration_id,$message,$ios_certificate,$badge,$tHost){
    // Provide the Host Information.
    //$tHost = 'gateway.sandbox.push.apple.com';

    $tPort = 2195;

    // Provide the Certificate and Key Data.
    //$tCert = 'certificates/meetmethere/apns-dev-cert.pem';
    $tPassphrase = '';

    //$tToken = 'efdf10632aa4e711ef8c57abf2a3cdec51e7c42811bb998c3e26de2876bac8fa';
    //$tAlert = 'this is the test message ';

    // The Badge Number for the Application Icon (integer >=0).

    $tBadge = 0;

    // 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' => $message,
                        'badge' => $badge,
                        'sound' => $tSound,
                    );

    $tBody ['payload'] = $tPayload;
    $tBody = json_encode ($tBody);

    // Create the Socket Stream.
    $tContext = stream_context_create ();

    stream_context_set_option ($tContext, 'ssl', 'local_cert', $ios_certificate);

    // 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)
        $status=false;

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

    // Send the Notification to the Server.

    $tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));

    if ($tResult)
        $status=true;
    else
        $status=false;
    fclose ($tSocket);

            return $status;
}`

【讨论】:

    【解决方案2】:

    给你一些链接希望这样可以帮助你在安卓设备上发送推送通知。

    如果您有任何疑问,请告诉我,我可以帮助您Send Push Notification on android devide

    【讨论】:

    • 我已经尝试过了,它可以工作,但这个工作只适用于 android.. 如果我使用 ios 设备怎么办?
    • pushnotification to IOS 看看这个希望对你有帮助。
    • 兄弟它仅适用于 ios。但我想结合 ios 和 android
    猜你喜欢
    • 2015-03-08
    • 2015-07-17
    • 1970-01-01
    • 2014-05-31
    • 2014-04-05
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多