Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的GCM纯文本推送通知?_Php_Android_Push Notification_Google Cloud Messaging_Plaintext - Fatal编程技术网

PHP中的GCM纯文本推送通知?

PHP中的GCM纯文本推送通知?,php,android,push-notification,google-cloud-messaging,plaintext,Php,Android,Push Notification,Google Cloud Messaging,Plaintext,我是android和PHP的新手。我正在处理推送通知。 我读过很多教程,但都是针对Json而不是纯文本的。 这里是For json代码,但我只想发送纯文本。 我读过这个 我也读过这篇文章。 我的密码在这里,有人能帮我吗 <?php $gcm_regid = 'fkjfsdhfsuvgsdhfkfkjshdfuwfsdfh9wfjehf9ufwjfhu9erfjkhf9efiefhwodfh9'; // GCM Registration ID $registatoin_ids

我是android和PHP的新手。我正在处理推送通知。 我读过很多教程,但都是针对Json而不是纯文本的。 这里是For json代码,但我只想发送纯文本。 我读过这个

我也读过这篇文章。

我的密码在这里,有人能帮我吗

   <?php

$gcm_regid = 'fkjfsdhfsuvgsdhfkfkjshdfuwfsdfh9wfjehf9ufwjfhu9erfjkhf9efiefhwodfh9'; // GCM Registration ID
$registatoin_ids = array($gcm_regid);
$message = array("message" => "Hello test");


// Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

    $fields = array(
        'registration_ids' => $gcm_regid,
        'data' => 'helloword',
    );

    $headers = array(
        'Authorization: key=12dsdsvefdfdfgdfgdfgdfgfgfgfg',
        'Content-Type: application/x-www-form-urlencoded'
    );
    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    // Execute post
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }

    // Close connection
    curl_close($ch);
    echo $result;

  ?>

如果尝试使用纯文本,则应忽略此块中的上下文类型

 $headers = array(
        'Authorization: key=12dsdsvefdfdfgdfgdfgdfgfgfgfg',
        'Content-Type: application/x-www-form-urlencoded'
    );
此外,对于纯文本,应该使用注册ID在名为
registration\u ID
的参数中传递,而不是
registration\u ID
数组