0

이 코드를 사용해 보았습니다. Phonegap PHP를 통해 메시지를 보낼 때 401 오류가 발생했습니다.

function sendNotification($apiKey, $registrationIdsArray, $messageData) 
{ 
    $headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey); 
    $data = array(
     'data' => $messageData, 
     'registration_ids' => $registrationIdsArray 
    ); 

    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); 

    $response = curl_exec($ch); 
    curl_close($ch); 

    return $response; 
} 

그리고이 함수를 호출하기 :

$message  = "the test message"; 
$tickerText = "ticker text message"; 
$contentTitle = "content title"; 
$contentText = "content body"; 

$registrationId = 'APA91bEgsAG3vmliDnJE7jfLAOGSUv3K9p41MkNranPFV4EY0svABRax8NY5oulOHv7s3v2Ks_bQutsLLw8j4mHOr5LkrRlFfXxfs3hxxwAlxIOG7cXCB4YPhlLCDspVtImyWBL_znGgkZzEWCncV3tidHMV'; (Id is wrong here for security reasons) 
$apiKey = "AIzaSyD6kZoY3Qb_1ut57IEmwdRg0JuxC42W1"; (Key is wrong here for security reasons) 

$response = sendNotification( 
       $apiKey, 
       array($registrationId), 
       array('message' => $message, 'tickerText' => $tickerText, 'contentTitle' => $contentTitle, "contentText" => $contentText)); 

echo $response; 

지금은 붙어 있습니다. 난 그냥 내 자신의 등록 ID와 구글 API 키를 가진 PHP 페이지를 만든다.

그러나 그것은 나에게의 오류 표시 :이 URL을 http://vbought.com/sendnotification.php

심지어 추가 한 GCM 참조 내 서버 IP 및 도메인 이름

.vbought을 실행하면 무단 오류 401

을 .com/

* .vbought.com

50.87.3.82

내가 잘못 했나요? 아니면 내가 알아야 할 것인가? 내 유일한 장치에 하나의 메시지를 보내려고합니다.

감사합니다. (사전에)

+0

컬이 문제라고 생각합니다. 거기에서 벗어날 방법이 있습니까? – user3201500

답변

1

답변을 찾았습니다. 그리고 대답은 GCM에서 아무것도 정의 할 필요가 없다는 것입니다. 마찬가지로 나는 나의 도메인 이름과 IP 주소를 정의했다. 그래서 나는 아무 것도 할 필요가 없다. 그냥 비워두면 매력처럼 작동합니다 ...

좋은 하루 되세요 :)

관련 문제