14. 1. 10.

안드로이드 Classic ASP PUSH 서버

push.asp 파일
<%
 ' 안드로이드 ASP 푸시 요청
 PushServerURL = "https://android.googleapis.com/gcm/send"

'  브라우저APIkey
 ApplicationAPIKey = "AIzaSyBi0pn1ckaJhRL9kK3mbwsHzk7x0fdE_Z8"

 ' regId(받을사람이 지급받은 registration_ids - 여러명일 경우 배열로 받아처리하면 될 듯 최대 1000)
 RegId = "APA91bFNkzpbgBJnWkDgyGmU0XsF8ZLMAEhVaAtcbf9po8_i1GoA4JNt4HiUc6xScBMEOoJMIHHybZECIns9e2EF4AGalfOgZqwmQIEUG1UpVk08nTapx0iY17vOELD_9wIQTUdRwUsR"

 ' 알림명
 tickerText = "알림테스트"
 ' 알림 제목
 contentTitle = "테스트 제목"
 ' 알림 내용
 message = "헬로~~~ 테스트입니다.~~~"

 postJSONData = "" & _
    "{" & _
    "  ""registration_ids"" : [ """ & RegId & """ ]" & _
    ", ""data"": {" & _
    "                 ""tickerText"" : """ & tickerText & """" & _
    "               , ""contentTitle"" : """ & contentTitle & """" & _
    "               , ""message"" : """ & 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

%>


참고:
html
<form method="post" action="push.asp">
    tickerText :
    <input type="text" name="tickerText" value="알림테스트" /><br>
    contentTitle :
    <input type="text" name="contentTitle" value="테스트 제목" /><br>
    message :
    <textarea name="message">헬로~~~ 테스트입니다.~~~</textarea><br>
    RegId :
    <input type="text" name="RegId" value="APA91bFNkzpbgBJnWkDgyGmU0XsF8ZLMAEhVaAtcbf9po8_i1GoA4JNt4HiUc6xScBMEOoJMIHHybZECIns9e2EF4AGalfOgZqwmQIEUG1UpVk08nTapx0iY17vOELD_9wIQTUdRwUsR" /><br>
    <input type="text" name="RegId" value="APA91bFNkzpbgBJnWkDgyGmU0XsF8ZLMAEhVaAtcbf9pp8_i1GoA4JNt4HiUc6xScBMEOoJMIHHybZECIns9e2EF4AGalfOgZqwmQIEUG1UpVk08nTapx0iY17vOELD_9wIQTUdRwUsR" /><br>
    <input type="text" name="RegId" value="APA91bFNkzpbgBJnWkDgyGmU0XsF8ZLMAEhVaAtcbf9pd8_i1GoA4JNt4HiUc6xScBMEOoJMIHHybZECIns9e2EF4AGalfOgZqwmQIEUG1UpVk08nTapx0iY17vOELD_9wIQTUdRwUsR" /><br>
    <input type="submit" value="전송요청" />
</form>
asp
<%
 tickerText = request.Form("tickerText")
 contentTitle = request.Form("contentTitle")
 message = request.Form("message")
 RegId_Count = request.Form("RegId").Count
 RegId = ""
 For i = 1 To RegId_Count
  if i<>1 then RegId = RegId & ","
  RegId = RegId & """" & request.Form("RegId")(i) & """"
 Next


 postJSONData = "" & _
    "{" & _
    "  ""registration_ids"" : [ " & RegId & " ]" & _
    ", ""data"": {" & _
    "                 ""tickerText"" : """ & tickerText & """" & _
    "               , ""contentTitle"" : """ & contentTitle & """" & _
    "               , ""message"" : """ & message & """" & _
    "            }" & _
    "}"

%>

댓글 2개:

  1. 지나가다 우연히 보고... 오래전 글인데 이정도 하셨다니 대단하시네요~ 지금도 되는지 모르겠으나... 좋은 자료로 한자 적고 갑니다. 따봉~~

    답글삭제