简体   繁体   English

特定whatsapp联系人的网络链接

[英]Web link to specific whatsapp contact

I'd like to place a link on a webpage which opens a whatsapp chat with a certain whatsapp contact.我想在网页上放置一个链接,该链接可打开与某个 whatsapp 联系人的 whatsapp 聊天。 In other words: I want a "contact me by whatsapp" link to go next to the page's "Contact us my facebook/twitter/google+/etc" links.换句话说:我想要一个“通过whatsapp联系我”链接到页面的“联系我们我的facebook/twitter/google+/etc”链接旁边。 Something like:就像是:

href="whatsapp:contact=015555555555@s.whatsapp.com&message="I'd like to chat with you"

********* UPDATE ADDED AT THE END ********* ********* 最后添加更新*********

I've tried many approaches and I have a winner (see Test 3), here is the result of each one:我尝试了很多方法,我有一个赢家(参见测试 3),这是每个方法的结果:

(I think the Test 3 will also work for you because if the person visiting your site doesn't have you on their contact list, it's the only option that will allow it.) (我认为测试 3 也适用于您,因为如果访问您网站的人的联系人列表中没有您,这是唯一允许这样做的选项。)

In all tests, the number had to be complete, with country and location code without any initial zeros.在所有测试中,号码必须是完整的,国家和地区代码没有任何开头的零。 Example:例子:

  • +55(011) 99999-9999 (NOT) +55(011) 99999-9999 (非)
  • +5511999999999 (YES) +5511999999999(是)

On tests 1 and 2, it only worked with a plus sign on the country code: +5511999999999在测试 1 和 2 中,它仅与国家代码上的加号一起使用:+5511999999999

Test 1:测试 1:

<a href="whatsapp://send?abid=phonenumber&text=Hello%2C%20World!">Send Message</a>

This way you must have the phonenumber on your contact list.这样,您的联系人列表中必须有电话号码 It doesn't work for me because I wanted to be able to send a message to a number which I may not have on my contact list.它对我不起作用,因为我希望能够向我的联系人列表中可能没有的号码发送消息。

If you don't have the number on your contact list, it opens the Whatsapp listing all your registered contacts, so you can choose one.如果您的联系人列表中没有该号码,它会打开 Whatsapp,列出您注册的所有联系人,您可以从中选择一个。

It's a good option for sharing stuff.这是分享东西的好选择。

Test 2:测试 2:

<a href="intent://send/phonenumber#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end">Send Message</a>

This approach only works on Android AND if you have the number on your contact list.此方法仅适用于 Android并且如果您的联系人列表中有该号码。 If you don't have it, Android opens your SMS app, so you can invite the contact to use Whatsapp.如果您没有,Android 会打开您的 SMS 应用程序,因此您可以邀请联系人使用 Whatsapp。

Test 3 (The Winner) :测试 3 (获胜者)

<a href="https://api.whatsapp.com/send?phone=15551234567">Send Message</a>

This was the only way that worked fully for me.这是唯一对我有效的方法。

  • It works on Android, iOS and Web app on the desktop,它适用于桌面上的 Android、iOS 和 Web 应用程序,
  • You can start a conversation with a number that you don't have on your contact list您可以使用您的联系人列表中没有号码开始对话
  • You can create a link with one pre-built message adding &text=[message-url-encoded] like:您可以创建一个带有一条预建消息的链接,添加&text=[message-url-encoded] ,例如:

https://api.whatsapp.com/send?phone=15551234567&text=Send20%a20%quote

And if you wish to have a bookmarklet for additional ease of use, you may use this one:如果您希望有一个书签以增加易用性,您可以使用这个:

javascript: (function() { var val= prompt("Enter phone number",""); if (val) location="https://api.whatsapp.com/send?phone="+escape('972' + val)+""; })()

Youll need to change the country code(or remove it) to you.r target country and paste it in the address field in a chrome/firefox link您需要将国家/地区代码(或将其删除)更改为 you.r 目标国家/地区并将其粘贴到 chrome/firefox 链接的地址字段中

Worth notice:值得注意的是:

