AppNoti

AppNoti

เซอร์วิสสำหรับส่ง Push Notification ไปยัง Mobile App เมื่อล็อกอินเสร็จต้องทำการ Request ไปยัง Firebase เพื่อเอา FCM Token มา Register ในระบบ เมื่อมีการเรียก /api/appdata หาก Stored Procedure นั้นมีการสั่งให้ส่ง Notification เว็บเซอร์วิสจะทำการส่งให้โดยอัตโนมัติ

คอนฟิก appsettings

{
  "WebServiceSettings": {
    "Firebase": {
      "ServerKey": "<SERVER_KEY>",
      "FcmPushUrl": "https://fcm.googleapis.com/fcm/send"
    }
  }
}
  • ServerKey คือ key ที่ได้การ Firebase Admin Console
  • FcmPushUrl คือ Url ที่ใช้ส่ง Notification

Send Notification with Programmatic

หาก Client App ต้องการส่ง Notification ด้วยตัวเอง สามารถทำได้ดังนี้

  1. Register FCM

Client App ต้องส่ง Access Token มากับ Header และส่งค่า fcm_token ที่ได้จาก Firebase มาด้วย โดยการ Register FCM จะทำแค่ครั้งแรกเท่านั้น

curl --location --request POST 'https://atlasx.cdg.co.th/axws-demo/api/appnoti/registerfcm' \
--header 'Authorization: Bearer <access_token>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'fcm_token=eWj75gFmOE78uEK3Tj8-DM:APA91bGtBO3NS-MEFOXnUyNAV5U99UopZRxpsnYFccsmEo8qaTiE4bB-vqqzlhZwmnD19r8tQOXHDprk63h3scwoIm8G0fA3UNEkmDB5COesGhBPLtowXv7fCuM9NA45zZeX_sP6kro1'

Client App จะได้รับ Http Status Code: 200 OK

  1. ส่ง Notification
curl --location --request POST 'https://atlasx.cdg.co.th/axws-demo/api/appnoti/send'