我已经实现了从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