나는 C2DM 서버에서 등록 ID를 요청하는 C2DM 클라이언트를 구현했습니다. 응용 프로그램이 등록 ID를 얻으면 응용 프로그램은 장치 ID와 등록 ID를 서버 데이터베이스에 저장합니다. PHP 서버를 구현했지만, 메시지를 게시하려고 시도 할 때 Error = MissingRegistration이 발생합니다. POST 요청에는 registration_id 매개 변수가없는 경우 문서 오류 = MissingRegistration에 따르면 PHP 서버 코드Android C2DM 등록 오류가 누락 되었습니까?
$url = 'https://www.google.com/accounts/ClientLogin';
$body = '[email protected]&Passwd=password&accountType=GOOGLE&source=MyLittleExample&service=ac2dm';
$c = curl_init ($url);
curl_setopt ($c, CURLOPT_POST, true);
curl_setopt ($c, CURLOPT_POSTFIELDS, $body);
curl_setopt ($c, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec ($c);
$p = explode("Auth=",$page);
curl_close ($c);
$url = 'https://android.apis.google.com/c2dm/send';
$param = // Get Registration id from my sql
$mtype = 'important';
$msg = 'Hello';
$len = strlen($param);
echo $len;
function sendMessageToPhone($authCode, $deviceRegistrationId, $msgType, $messageText) {
$headers = array('Content-length:300','Authorization: GoogleLogin auth='.$authCode);
$data = array(
'registration_id' => $deviceRegistrationId,
'collapse_key' => $msgType,
'data.message' => $messageText //TODO Add more params with just simple data instead
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send");
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$data = sendMessageToPhone($p[1],$param,$mtype,$msg);
var_dump($data);
가 발생합니다. 심지어 등록 ID를 하드 코딩하여 응용 프로그램을 실행하려고했습니다. 어떤 도움이라도 대단히 감사합니다. 고맙습니다.
잘 구조화하고 명확한 질문입니다. 나는 PHP조차 모르지만 여전히 모든 것을 이해할 수 있습니다. +1이 필요합니다. 그래도 문제를 찾고 있습니다. –
@ 보리스 감사합니다 :) – iNan