WhatsApp检查上次见过

时间:2016-10-11 12:15:43

标签: php whatsapp whatsapi

我正在使用此回购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);



?>

0 个答案:

没有答案