Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.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 android发送的谷歌云消息(GCM)错误无效_Php_Android_Curl - Fatal编程技术网

Php android发送的谷歌云消息(GCM)错误无效

Php android发送的谷歌云消息(GCM)错误无效,php,android,curl,Php,Android,Curl,我正在用Google cloud message(GCM)后续文章构建一个应用程序 但当我尝试通过带有链接和代码中的某些字段的CURL向Google服务器发送通知时,我遇到了错误 function send_push_notification($registatoin_ids, $message) { echo implode($registatoin_ids); echo implode($message); // Set POST variables $u

我正在用Google cloud message(GCM)后续文章构建一个应用程序

但当我尝试通过带有链接和代码中的某些字段的CURL向Google服务器发送通知时,我遇到了错误

 function send_push_notification($registatoin_ids, $message) {

    echo implode($registatoin_ids);
    echo implode($message);
    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

    $fields = array(
        'registration_ids' => $registatoin_ids,
        'data' => $message,
    );

    $headers = array(
        'Authorization: key=' . GOOGLE_API_KEY,
        'Content-Type: application/json'
    );
    //print_r($headers);
    // Open connection
    $ch = curl_init();

    //echo $ch;
    // 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) {
        echo ("RESULT ERROR :" + $ch);
        die('Curl failed: ' . curl_error($ch));

    }

    // Close connection
    curl_close($ch);
    echo $result;
}
我在尝试发送时收到一个结果错误

所以,你能帮我修复或配置发送消息到服务器,我尝试制作一个应用程序,从服务器发送通知到Android设备, 多谢各位

对我的英语很抱歉,再次谢谢


Huan

您使用的教程太旧了

看这里:

 GCMRegistrar.setRegisteredOnServer(context, true);
此类已弃用

现在,您应该使用