<bdo id='56pF3'></bdo><ul id='56pF3'></ul>
  1. <legend id='56pF3'><style id='56pF3'><dir id='56pF3'><q id='56pF3'></q></dir></style></legend>

  2. <tfoot id='56pF3'></tfoot>
    <i id='56pF3'><tr id='56pF3'><dt id='56pF3'><q id='56pF3'><span id='56pF3'><b id='56pF3'><form id='56pF3'><ins id='56pF3'></ins><ul id='56pF3'></ul><sub id='56pF3'></sub></form><legend id='56pF3'></legend><bdo id='56pF3'><pre id='56pF3'><center id='56pF3'></center></pre></bdo></b><th id='56pF3'></th></span></q></dt></tr></i><div id='56pF3'><tfoot id='56pF3'></tfoot><dl id='56pF3'><fieldset id='56pF3'></fieldset></dl></div>

    1. <small id='56pF3'></small><noframes id='56pF3'>

    2. GCM 与 PHP(谷歌云消息)

      时间:2024-08-22
        <bdo id='jxX03'></bdo><ul id='jxX03'></ul>

          <tbody id='jxX03'></tbody>
          <legend id='jxX03'><style id='jxX03'><dir id='jxX03'><q id='jxX03'></q></dir></style></legend>

        1. <small id='jxX03'></small><noframes id='jxX03'>

            <i id='jxX03'><tr id='jxX03'><dt id='jxX03'><q id='jxX03'><span id='jxX03'><b id='jxX03'><form id='jxX03'><ins id='jxX03'></ins><ul id='jxX03'></ul><sub id='jxX03'></sub></form><legend id='jxX03'></legend><bdo id='jxX03'><pre id='jxX03'><center id='jxX03'></center></pre></bdo></b><th id='jxX03'></th></span></q></dt></tr></i><div id='jxX03'><tfoot id='jxX03'></tfoot><dl id='jxX03'><fieldset id='jxX03'></fieldset></dl></div>
            <tfoot id='jxX03'></tfoot>

              1. 本文介绍了GCM 与 PHP(谷歌云消息)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                更新: GCM 已弃用,请使用 FCM

                如何将新的 Google Cloud Messaging 集成到 PHP 后端?

                How can I integrate the new Google Cloud Messaging in a PHP backend?

                推荐答案

                此代码将通过 PHP CURL 向多个注册 ID 发送 GCM 消息.

                This code will send a GCM message to multiple registration IDs via PHP CURL.

                // Payload data you want to send to Android device(s)
                // (it will be accessible via intent extras)    
                $data = array('message' => 'Hello World!');
                
                // The recipient registration tokens for this notification
                // https://developer.android.com/google/gcm/    
                $ids = array('abc', 'def');
                
                // Send push notification via Google Cloud Messaging
                sendPushNotification($data, $ids);
                
                function sendPushNotification($data, $ids) {
                    // Insert real GCM API key from the Google APIs Console
                    // https://code.google.com/apis/console/        
                    $apiKey = 'abc';
                
                    // Set POST request body
                    $post = array(
                                    'registration_ids'  => $ids,
                                    'data'              => $data,
                                 );
                
                    // Set CURL request headers 
                    $headers = array( 
                                        'Authorization: key=' . $apiKey,
                                        'Content-Type: application/json'
                                    );
                
                    // Initialize curl handle       
                    $ch = curl_init();
                
                    // Set URL to GCM push endpoint     
                    curl_setopt($ch, CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/send');
                
                    // Set request method to POST       
                    curl_setopt($ch, CURLOPT_POST, true);
                
                    // Set custom request headers       
                    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                
                    // Get the response back as string instead of printing it       
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                
                    // Set JSON post data
                    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
                
                    // Actually send the request    
                    $result = curl_exec($ch);
                
                    // Handle errors
                    if (curl_errno($ch)) {
                        echo 'GCM error: ' . curl_error($ch);
                    }
                
                    // Close curl handle
                    curl_close($ch);
                
                    // Debug GCM response       
                    echo $result;
                }
                

                这篇关于GCM 与 PHP(谷歌云消息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何使用php更新mysql中的多个列 下一篇:Pushnotification 服务器端实现

                相关文章

              2. <legend id='a6IlU'><style id='a6IlU'><dir id='a6IlU'><q id='a6IlU'></q></dir></style></legend>
                  <bdo id='a6IlU'></bdo><ul id='a6IlU'></ul>

                <small id='a6IlU'></small><noframes id='a6IlU'>

                    <i id='a6IlU'><tr id='a6IlU'><dt id='a6IlU'><q id='a6IlU'><span id='a6IlU'><b id='a6IlU'><form id='a6IlU'><ins id='a6IlU'></ins><ul id='a6IlU'></ul><sub id='a6IlU'></sub></form><legend id='a6IlU'></legend><bdo id='a6IlU'><pre id='a6IlU'><center id='a6IlU'></center></pre></bdo></b><th id='a6IlU'></th></span></q></dt></tr></i><div id='a6IlU'><tfoot id='a6IlU'></tfoot><dl id='a6IlU'><fieldset id='a6IlU'></fieldset></dl></div>
                  1. <tfoot id='a6IlU'></tfoot>