我已經實現了從C2DM服務器請求註冊ID的C2DM客戶端。一旦應用程序獲得註冊ID,應用程序將設備ID和註冊ID存儲在服務器數據庫中我已經實現了一個PHP服務器,但是當我嘗試發佈消息時,我得到Error = MissingRegistration。Android C2DM缺少註冊錯誤?
PHP服務器代碼
$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);
根據該文件錯誤= MissingRegistration如果在發佈採購信息不registration_id參數發生。我甚至試圖通過對註冊ID進行硬編碼來運行應用程序。任何幫助不勝感激。謝謝。
結構清晰,明確的問題。我甚至不知道PHP,但我仍然可以理解一切。值得+1。仍然在尋找問題。 – 2012-02-18 10:04:39
@Boris謝謝:) – iNan 2012-02-18 10:06:47