Whatsapp 点击使用表情符号聊天

问题描述 投票:0回答:3

使用 Whatsapp “点击聊天” 我能够按预期向某个号码发送消息。 但是,我想在预填充的消息中发送一些表情符号。当我使用浏览器时它运行良好,但当我在应用程序内使用 WebView 时它不起作用(特别是带有运行同一站点的 WebView 的 React Native 应用程序)。

问题
对于桌面浏览器或 webView,我使用相同的功能和相同的编码 (

encodeURI()
),但是 当 WebView 调用 Whatsapp URL(“wa.me/...”)时,Whatsapp 上的聊天将所有表情符号显示为:�

  • 是否可以在 Whatsapp Click to Chat 上使用表情符号? (我敢打赌,因为桌面浏览器可以工作)。
  • 移动设备/应用程序上会发生什么?
  • 我应该使用某种字符编码,如unicode、UTF-8(我已经测试了一些,但没有成功)?

这是我正在使用的功能:

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并“直接”传递表情符号,它仍然无法工作。 我很确定几周前它就起作用了......

javascript encoding whatsapp emoji
3个回答
2
投票

这就是您应该如何编码您的 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。有可能在浏览器中它仍然给出
。但在你的手机上这应该可以工作。


2
投票

我来晚了一点,但我遇到了同样的问题。解决办法如下:

请勿使用

var urlApiWhats = "https://wa.me/" + number + "?text=" + message;

用这个代替

var urlApiWhats = "https://api.whatsapp.com/send/?phone=" + number + "&text=" + message;

Vissie 的答案在他/她使用

api.whatsapp.com/send/
时有效。浏览器确实仍会显示
,但一旦打开 WhatsApp,您就会看到表情符号。然而,短网址
wa.me
不起作用。显然,WhatsApp 的服务器会将所有
wa.me
请求重定向到
api.whatsapp.com/send/
,并且在重定向期间表情符号会变成
。这不是你的代码的问题。


0
投票

我使用了 api.whatsapp.com 但打开 WhatsApp 后仍然显示 ����???

© www.soinside.com 2019 - 2024. All rights reserved.