代码之家  ›  专栏  ›  技术社区  ›  Lyric Roy ad08

移动网站“WhatsApp”按钮可向特定号码发送消息

  •  44
  • Lyric Roy ad08  · 技术社区  · 10 年前

    移动网站可以定制为允许用户在WhatsApp中向手动选择的联系人共享预先填写的消息。如给定的 here 使用自定义URL方案完成。例如:

    <a href="whatsapp://send?text=Hello%20World!">Hello, world!</a>
    

    要拨打特定号码,我们使用:

    <a href="tel:0123456789">Call</a>
    

    同样,我们是否可以向特定号码发送WhatsApp消息(或至少打开聊天室),而无需用户手动选择电话号码,而这将是预定义的参数/属性值之一?

    9 回复  |  直到 5 年前
        1
  •  59
  •   Lyric Roy ad08    5 年前

    将WhatsApp消息发送到特定号码的格式(2018年11月更新)

    <a href="https://wa.me/whatsappphonenumber/?text=urlencodedtext"></a>
    

    哪里

    WhatsApp电话号码 是国际格式的完整电话号码

    URL编码文本 是URL编码的预填充消息。


    例子:

    1. 使用预先填充的消息创建链接 自动出现在聊天的文本字段中,发送给特定号码

      邮寄 我对你出售的汽车感兴趣 +001-(555)1234567

      https://wa.me/15551234567?text=I%20am%20interested%20in%20your%20car%20for%20sale

      注:

      使用: https://wa.me/15551234567

      不要使用: https://wa.me/+001-(555)1234567

    2. 创建一个链接,其中只包含一条预先填充的消息 自动出现在聊天的文本字段中,号码将由用户选择

      邮寄 我在打听公寓的名单

      https://wa.me/?text=I%20am%20enquiring%20about%20the%20apartment%20listing

      单击链接后,用户将看到他们的联系人列表 可以将预先填写的邮件发送到。

    有关详细信息,请参阅 https://www.whatsapp.com/faq/en/general/26000030

    --

    P.S:旧格式(更新前)供参考

    <a href="https://api.whatsapp.com/send?phone=whatsappphonenumber&text=urlencodedtext"></a>
    
        2
  •  13
  •   Community CDub    4 年前

    WhatsApp现在提供了一个更简单的API https://wa.me/ 这并没有引入任何新功能,只是一种更简单的执行方式。在实现此API时无需检查用户代理,因为它还可以与本地应用程序以及桌面上的whatsapp(web.whatsapp.com)的web界面一起使用。

    这可以用于多个用例

    • A. 单击以聊天 按钮:使用 https://wa.me/whatsappphonenumber 与指定的whatsapp用户打开聊天对话框。请注意 whatsappphonenumber 应为国际格式的有效whatsapp编号,不带前导零、“+”、“-”和空格。e、 例如15551234567

      <a href="https://wa.me/15551234567">Whatsapp Me</a>

    • A. 在whatsapp上共享此内容 按钮:使用 https://wa.me/?text=urlencodedtext 打开带有预设文本的whatsapp联系人选择对话框。例如

      <a href="https://wa.me/?text=I%20found%20a%20great%20website.%20Check%20out%20this%20link%20https%3A%2F%2Fwww.example.com%2F">Share on WhatsApp</a>

    • A. 联系我 带有的按钮 预填充文本 :以上两种方法的组合,如果您希望从登录到特定页面的用户处获得预填充的自定义消息,可能会很有用。使用格式 https://wa.me/whatsappphonenumber/?text=urlencodedtext

      <a href="https://wa.me/15551234567?text=I%20am%20interested%20in%20your%20services.%20How%20to%20get%20started%3F">I am interested</a>

    官方文件访问 https://faq.whatsapp.com/en/general/26000030

        3
  •  9
  •   Tasos K. Sagar Jaybhay    9 年前

    在android上,您可以尝试

    href="intent://send/[countrycode_without_plus][number]#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end
    

    代替 [countrycode_without_plus][number] 使用该数字,

        4
  •  3
  •   Umair Mehmood    6 年前

    我用了这个代码,它对我来说很好,只要改变 +92xxxxxxxxxx 到您的有效whatsapp号码,带国家代码

    <script type="text/javascript">
            (function () {
                var options = {
                    whatsapp: "+92xxxxxxxxxx", // WhatsApp number
                    call_to_action: "Message us", // Call to action
                    position: "right", // Position may be 'right' or 'left'
    
                };
                var proto = document.location.protocol, host = "whatshelp.io", url = proto + "//static." + host;
                var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = url + '/widget-send-button/js/init.js';
                s.onload = function () { WhWidgetSendButton.init(host, proto, options); };
                var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
            })();
        </script> 
    
        5
  •  2
  •   Santiago Bernal    10 年前

    不幸的是,在whatsapp协议中并没有设置数字的选项。只能使用参数ABID(地址簿ID),但您必须使用具有特定名称的联系人才能执行此操作。 检查 WhatsApp Documentation

        7
  •  2
  •   imtaher    6 年前

    这个答案对于那些希望在网站中点击聊天whatsapp以重定向web.whatsapp.com并使用默认内容或消息,并在移动设备中使用whatsapp在移动应用程序中打开并使用默认属性在应用程序中的文本栏的人来说很有用。

    还添加jquery链接。

    <a  target="_blank" title="Contact Us On WhatsApp" href="https://web.whatsapp.com/send?phone=+91xxxxxxxxx&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=+91xxxxxxxxx&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>
    
        8
  •  1
  •   HoldOffHunger Lux    5 年前

    如其他人所述,官方文件可在以下位置获得: WhatsApp.com FAQ: Android -> Chats -> How to use click to chat 。文件说明:

    例子: https://wa.me/15551234567?text=I 我%20感兴趣%20在%20你的%20汽车%20出售%20

    但是! 为什么我们不尝试将其复制到浏览器中的新选项卡中,然后立即转到那里?

    https://wa.me/text=testtesttesttest

    结果: 找不到错误页。

    什么原因???

    使用以下方法之一轻松修复 这些 格式:

    https://api.whatsapp.com/send?text=YourShareTextHere
    https://api.whatsapp.com/send?text=YourShareTextHere&phone=123
    

    此URL中没有wa.me域!

    WhatsApp send text page.

        9
  •  0
  •   Nishal K.R    4 年前

    要从网站发送Whatsapp消息,请使用以下URL。

    网址: https://api.whatsapp.com/send?phone=XXXXX&text=dummy

    这里是 电话 文本 是参数,其中一个是必需的。

    • 电话 :我们需要向谁发送消息
    • 文本 :文本需要共享。

    也可以使用此URL。如果找不到应用程序,它将显示一个空白屏幕!

    网址:whatsapp://send?text=The要共享的文本!

    注意:只有在安装了WhatsApp桌面应用程序的情况下,以上所有功能才能在web上运行