0
문제가 생겼습니다. 장치에 메시지 알림 및 경고 알림을 보내야합니다. 사용자가 다른 사람에게 메시지를 보내고 서버에서 사용자에게 알리도록 경고 알림이 생성되면 메시지 알림이 전송됩니다. 즉 여러 알림 유형이 필요합니다. 내 서버에서 알림을 내 기기로 푸시합니다.Android GCM이 기기에 여러 개의 메시지를 보냅니다.
// This is code from the class that take user input
$notify = "This is message"
$msg = array("Message" => $notify);
$sense = $gcm->send_notification($registatoin_ids, $msg);
//This is the send notification in GCM class
public function send_notification($registatoin_ids, $message) {
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
내 요구 사항을 충족시키기 위해 위 코드를 어떻게 조정할 수 있습니까? 나는
$fields = array(
"registration_ids" : registatoin_ids,
"data" : {
"type" : "Message",
"Message" : $message,
}
);
을 보내려고하지만 당신은이에 대한 =>
연산자를 사용할 필요가
E/JSON(3444): <b>Parse error</b>: syntax error, unexpected ':', expecting ')' in <b>/home/a8709494/public_html/mobile/GCM.php</b> on line <b>25</b><br />
감사하지만 난'registration_ids을 둘 필요 ''를 하나의 따옴표에 묶어서받은 다음 번들 {{android.support.content.wakelockid = 1, collapse_key = do_not_collapse, from = xxxxxxxxxxxx, type = Message, Message = { "Message": "From"Me 당신에게. "}}] '다시 큰 따옴표로 작업하지 못했습니다. 어떻게 클라이언트 측에서이 문자열을 처리 할 수 있습니까? 나는 GCMIntentService를'private void sendNotification (String msg)'로 imlement하고'msg = ""Message ":"From : Me to you. "}" "" – Nepal12
이미 사용했던 것과 동일한 기술을 사용할 수 있습니다 : Define 이를 구현하기 위해 몇 가지 중첩 된 배열. 변수를 전달하면 작은 따옴표로 대체 할 수 없으며 큰 따옴표 만 변수의 값을 확장합니다. 평판과 피드백 모두에 대한 목표를 달성했으면 그 때까지 얻을 수있는 모든 것에서 가장 도움이 된 답변을 수락하는 것을 잊지 마십시오. – nKn