[英]Android C2DM Missing Registration Error?
我已經實現了一個C2DM客戶端,該客戶端從C2DM服務器請求注冊ID。 應用程序獲取注冊ID后,應用程序會將設備ID和注冊ID存儲在服務器數據庫中。 我已經實現了一個PHP服務器,但是每當我嘗試發布消息時,我都會收到Error = MissingRegistration。
PHP服務器代碼
$url = 'https://www.google.com/accounts/ClientLogin';
$body = 'Email=senderid@gmail.com&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);
根據文檔,如果Post請求中沒有registration_id參數,則會發生Error = MissingRegistration。 我什至嘗試通過對注冊ID進行硬編碼來運行應用程序。 任何幫助,不勝感激。 謝謝。
啊哈! 這是可能的解決方案(取自與我不知道的另一種語言有關的通知的線程): https : //stackoverflow.com/a/8339611/1108032 。 請閱讀他所說的解決他的問題的內容。 對我來說,類似的事情應該會讓您失望的,因為按代碼進行代碼似乎還可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.