***************** UPDATE (START) ***************** *****************更新(开始) *****************

Whatsapp made available other option, now you can create one link to a conversation like this: Whatsapp 提供了其他选项,现在您可以创建一个指向对话的链接,如下所示:

https://wa.me/[phonenumber] https://wa.me/[电话号码]

The phone number should be in international format:电话号码应为国际格式:

Like this:像这样:

https://wa.me/552196312XXXX

NOT like this:不喜欢这样:

https://wa.me/+55(021)96312-XXXX

And if you want to add one pre-built message to your link, you can add ?text= at the end with the text URL Encoded:如果你想在你的链接中添加一条预先构建的消息,你可以在末尾添加?text=和文本 URL 编码:

https://wa.me/552196312XXXX?text=[message-url-encoded]

Exemple:例子:

https://wa.me/552196312XXXX?text=Send20%a20%quote

More info here:更多信息在这里:

https://faq.whatsapp.com/general/chats/how-to-use-click-to-chat https://faq.whatsapp.com/general/chats/how-to-use-click-to-chat

***************** UPDATE (END) ***************** *****************更新(完) *****************

The following link seems to work fine -以下链接似乎工作正常 -

<a href="whatsapp://send?text=Hello World!&phone=+9198********1">Ping me on WhatsApp</a>

It opens the contact in WhatsApp app, along with the message 'Hello World!'它会在 WhatsApp 应用程序中打开联系人,并显示“Hello World!”消息。 prepopulated in the input text box.预填充在输入文本框中。

(Tested this with google chrome on an android phone.) (在安卓手机上用谷歌浏览器测试过这个。)

I've tried this:我试过这个:

<a href="whatsapp://send?abid=phonenumber&text=Hello%2C%20World!">whatsapp</a>

changing 'phonenumber' into a specific phonenumber.将“电话号码”更改为特定的电话号码。 This doesn't work completely, but when they click on the link it does open whatsapp and if they click on a contact the message is filled in.这并不完全有效,但是当他们单击链接时,它会打开 whatsapp,如果他们单击联系人,则会填充消息。

If you want to open a specific person in chat you can, but without text filled in.如果你想在聊天中打开一个特定的人,你可以,但没有填写文本。

<a href="intent://send/phonenumber#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end">test</a>

You'll probably have to make a choice between the two.您可能不得不在两者之间做出选择。

some links to help you Sharing link on WhatsApp from mobile website (not application) for Android https://www.whatsapp.com/faq/nl/android/28000012一些链接可以帮助您从 Android 的移动网站(不是应用程序)在 WhatsApp 上分享链接https://www.whatsapp.com/faq/nl/android/28000012

Hope this helps希望这可以帮助

(I tested this with google chrome on an android phone) (我在安卓手机上用谷歌浏览器测试了这个)

You can use the following URL as per the WhatsApp FAQ:您可以根据 WhatsApp 常见问题使用以下 URL:

https://wa.me/PHONENUMBERHERE

Add the country code in front of the number and don't add any plus (+) sign or any dashes (-) or any other characters in the number.在号码前添加国家/地区代码,不要在号码中添加任何加号 (+) 或任何破折号 (-) 或任何其他字符。 Only integrers/numeric values.只有积分器/数值。

You can also predefine a text message to start with:您还可以预定义一条短信开头:

https://wa.me/PHONENUMBERHERE/?text=urlencodedtext

You can now use a very simple API https://wa.me/ to perform this task where you can provide a valid whatsapp contact number like 15555555555 ( add country code , remove all '+', '-', brackets, spaces or leading zeros ).您现在可以使用一个非常简单的 API https://wa.me/来执行此任务,您可以在其中提供有效的 whatsapp 联系电话,例如 15555555555(添加国家/地区代码删除所有“+”、“-”、括号、空格或前导零)。 You can also provide a urlencoded text as a predefined msg which user can send directly or change before sending.您还可以提供 urlencoded 文本作为预定义的 msg,用户可以直接发送或在发送前更改。

Chat with me link : <a href="https://wa.me/15555555555">Contact me by whatsapp</a>与我聊天链接<a href="https://wa.me/15555555555">Contact me by whatsapp</a>

Chat with me link with predefined text : <a href="https://wa.me/15555555555?text=I%27d%20like%20to%20chat%20with%20you">Contact me on whatsapp</a>用预定义文本与我聊天链接<a href="https://wa.me/15555555555?text=I%27d%20like%20to%20chat%20with%20you">Contact me on whatsapp</a>

Beauty of this wa.me url is you don't need to check user agent as it works on both mobile and desktop (opens web.whatsapp.com)这个wa.me url 的wa.me在于你不需要检查用户代理,因为它适用于移动和桌面(打开 web.whatsapp.com)


Source : https://faq.whatsapp.com/en/general/26000030来源: https : //faq.whatsapp.com/en/general/26000030

More details in my answer on a similar question https://stackoverflow.com/a/51854282/2485420我对类似问题的回答中的更多详细信息https://stackoverflow.com/a/51854282/2485420

For what its worth, as of this writing (Nov. 29, 2018), the updated API that seems to work on my end is using this link:就其价值而言,在撰写本文时(2018 年 11 月 29 日),似乎对我有用的更新后的 API 正在使用以下链接:

https://wa.me/<phone number here>

Note:笔记:

Just replace the placeholder <phone number here> with the intended phone number that you want to use INCLUDING the country code, this means I had to add +60 then the rest of the remaining number.只需将占位符<phone number here>替换为您要使用的预期电话号码,包括国家/地区代码,这意味着我必须添加+60然后添加其余号码。

It doesn't work on my end without one (using Android and iOS at least).如果没有(至少使用 Android 和 iOS),它就无法在我的一端工作。 It doesn't work means an error message that says along the lines of "you don't have this number".它不起作用意味着一条错误消息说“你没有这个号码”。

Reference:参考:

https://faq.whatsapp.com/en/general/26000030 https://faq.whatsapp.com/en/general/26000030

This approach only works on Android AND if you have the number on your contact list.此方法仅适用于 Android 并且如果您的联系人列表中有该号码 If you don't have it, Android opens your SMS app, so you can invite the contact to use Whatsapp.如果您没有,Android 会打开您的 SMS 应用程序,因此您可以邀请联系人使用 Whatsapp。

<a href="https://api.whatsapp.com/send?phone=2567xxxxxxxxx" method="get" target="_blank"><i class="fa fa-whatsapp"></i></a>

Google Chrome am targeting a blank window谷歌浏览器的目标是一个空白窗口

From the Official Whatsapp FAQ: https://faq.whatsapp.com/en/android/26000030/来自官方 Whatsapp 常见问题解答: https ://faq.whatsapp.com/en/android/26000030/

WhatsApp's Click to Chat feature allows you to begin a chat with someone without having their phone number saved in your phone's address book. WhatsApp 的“点击聊天”功能允许您开始与某人聊天,而无需将他们的电话号码保存在您手机的通讯录中。 As long as you know this person's phone number, you can create a link that will allow you to start a chat with them.只要您知道此人的电话号码,您就可以创建一个链接,让您可以与他们开始聊天。 By clicking the link, a chat with the person automatically opens.通过单击该链接,会自动打开与此人的聊天。 Click to Chat works on both your phone and WhatsApp Web.单击聊天适用于您的手机和 WhatsApp 网页版。

To create your own link, use https://wa.me/ where the is a full phone number in international format.要创建您自己的链接,请使用https://wa.me/ ,其中 是国际格式的完整电话号码。 Omit any zeroes, brackets or dashes when adding the phone number in international format.添加国际格式的电话号码时,请省略任何零、括号或破折号。 For a detailed explanation on international numbers, read this article.有关国际号码的详细说明,请阅读本文。 Please keep in mind that this phone number must have an active account on WhatsApp.请记住,此电话号码必须在 WhatsApp 上拥有有效帐户。

Use: https://wa.me/15551234567

Don't use: https://wa.me/+001-(555)1234567

