FCMを使ってAndroid端末へ通知を送るスクリプト

Firebase Cloud Messaging(FCM)を使ってAndroid端末へ通知を送るスクリプトを作りました(iOSは非対応です)
スクリプト内で送られているデータはcurlを使う場合を参照してください

作成したスクリプト

ソースコードhttps://github.com/sckm/fcm-send にあがっています

インストー

あらかじめgoがインストールされている必要があります

$ go get github.com/sckm/fcm-send

使い方

以下のように、はじめにjsonのdataキーで送りたい内容をファイルに書いておきます

{
    "message": "Hello World!",
    "title": "example title"
}

その後、以下のコマンドを実行することで通知が送られます

$ token='registration token'
$ server_key='your server key'
$ fcm-send -t $token -s $server_key -p data.json

curlを使う場合

作成したスクリプトは以下のcurlコマンドと同等のリクエストを送っています

token='registration token'
server_key='your server key'
msg='{"message":"Hello World!", "title": "example title"}'

curl \
    --header "Authorization: key=${server_key}" \
    --header Content-Type:"application/json" \
    https://fcm.googleapis.com/fcm/send \
    -d "{ 
        \"to\" : \"${token}\", 
        \"data\": $msg
    }"