简体   繁体   中英

How to send Ms Azure push notifications to android device from Postman

I am trying to send Azure push notification to android devices by using Postman. To achieve this i saw post in microsoftDocs but docs saying that This API doesn't support Firebase Cloud Messaging (FCM) yet. Is there any way to send FCM push notification from postman by using MsAzure

Finally i got the solution

URL

https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/?api-version=2015-01

Parameter

  • Headers

     Authorization {{azure-authorization}} Content-Type application/json ServiceBusNotification-Format gcm 
  • Body (Body will be according to you. No need to maintain as below)

     {"data":{"gcm.notification.body":"Hi", "gcm.notification.title":"Hi"}} 
  • Pre-request Script

     function getAuthHeader(resourceUri, keyName, key) { var d = new Date(); var sinceEpoch = Math.round(d.getTime() / 1000); var expiry = (sinceEpoch + 3600); var stringToSign = encodeURIComponent(resourceUri) + '\\n' + expiry; var hash = CryptoJS.HmacSHA256(stringToSign, key); var hashInBase64 = CryptoJS.enc.Base64.stringify(hash); var sasToken = 'SharedAccessSignature sr=' + encodeURIComponent(resourceUri) + '&sig=' + encodeURIComponent(hashInBase64) + '&se=' + expiry + '&skn=' + keyName; console.log(sasToken); alert(sasToken); return sasToken; } postman.setEnvironmentVariable('azure-authorization', getAuthHeader(request.url,"DefaultFullSharedAccessSignature", "xxxxxxxxxxxxxxxxxxxxxx")); postman.setEnvironmentVariable('current-date',new Date().toUTCString()); 

In the above code (Pre-request Script) we have to update DefaultFullSharedAccessSignature for that follow the below steps

Go to Azure portal | Access Policies | Copy the DefaultFullSharedAccessSignature and paste some where | from there copy the SharedAccessKey

Images for reference

Pic 1: 在此处输入图片说明

Pic 2: 在此处输入图片说明

Pic 3: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM