PushServerURL = "https://android.googleapis.com/gcm/send"
' 브라우저APIkey
ApplicationAPIKey = "android_api_key"
' regId(받을사람이 지급받은 registration_ids - 여러명일 경우 배열로 받아처리하면 될 듯 최대 1000)
RegId = "디바이스_id"
' 알림 제목
contentTitle = "테스트 제목"
' 알림 내용
message = "테스트"
postJSONData = "" & _
"{" & _
" ""registration_ids"" : [ """ & RegId & """ ]" & _
", ""data"": {" & _
" , ""title"" : """ & contentTitle & """" & _
" , ""msg"" : """ & message & """" & _
" }" & _
"}"
Set httpObj = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
httpObj.open "POST" , PushServerURL, False
httpObj.SetRequestHeader "Content-Type", "application/json"
httpObj.SetRequestHeader "Authorization", "key=" & ApplicationAPIKey
httpObj.Send postJSONData
httpObj.WaitForResponse
If httpObj.Status = "200" Then
response.Write("전송성공 : " & httpObj.ResponseText)
Else
response.Write("전송실패 : " & httpObj.ResponseText)
End If
위의 소스는 asp에서 작성된 코드구요
서버에 접속할 수 없습니다 라는 메세지가 나오는데.. 그 이유를 전혀 모르겠어서 염치 불구하고 질문을 올립니다...
다른 방법을 찾다가 아래와 같은 방법으로 해결해 보려 했으나 아래방법 또한 정상적으로 작동이 안되네요 ㅠㅠ
var api_key = "android_api_key";
var regid = "APA91bG8qGW-3t5MgmUtYdMnxbp.............";
var sender_id = "프로젝트number";
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json=charset=UTF-8");
xhrObj.setRequestHeader("Authorization","key="+api_key);
},
url: "https://android.googleapis.com/gcm/send",
type: "POST",
dataType: "json",
registration_id : regid,
SENDER_ID : sender_id,
data:{
"title" : "푸시테스트",
"msg" : "GCM 테스트"
},
success: function(data) {
alert("성공");
},
error: function(data) {
alert("에러:");
console.log(data);
}
});
어느부분이 잘못된것인지.. 알려주시면 참고하도록 하겠습니다...!!