Cal*_*nes 6 javascript encoding emoji whatsapp
使用 Whatsapp “点击聊天”,我可以按预期向某个号码发送消息。\n但是,我想在预填充消息中发送一些表情符号。当我使用浏览器时它运行良好,但当我在应用程序内使用 WebView 时它不起作用(特别是带有运行同一站点的 WebView 的 React Native 应用程序)。
\n问题:
\n对于桌面浏览器或 webView,我使用相同的功能和相同的编码 ( encodeURI()),但是\n当 WebView 调用 Whatsapp URL(“wa.me/...”)时,Whatsapp 上的聊天将所有表情符号显示为:\xef\xbf\xbd
这是我正在使用的函数:
\nSendWhatsapp = function(message, number) {\n number = LibGeral.NormalizeMobileNumber(number);\n if (empty(message)) {\n message = "";\n }\n\n var urlApiWhats = "https://wa.me/" + number + "?text=" + message;\n urlApiWhats = encodeURI(urlApiWhats);\n var a = document.createElement("a");\n a.setAttribute("data-action", "share/whatsapp/share")\n a.href = urlApiWhats;\n window.document.body.appendChild(a)\n a.click();\n window.document.body.removeChild(a);\n return true;\n}\n\nSendWhatsapp("I\'m a message with emoji ", "xxxxxxxxx")\nRun Code Online (Sandbox Code Playgroud)\n\n如前所述,在应用程序的 WebView 内,它调用 Whatsapp url 并正确打开聊天,但表情符号丢失,只显示一个问号。在浏览器(例如 Chrome)上,它工作得很好,并且出现了表情符号(甚至在移动版 Chrome 上)\n此外,即使我删除encodeURI并“直接”传递表情符号,它仍然无法工作。\n我\我很确定几周前它就起作用了......
\n这是您应该如何编码您的 URL:
\nconst url = `https://api.whatsapp.com/send?phone=31612345678&text=${encodeURIComponent('Cheers from Vissie \xe2\x9a\xa1\xef\xb8\x8f')};\n// returns: "https://api.whatsapp.com/send?phone=31612345678&text=Cheers%20from%20Vissie%20%E2%9A%A1%EF%B8%8F"\nRun Code Online (Sandbox Code Playgroud)\n您可以使用https://wa.me/,我只是在本示例中使用了其他 URL。有可能在浏览器中它仍然给出\xef\xbf\xbd. 但在你的手机上这应该可行。
| 归档时间: |
|
| 查看次数: |
7912 次 |
| 最近记录: |