什么url可以用来实现新的GCM框架的Http服务器?


What url can be used to implement Http server for new GCM framework

我已经在我的项目中实现了用于发送消息的GCM,它在7月28日之前工作良好,突然,应用程序开始出现问题。我的代码样本从我的php应用服务器发送消息看起来像

 function setPush_Notification($device_Ids, $message) {
$url = "https://android.googleapis.com/gcm/send";
$GOOGLE_API_KEY = "MY_API_KEY";
$fields = array('registration_ids' => $device_Ids,
    'data' => $message,
);
$headers = array(
    'Authorization: key=' . $GOOGLE_API_KEY,
    'Content-Type: application/json'
);
$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) {
    print_r(curl_getinfo($ch));
    die('Curl failed: ' . curl_error($ch));
}
    curl_close($ch);
    return $result;
}

但是最近,我无法发送消息,似乎问题来自url,因为每次尝试都会返回错误:

连接失败[00:1450:4016:804::200a]网络不可达从我的发现它的服务器https://android.googleapis.com/gcm/send是不可达的,什么url现在用于从第三方应用程序服务器发送消息到GCM ????。

我试过其他url https://gcm-http.googleapis.com/gcm/send没有成功。有人有过这样的经历吗?请帮助

检查下面的链接,我在2天前的应用程序中使用它实现了GCM。它正在工作,看看这个https://developers.google.com/cloud-messaging/android/client

function px_sendGCM($message, $type) {
$result;
$options = get_option('gcm_setting');
$apiKey = $options['api-key'];
$url = 'https://android.googleapis.com/gcm/send';
$id = px_getIds();

if($id >= 1000){
    $newId = array_chunk($id, 1000);
    foreach ($newId as $inner_id) {
        $fields = array(
            'registration_ids' => $inner_id,
            'data' => array( $type => $message ),);
        $headers = array(
            'Authorization: key=' . $apiKey,
            'Content-Type: application/json');

        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_URL, $url );
        curl_setopt( $ch, CURLOPT_POST, true );
        curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
        $result = curl_exec($ch);
    }
}else {
    $fields = array(
        'registration_ids' => $id,
        'data' => array( $type => $message ),);
    $headers = array(
        'Authorization: key=' . $apiKey,
        'Content-Type: application/json');

    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
    $result = curl_exec($ch);
}

$answer = json_decode($result);

这是正确的URL,根据https://developers.google.com/cloud-messaging/http

https://gcm-http.googleapis.com/gcm/send

如果它不能工作,检查你的网络