This answer is useful to them who want click to chat whatsapp in website to redirect web.whatsapp.com with default content or message and in mobile device to open in whatsapp in mobile app with default content to text bar in app.这个答案对于想要点击网站中的 whatsapp 聊天以使用默认内容或消息重定向 web.whatsapp.com 以及在移动设备中以在移动应用程序中的 whatsapp 中打开并使用默认内容到应用程序中的文本栏的人很有用。

also add jquery link.还添加 jquery 链接。

<a  target="_blank" title="Contact Us On WhatsApp" href="https://web.whatsapp.com/send?phone=+919581880892&amp;text=Hi, I would like to get more information.." class="whatsapplink hidemobile" style="background-color:#2DC100">
    <i class="fa fa-fw fa-whatsapp" style="color:#fff"></i>
    <span style="color:#fff">
        Contact Us On WhatsApp        </span>
</a>
<a  target="_blank" title="Contact Us On WhatsApp" href="https://api.whatsapp.com/send?phone=+919581880892&text=Hi,%20I%20would%20like%20to%20get%20more%20information.." class="whatsapplink hideweb" style="background-color:#2DC100">
    <i class="fa fa-fw fa-whatsapp" style="color:#fff"></i>
    <span style="color:#fff">
        Contact Us On WhatsApp        </span>
</a>

   <script type="text/javascript"> 
var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
if (mobile) { 

    $('.hidemobile').css('display', 'none'); // OR you can use $('.hidemobile').hide();
} 
else 
{ 
    $('.hideweb').css('display', 'none'); // OR you can use $('.hideweb').hide();
}
</script>

The solution that worked for me is here in PHP :对我有用的解决方案在PHP

$android = stripos($_SERVER['HTTP_USER_AGENT'], "android");
$iphone = stripos($_SERVER['HTTP_USER_AGENT'], "iphone");
$ipad = stripos($_SERVER['HTTP_USER_AGENT'], "ipad");

$whatsappNumber = '1234597891';
$whatsappLink = '';
if($android !== false || $ipad !== false || $iphone !== false) {//For mobile
    $whatsappLink = '<a href="https://api.whatsapp.com/send?phone='.$whatsappNumber.'">'.$whatsappNumber.'</a>';
} else {//For desktop
    $whatsappLink = '<a href="https://web.whatsapp.com/send?phone='.$whatsappNumber.'">'.$whatsappNumber.'</a>';
}

I tried all combination for swiss numbers on my webpage.我在我的网页上尝试了瑞士数字的所有组合。 Below my results:在我的结果下面:

Doesn't work for Android and iOS不适用于 Android 和 iOS

https://wa.me/0790000000/?text=myText

Works for iOS but doesn't work for Android适用于 iOS 但不适用于 Android

https://wa.me/0041790000000/?text=myText
https://wa.me/+41790000000/?text=myText

Works for Android and iOS:适用于 Android 和 iOS:

https://wa.me/41790000000/?text=myText
https://wa.me/041790000000/?text=myText

Hope this information helps somebody!希望这些信息对某人有帮助!

Phone Number will be a country code followed by WhatsApp mobile number without any symbol.电话号码将是国家代码,后跟 WhatsApp 手机号码,不带任何符号。 Please refer below code.请参考以下代码。

<a href="https://api.whatsapp.com/send?phone=19998887878&text=Hi%20There!">WhatsApp Now</a>

I have been struggling also how to do that and i managed to get this helpful method我也一直在努力如何做到这一点,我设法得到了这个有用的方法

from php variable来自 php 变量

href="https://wa.me/?text=Hi%27,%20like%20to%20chat%20with%20you" href="https://wa.me/?text=Hi%27,%20like%20to%20chat%20with%20you"

<?php echo esc_attr( $phone ); ?> <?php echo esc_attr( $phone ); ?> for number in the format <?php echo esc_attr( $phone ); ?>表示格式中的数字

href="https://wa.me/263777300093?text=Hi%27,%20like%20to%20chat%20with%20you" href="https://wa.me/263777300093?text=Hi%27,%20like%20to%20chat%20with%20you"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM