Skip to content

Instantly share code, notes, and snippets.

@smd877
Last active July 2, 2019 06:34
Show Gist options
  • Save smd877/a37bd09c7461d9efdf3dd7cfe5a0751c to your computer and use it in GitHub Desktop.
Save smd877/a37bd09c7461d9efdf3dd7cfe5a0751c to your computer and use it in GitHub Desktop.
FCM使ってWebPushするPythonこーど
#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