push.asp 파일
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <% ' 안드로이드 ASP 푸시 요청 ' 브라우저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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | < form method = "post" action = "push.asp" > tickerText : < input type = "text" name = "tickerText" value = "알림테스트" /> contentTitle : < input type = "text" name = "contentTitle" value = "테스트 제목" /> message : < textarea name = "message" >헬로~~~ 테스트입니다.~~~</ textarea > RegId : < input type = "text" name = "RegId" value = "APA91bFNkzpbgBJnWkDgyGmU0XsF8ZLMAEhVaAtcbf9po8_i1GoA4JNt4HiUc6xScBMEOoJMIHHybZECIns9e2EF4AGalfOgZqwmQIEUG1UpVk08nTapx0iY17vOELD_9wIQTUdRwUsR" /> < input type = "text" name = "RegId" value = "APA91bFNkzpbgBJnWkDgyGmU0XsF8ZLMAEhVaAtcbf9pp8_i1GoA4JNt4HiUc6xScBMEOoJMIHHybZECIns9e2EF4AGalfOgZqwmQIEUG1UpVk08nTapx0iY17vOELD_9wIQTUdRwUsR" /> < input type = "text" name = "RegId" value = "APA91bFNkzpbgBJnWkDgyGmU0XsF8ZLMAEhVaAtcbf9pd8_i1GoA4JNt4HiUc6xScBMEOoJMIHHybZECIns9e2EF4AGalfOgZqwmQIEUG1UpVk08nTapx0iY17vOELD_9wIQTUdRwUsR" /> < input type = "submit" value = "전송요청" /> </ form > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <% 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 & "" "" & _ " }" & _ "}" %> |