Я использую этот репо https://github.com/mgp25/Chat-API — У меня работает инструмент регистрации, но я хочу проверить, когда пользователь последний раз был в сети.
У меня в настоящее время есть этот код, который регистрирует меня, но, кажется, не проверяет статус людей — какие-нибудь идеи, как заставить это работать?
<?php
set_time_limit(10);
require_once __DIR__.'/../src/whatsprot.class.php';
require_once __DIR__.'/../src//events/MyEvents.php';
//Change to your time zone
date_default_timezone_set('Europe/Madrid');
//######### DO NOT COMMIT THIS FILE WITH YOUR CREDENTIALS ###########
///////////////////////CONFIGURATION///////////////////////
//////////////////////////////////////////////////////////
$username = '447732XXXXXX'; // Telephone number including the country code without '+' or '00'.
$password = 'XXXXXXXXXXXX'; // Use registerTool.php or exampleRegister.php to obtain your password
$nickname = 'JB'; // This is the username (or nickname) displayed by WhatsApp clients.
$target = "4477715XXXXX"; // Destination telephone number including the country code without '+' or '00'.
$debug = false; // Set this to true, to see debug mode.
///////////////////////////////////////////////////////////
function fgets_u($pStdn)
{
$pArr = [$pStdn];
if (false === ($num_changed_streams = stream_select($pArr, $write = null, $except = null, 0))) {
echo "\$ 001 Socket Error : UNABLE TO WATCH STDIN.\n";
return false;
} elseif ($num_changed_streams > 0) {
return trim(fgets($pStdn, 1024));
}
}
//This function only needed to show how eventmanager works.
function onGetProfilePicture($from, $target, $type, $data)
{
if ($type == 'preview') {
$filename = 'preview_'.$target.'.jpg';
} else {
$filename = $target.'.jpg';
}
$filename = Constants::PICTURES_FOLDER.'/'.$filename;
file_put_contents($filename, $data);
echo '- Profile picture saved in '.Constants::PICTURES_FOLDER.'/'.$filename."\n";
}
function onPresenceAvailable($username, $from)
{
$dFrom = str_replace(['@s.whatsapp.net', '@g.us'], '', $from);
echo "<$dFrom is online>\n\n";
}
function onPresenceUnavailable($username, $from, $last)
{
$dFrom = str_replace(['@s.whatsapp.net', '@g.us'], '', $from);
echo "<$dFrom is offline> Last seen: $last seconds\n\n";
}
echo "[] Logging in as '$nickname' ($username)\n";
//Create the whatsapp object and setup a connection.
$w = new WhatsProt($username, $nickname, $debug);
$w->connect();
// Now loginWithPassword function sends Nickname and (Available) Presence
$w->loginWithPassword($password);
//Retrieve large profile picture. Output is in /src/php/pictures/ (you need to bind a function
//to the event onProfilePicture so the script knows what to do.
//$w->eventManager()->bind('onGetProfilePicture', 'onGetProfilePicture');
//$w->sendGetProfilePicture($target, true);
//$w->sendPresenceSubscription($target)
$w->sendPresenceSubscription($target);?>
Задача ещё не решена.
Других решений пока нет …