waaltcom/whatools-php

此包的最新版本(dev-master)没有提供许可信息。

PHP库,用于轻松将Whatools集成到您的应用程序中。

dev-master 2015-09-22 20:03 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:16:02 UTC


README

PHP库,用于轻松将Whatools集成到您的应用程序中

注意

此库仅适用于v3 API。请确保您的Whatools行配置为使用此API版本。

API参考

配置

您所需做的只是包含这个库,然后通过将Whatools API密钥作为参数传递给类构造函数来创建一个API对象。

include("whatools.inc.php");
$w = new Whatools("Put here your API key");

请记住,您可以通过登录Whatools并转到高级设置 > REST API来获取您的Whatools行API密钥。

登录和注销

在v3 API中,登录和注销是旧版API版本中订阅和取消订阅的类似过程。尽管如此,在v3中,当您注销时,您实际上是在关闭WhatsApp服务器与您的账户之间的连接,因此您可以确保不会错过任何一条消息。

$w->login();
echo "Logged in as +", $w->whatsappInfo->cc, $w->whatsappInfo->pn, "\n";
$w->logout();

设置您的昵称

$w->nicknamePost("John Doe");

获取您的昵称

$nickname = $w->nicknameGet("John Doe");

设置您的状态消息

$w->statusPost("To be, or not to be, that is the question.");

获取您的状态消息

$status = $w->statusGet();

设置您的头像

$w->avatarPost("Route for an image file");

获取和存储某人的头像

$avatar = $w->avatarGet("Phone number in international format");
file_put_contents("avatar.jpg", $avatar);

发送消息

$w->messagePost("Phone number in international format", "Body of the message");

发送图片

$w->picturePost("Phone number in international format", "Route for an image file", "Optional caption");

检索和打印自上次注销以来接收和发送的消息

$messages = $w->messageGet();
foreach ($messages as $message)
{
  if ($msg->mine)
    echo "> ", $msg->to;
  else
    echo "< ", $msg->from;
  echo "\n\t\"", $msg->body, "\"";
  echo "\n\t@", $msg->stamp;
  echo "\n\tACK: ", $msg->ack, "\n";
}