2014-01-19 5 views
1

GCM과 컬링을 사용하여 서버에서 클라이언트 (안드로이드)로 메시지를 보내려고하는데 내가 사용한 코드가 localhost (에뮬레이터 및 장치)에서 완벽하게 작동했지만 일반용으로는 작동하지 않습니다. 서버에 연결된 코드는 사용 된 코드이며 오류 메시지는GCM 컬 연결 오류

입니다. 온라인 서버에서 코드를 작동시키기 위해 수행해야 할 추가 단계 나 변경 사항이 있습니다. 어떤 도움에 감사드립니다 :)

<?php 

function Reg($USER_REG_ID) 
{ 
    require_once __DIR__ . '/db_connect.php'; 
    $db = new DB_CONNECT(); 
    $response = array(); 
    $API_Key = 'AIzaSyCQgPGhpAzuWGuUd0DCI8pYaXXAItthEsg'; 
    $url  = 'https://android.googleapis.com/gcm/send'; 


    $result = mysql_query("SELECT * FROM users where type = 'bus'") or die(mysql_error()); 

    while ($row = mysql_fetch_array($result)) { 

     $Registration_ID = $row["user_RegID"]; 
     array_push($response, $Registration_ID); 

    } 

//THIS PART SENDS TEH REQUEST USING GCM 
    $fields = array(
     'registration_ids' => $response, 
     'data' => array(
      "message" => $USER_REG_ID 
     ) 
    ); 

     print_r ($fields); 

    $headers = array(
     'Authorization: key=' . $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); 


} 
Reg(1) 
?> 

필드 배열

Array ([registration_ids] => Array ([0] => APA91bFolV5ZK2diIbTyxwPLp6BqTMdhqaMDYgEsGOlznmxn4NRV6QQzPtfr58ORrpmxq0N_UMwz6s30gWgj--w5SqHxCEHh662PnvjDpGce_4EiHDe-muflVYMOsLlbVDRybvNDubX9aF_RE4VPJdArUsqQjcrQRg) [data] => Array ([message] => 1)) 

오류 메시지이 그것을해야

Curl failed: Failed to connect to 2a00:1450:400c:c05::5f: Network is unreachable 

답변

2

:

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 

위 아무튼이 ' T는 작품, 당신은 ipv6 시스템을 해제하려고 할 수 있습니다 승 ide :

echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6 
+0

답장을 보내 주셔서 감사합니다. D – user2652614

+0

언제나 기꺼이 도와 드리겠습니다. –

+0

@ user2652614 문제가 발생했습니다. 어떤 솔루션이 당신을 위해 일 했는가. 처음에는 도움이 안되고 두 번째 것을 어디에서 사용해야할지 모르겠다. – dreamer1989