웹 (브라우저)과 Android 클라이언트에서 모두 소비되는 슬림 PHP 네트워크를 기반으로 API를 작성했으며 Google Cloud를 구현하는 데 관한 질문이 있습니다. 안드로이드 클라이언트에 대한 푸시 알림 메시지. 기본적으로,이 내 현재의 데이터 구조Google Cloud 메시징을 사용하는 API의 데이터 구조
내가하고 싶은 것은 모든 장치에 전송 알림이입니다users:
--Fields:
----id
----name
----email
----password
posts:
--Fields:
----id
----post_title
----post_category
----post_content
----image_url
----created_at
comments:
--Fields:
----id
----comment
----mood
----created_at
post_comments (which holds the relationship between the post and the comment):
--Fields:
----id
----post_id
----comment_id
user_comments (which holds the relationship between the user and the comment):
--Fields:
----id
----user_id
----comment_id
인 포스트 테이블이있을 때 행이 추가 (즉, 특정 요구 사항을 충족). PHP에 대한 실제 푸시 기능을 이해하고 있지만, 안드로이드 장치에서 실행중인 장치를 등록하는 방법을 잘 모르겠습니다.
----has_device
----device_registration_id
및 (거짓에 대한 has_device = 0을 보낼 것이다 웹 클라이언트 반대) 안드로이드 장치가 로그인에 has_device = 1 PARAM을 보내 :이처럼 내 사용자 테이블에 두 개의 필드를 추가 할 생각 해당 사용자의 device_registration_id 필드가 비어 있는지 확인한 다음 새 등록 ID를 생성하고 해당 필드를 채 웁니다. 나는 올바른 길을 가고 있는가?
편집 : 이것은 내 PHP 송신 기능 것입니다. 등록 ID가없는 현재 해당 장치에 로그인 한 사용자에게 장치에 연결되어 있기 때문에
function sendNotification($apiKey, $registrationIdsArray, $messageData)
{
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
$data = array(
'data' => $messageData,
'registration_ids' => $registrationIdsArray
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
무엇이 문제입니까? – Eran
사용자 테이블에이 두 필드를 추가하는 것으로 충분할 것인지 또는 별도의 gcm_users 테이블이 필요한지 궁금합니다. 전에는 GCM을 사용한 적이 없으므로 비즈니스 로직이 어떻게 작동하는지 전혀 모릅니다. –