How to send a Firebase Cloud Messaging Notification with special characters like ä, ö, ü?

☆樱花仙子☆ 提交于 2020-01-23 11:13:12

问题


I tried for a while to send a FCM Notification with special characters like this:

curl --header "Authorization: key=Auth-CODE" 
--header Content-Type:"application/json 
for JSON; application/x-www-form-urlencoded;charset=UTF-8" 
-d '{"to":"token","notification":{"title":"München",
"body":"Test Content with äöü",
"icon":"images/icon-192x192.png"}}' 
https://fcm.googleapis.com/fcm/send 

The notification I'll get looks like this:

Mnchen
Test Content with

Can anybody please guide me to the right direction? Thanks a lot!

EDIT

The client is a browser, because the app is a web-App.


回答1:


With application/json;charset=UTF-8 should work. Had the same issue, that adding charset=UTF-8 to the Content-Type solved it.




回答2:


According to @LangHoang I tried to use Base64 encode and decode to get a special character support!

<?php 
base64_encode ($string);

and decode the response in javascript (firebase-messaging-sw.js)

body:b64DecodeUnicode(payload.notification.body)

And now everything works very well!



来源:https://stackoverflow.com/questions/41115769/how-to-send-a-firebase-cloud-messaging-notification-with-special-characters-like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!