使用 Whatsapp 'Click To Chat'正如预期的那样,我可以向一个号码发送消息。
但是,我想在预填充的消息中发送一些表情符号。当我使用浏览器时它运行良好,但当我在应用程序中使用 WebView 时它不起作用(特别是带有运行同一站点的 webview 的 React Native 应用程序)。
问题 :
对于桌面浏览器或 webView,我使用相同的功能和相同的编码 (encodeURI()
),但是
当 WebView 调用 Whatsapp URL(“wa.me/...”)时,Whatsapp 上的聊天将所有表情符号显示为: �
这是我正在使用的功能:
SendWhatsapp = function(message, number) {
number = LibGeral.NormalizeMobileNumber(number);
if (empty(message)) {
message = "";
}
var urlApiWhats = "https://wa.me/" + number + "?text=" + message;
urlApiWhats = encodeURI(urlApiWhats);
var a = document.createElement("a");
a.setAttribute("data-action", "share/whatsapp/share")
a.href = urlApiWhats;
window.document.body.appendChild(a)
a.click();
window.document.body.removeChild(a);
return true;
}
SendWhatsapp("I'm a message with emoji 😂", "xxxxxxxxx")
如前所述,在应用程序的 WebView 中,它调用了 whatsapp url 并正确打开了聊天,但表情符号丢失了,只出现了一个问号。在浏览器(例如 Chrome)上,它运行良好并且出现表情符号(甚至在移动版 Chrome 上)
此外,即使我删除了 encodeURI 并“直接”传递了表情符号,它仍然无法正常工作。
我很确定几周前它还在工作......
最佳答案
这就是你应该如何编码你的 URL:
const url = `https://api.whatsapp.com/send?phone=31612345678&text=${encodeURIComponent('Cheers from Vissie ⚡️')};
// returns: "https://api.whatsapp.com/send?phone=31612345678&text=Cheers%20from%20Vissie%20%E2%9A%A1%EF%B8%8F"
您可以使用 https://wa.me/
,我只是在此示例中使用了其他 URL。有可能在浏览器中它仍然给出 �
。但在您的手机上,这应该可以工作。
关于javascript - Whatsapp 点击与表情符号聊天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64215662/