【问题标题】:send whatsapp message using php使用php发送whatsapp消息
【发布时间】:2017-02-04 21:50:47
【问题描述】:

嗨。 我想使用 php 发送 whatsapp 消息。我运行这段代码

<?php
require_once 'Chat-API-master/src/whatsprot.class.php';
$username = "6285648145xxx";
$nickname = "ardi";
$password = "password"; // The one we got registering the number
$debug = true;

// Create a instance of WhastPort.
$w = new WhatsProt($username, $nickname, $debug);

$w->connect(); // Connect to WhatsApp network
$w->loginWithPassword($password); // logging in with the password we got!

$target = '62811304xxxx'; // The number of the person you are sending the message
$message = 'Hi! :) this is a test message';

$w->sendMessage($target , $message);
?>

但我在浏览器中得到了这段代码

tx  <stream:features></stream:features>

tx  <auth user="6285648145xxx" mechanism="WAUTH-2"></auth>

rx  <from s.whatsapp.net=""></from>

rx  <stream:features></stream:features>

rx  <challenge>376a507c7e915642d85255fe96cb1d101fa23819</challenge>

tx  <response>200e09fa50b7c6a3fa3416878f1e165e8d7670f054ddeaa1c77278a5f8e5b881f4f9f75dce809f42cbdcf17931db8c15641399488b90e9cb74e87de94560802f98bb028af9b5967403fb278c28e06c</response>


Fatal error: Maximum execution time of 30 seconds exceeded in D:\XAMPP\htdocs\waonline\Chat-API-master\src\whatsprot.class.php on line 2609

怎么了??请给我解决方案。谢谢

【问题讨论】:

  • 隐藏密码,如果正确的话
  • 您已经超出了配置允许的 PHP 脚本的默认最大运行时间。这可以修复,但我无法从代码中看到您实际显示为什么 30 秒不足以运行该脚本的时间。这就是你脚本中的所有代码吗?
  • 为什么是android 标签?
  • 好的。我会再次检查我的代码。谢谢。也许您还有其他代码可以使用 php 发送 whatsapp 消息?

标签: php android html whatsapp


【解决方案1】:

添加

set_time_limit(120);

您的脚本执行时间过长

【讨论】:

  • 除了一些托管公司会禁用此功能
  • 我把代码'set_time_limit(120);'放在哪里也许您还有其他使用 php 发送消息的代码?
【解决方案2】:

使用官方的“点击聊天”API

第一种可能的方法是通过 URL 过程将用户发送到:

https://api.whatsapp.com/send?phone=XXYYYYYYYY

(其中XX 是国家代码,YYYYYYYY 是数字)

现在 API 的格式更短,允许包含文本消息。

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

(其中whatsappphonenumber 是国际格式的完整电话号码,URL-encodedtext 是 URL 编码的预填充消息)

也可以只指定要发送的消息,但不指定用户,让用户稍后选择将其发送给谁,可以一次将其发送给许多人,使用此方法:

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

您可以在此处查看所有官方当前信息 https://faq.whatsapp.com/en/android/26000030/

【讨论】:

    【解决方案3】:

    The official documentation says to use their wa.me URL,让我们来看看:http://wa.me/?text=mytest。你看到了什么?您是否看到错误页面?这是我看到的:

    我们找不到您要查找的页面

    看起来您正在寻找一个不存在的页面。或者我们可能刚刚删除的页面。无论哪种方式,请返回或确保检查 url、您的拼写并重试。

    所以,简而言之,不要使用 wa.me URL。使用api.whatsapp.com URL,例如以下之一:

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

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

    这两个都非常适合我!

    如果您有兴趣观看跟踪这些 URL 的项目,请关注我们!:https://github.com/bradvin/social-share-urls#whatsapp

    【讨论】:

      猜你喜欢
      • 2015-04-05
      • 1970-01-01
      • 2018-06-28
      • 2019-09-19
      • 2013-10-08
      • 1970-01-01
      • 2018-09-01
      • 2021-12-10
      • 1970-01-01
      相关资源
      最近更新 更多