GCM未经授权的错误401 php

时间:2016-06-15 07:51:13

标签: google-cloud-messaging unauthorized

我从5个月前使用gcm服务,它在服务器和应用程序方面运行良好。但是当我与另一个应用程序集成时突然出现了未经授权的错误,但是设备成功注册了gcm和php有未经授权的错误401.我在一个应用程序中使用了一个gcm api密钥。它在使用wamp

的本地服务器上正常工作

以下是我的PHP代码

public function send_notification($registatoin_ids, $message) {
                  $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'
    );
    // 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;
}

0 个答案:

没有答案