0

我正在使用这个 repo 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);



?>
4

0 回答 0