Skip to content

Instantly share code, notes, and snippets.

@kibotu
Last active January 29, 2024 20:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kibotu/2c34e516b91942b5e71252cac9d40880 to your computer and use it in GitHub Desktop.
Save kibotu/2c34e516b91942b5e71252cac9d40880 to your computer and use it in GitHub Desktop.
cURL pushes for firebase cloud messaging (fcm) and huawei cloud messaging (hcm)
#!/bin/sh
set -o errexit
set -o nounset
set -o xtrace
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
API_KEY=012345678910012345
FCM_TOKEN="ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHAB"
curl --location --request POST 'https://fcm.googleapis.com/fcm/send' \
--header 'Content-type: application/json' \
--header "Authorization: key=${API_KEY}" \
--data-raw '{
"to": "'${FCM_TOKEN}'",
"notification": {
"title": "Hello",
"body": "Hello, shirley!",
},
data{
"key": "value"
}
}'
#!/bin/sh
set -o errexit
set -o nounset
set -o xtrace
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# https://developer.huawei.com/consumer/en/doc/development/HMSCore-References/https-send-api-0000001050986197#EN-US_TOPIC_0000001124288117__p1324218481619
PROJECT_ID=012345678910012345
CLIENT_ID=012345678
CLIENT_SECRET=0123456789100123456789100123456789100123456789100123456789100123
HCM_TOKEN="ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHAB"
ACCESS_TOKEN=$(curl --location --request POST 'https://oauth-login.cloud.huawei.com/oauth2/v3/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode "client_id=${CLIENT_ID}" \
--data-urlencode "client_secret=${CLIENT_SECRET}" | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["access_token"]')
curl --location --request POST "https://push-api.cloud.huawei.com/v2/${PROJECT_ID}/messages:send" \
--header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header 'Content-Type: application/json' \
--data-raw '{
"validate_only": false,
"message": {
"notification": {
"title": "Hello!",
"body": "Hello, shirley!",
"click_action": {
"type": 3
}
},
"android": {
"urgency": "NORMAL",
"ttl": "10000s",
"notification": {
"title": "Hello!",
"body": "Hello, shirley!",
"click_action": {
"type": 3
}
}
},
"token": [
"'${HCM_TOKEN}'"
]
}
}'
#!/bin/sh
set -o errexit
set -o nounset
set -o xtrace
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# https://developer.huawei.com/consumer/en/doc/development/HMSCore-References/https-send-api-0000001050986197#EN-US_TOPIC_0000001124288117__p1324218481619
PROJECT_ID=012345678910012345
CLIENT_ID=012345678
CLIENT_SECRET=0123456789100123456789100123456789100123456789100123456789100123
HCM_TOKEN="ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHAB"
ACCESS_TOKEN=$(curl --location --request POST 'https://oauth-login.cloud.huawei.com/oauth2/v3/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode "client_id=${CLIENT_ID}" \
--data-urlencode "client_secret=${CLIENT_SECRET}" | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["access_token"]')
curl --location --request POST "https://push-api.cloud.huawei.com/v2/${PROJECT_ID}/messages:send" \
--header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header 'Content-Type: application/json' \
--data-raw '{
"validate_only": false,
"message": {
"data" : "{ \"bla\" : \"keks\" }",
"android": {
"urgency": "NORMAL",
"ttl": "10000s",
"data" : "{ \"hallo\" : \"world\" }"
},
"token": [
"'${HCM_TOKEN}'"
]
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment