繁体   English   中英

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

[英]GCM plain text Push notification in PHP?

我是新来的android和PHP。 我正在研究推送通知。 我已经阅读了许多教程,但是所有教程都是针对Json的,而不是纯文本的。 对于json代码在这里,但我只想发送纯文本。 我已经读过了。

https://github.com/mattg888/GCM-PHP-Server-Push-Message/blob/master/GCMPushMessage.php

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

我也读过这个。 GCM Error = MissingRegistration通过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_id代替registration_ids阵列。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM