Last active
July 2, 2019 06:34
-
-
Save smd877/a37bd09c7461d9efdf3dd7cfe5a0751c to your computer and use it in GitHub Desktop.
FCM使ってWebPushするPythonこーど
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: UTF-8 | |
import os | |
import json | |
import urllib.request, urllib.parse | |
SEND_URL = 'https://fcm.googleapis.com/fcm/send' | |
def lambda_handler(event, context): | |
headers = { | |
'Content-Type': 'application/json', | |
'Authorization': 'key=' + os.environ['AUTH_KEY'] | |
} | |
data = { | |
'notification': { | |
'title': 'ここにタイトル', | |
'body': 'ここに本文', | |
'icon': 'firebase-logo.png' | |
}, | |
'to': os.environ['SEND_TO'] | |
} | |
req = urllib.request.Request(SEND_URL, data=json.dumps(data).encode("utf-8"), method='POST', headers=headers) | |
urllib.request.urlopen(req) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment