Exemple #1
0
 /**
  * Connect to Whatsapp.
  *
  * Create a connection to the whatsapp servers
  * using the supplied password.
  *
  * @return boolean
  */
 private function connectToWhatsApp()
 {
     if (isset($this->wa)) {
         $this->wa->connect();
         $this->wa->loginWithPassword($this->password);
         return true;
     }
     return false;
 }
function sendWhatsapp($target, $message)
{
    $username = "******";
    $password = "******";
    $w = new WhatsProt($username, "דוח סגולה", "A-Report", true);
    $w->connect();
    $w->loginWithPassword($password);
    if (strlen($target) == 8) {
        $target = "9725" . $target;
    } else {
        if (strlen($target) == 10) {
            $target = "972" . substr($target, 1);
        }
    }
    $w->SendPresenceSubscription($target);
    $w->sendMessage($target, $message);
}
Exemple #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = getenv('USERNAME');
     $nickname = getenv('NICKNAME');
     $password = getenv('PASSWORD');
     $debug = false;
     // Create a instance of WhastPort.
     $w = new \WhatsProt($username, $nickname, $debug);
     $w->connect();
     // Connect to WhatsApp network
     $w->loginWithPassword($password);
     $events = new CustomEvent($w, $output);
     $events->setEventsToListenFor(['onGetMessage']);
     $w->pollMessage();
     $helper = $this->getHelper('question');
     $question = new Question('..', false);
     $destination = $helper->ask($input, $output, $question);
 }
Exemple #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = getenv('USERNAME');
     $nickname = getenv('NICKNAME');
     $password = getenv('PASSWORD');
     $debug = false;
     // Create a instance of WhastPort.
     $w = new \WhatsProt($username, $nickname, $debug);
     $w->connect();
     // Connect to WhatsApp network
     $w->loginWithPassword($password);
     $helper = $this->getHelper('question');
     $question = new Question('Digite o numero que deseja enviar sua mensagem: ', false);
     $destination = $helper->ask($input, $output, $question);
     $question = new Question('Digite sua mensagem: ', false);
     $message = $helper->ask($input, $output, $question);
     $w->sendMessage($destination, $message);
     $output->writeln('<fg=green>Send message with success!</>');
 }
Exemple #5
0
function start($s_num, $s_encuestan)
{
    require 'config/config_w.php';
    require 'strings.php';
    require 'frase.php';
    require_once 'encuestaloader.php';
    require_once 'encuesta.php';
    $encuestaloader = new Encuestaloader($s_encuestan);
    $encuesta = $encuestaloader->get_encuesta();
    $s_saludo = new Frase();
    echo "Enviar a--> {$s_num}\n";
    echo "Cantidad de preguntas: " . $encuesta->tam() . "\n\n";
    $wa = new WhatsProt($s_sender, $s_nickname, false);
    $wa->connect();
    $wa->loginWithPassword($s_password);
    echo "Presentando...\n";
    envio($wa, $s_saludo->get_stiempo(0) . $s_msg_hi, $s_num);
    $i_contfail = 0;
    do {
        $respa = getresp($wa, $s_num);
        $resp = $respa[0];
        $resp = trim($resp);
        $nombre = $respa[1];
        if (strcasecmp($resp, "Si") == 0 or strcasecmp($resp, "Sí") == 0) {
            echo "Acepto!!\n";
            envio($wa, $s_msg_start, $s_num);
            encuesta_start($wa, $s_num, $encuesta, $nombre);
        } elseif (strcasecmp($resp, "No") == 0) {
            echo "No Acepto.\nDespidiendo...\n";
            envio($wa, $nombre . ' ' . $s_msg_sory . $s_saludo->get_stiempo(1), $s_num);
            exit(0);
        } else {
            echo "Reenvio...\n";
            envio($wa, $nombre . ' ' . $s_msg_retry, $s_num);
        }
        $i_contfail++;
    } while ($i_contfail < 3);
    envio($wa, $nombre . ' ' . $s_msg_sory . $s_saludo->get_stiempo(1), $s_num);
}
}
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>\n\n";
}
echo "[] logging in as '{$nickname}' ({$username})\n";
$w = new WhatsProt($username, $nickname, $debug);
$w->eventManager()->bind('onPresenceAvailable', 'onPresenceAvailable');
$w->eventManager()->bind('onPresenceUnavailable', 'onPresenceUnavailable');
$w->connect();
// Nos conectamos a la red de WhatsApp
$w->loginWithPassword($password);
// Iniciamos sesion con nuestra contraseña
echo "[*]Conectado a WhatsApp\n\n";
$w->sendGetServerProperties();
// Obtenemos las propiedades del servidor
$w->sendClientConfig();
// Enviamos nuestra configuración al servidor
$sync = [$target];
$w->sendSync($sync);
// Sincronizamos el contacto
$w->pollMessage();
// Volvemos a poner en cola mensajes
$w->sendPresenceSubscription($target);
// Nos suscribimos a la presencia del usuario
Exemple #7
0
    echo "USAGE: " . $_SERVER['argv'][0] . " [-l] [-s <phone> <message>] [-i <phone>] [-set <status>]\n";
    echo "\tphone: full number including country code, without '+' or '00'\n";
    echo "\t-s: send message\n";
    echo "\t-l: listen for new messages\n";
    echo "\t-i: interactive conversation with <phone>\n";
    echo "\t-set: Set Status to <status>\n";
    exit(1);
}
$dst = $_SERVER['argv'][2];
$msg = "";
for ($i = 3; $i < $argc; $i++) {
    $msg .= $_SERVER['argv'][$i] . " ";
}
echo "[] Logging in as '{$nickname}' ({$sender})\n";
$wa = new WhatsProt($sender, $imei, $nickname, TRUE);
$wa->connect();
$wa->loginWithPassword($password);
if ($_SERVER['argv'][1] == "-i") {
    echo "\n[] Interactive conversation with {$dst}:\n";
    stream_set_timeout(STDIN, 1);
    while (TRUE) {
        $wa->pollMessages();
        $buff = $wa->getMessages();
        if (!empty($buff)) {
            print_r($buff);
        }
        $line = fgets_u(STDIN);
        if ($line != "") {
            if (strrchr($line, " ")) {
                // needs PHP >= 5.3.0
                $command = trim(strstr($line, ' ', TRUE));
 /** CONNECT WITH PASSWORD CONFIGURE IN BASE **/
 public function connectPassword()
 {
     $return = $this->managerWhats->connect();
     $this->managerWhats->loginWithPassword($this->users->getSenhaWhatsapp());
     return $this->managerWhats;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if (!$this->argument('number')) {
         return $this->error('No number specified.');
     }
     $number = Number::where('number', $this->argument('number'))->first();
     if (is_null($number) || is_null($number->wa_password) || is_null($number->wa_expiration)) {
         return $this->error('Whatsapp not registered. Run php artisan whatsapp:register');
     }
     $contacts = $number->contacts->map(function ($contact) {
         return $contact->number;
     });
     $wa = new WhatsProt($number->number, $number->number, true);
     $wa->connect();
     // Connects to WhatsApp
     $wa->loginWithPassword($number->wa_password);
     // Login
     $wa->pollMessage();
     $wa->sendGetPrivacyBlockedList();
     // Get our privacy list
     $wa->sendGetClientConfig();
     // Get client config
     $wa->sendGetServerProperties();
     // Get server properties
     if (!$contacts->isEmpty()) {
         $wa->sendGetHasVoipEnabled($contacts);
     }
     // Get which users have voip enabled
     $wa->sendGetGroups();
     // Get groups (participating)
     $wa->sendGetBroadcastLists();
     // Get broadcasts lists
     // $wa->sendGetProfilePicture(self); // self preview profile picture [OPTIONAL]
     if (!$contacts->isEmpty()) {
         $wa->sendSync($contacts);
     }
     // Sync all contacts
     // $wa->sendGetStatuses(All contacts); // Get contacts status [OPTIONAL]
     /*
     for (All contacts) [OPTIONAL]
     {
       			$wa->sendGetProfilePicture(contact); // preview profile picture of every contact
     }
     */
     // $wa->sendPing(); // Keep alive
     $wa->eventManager()->bind("onGetMessage", function ($mynumber, $from, $id, $type, $time, $name, $body) {
         // todo // save message id and compare to avoid duplicate
         $inbound = new Inbound();
         $inbound->from = $this->getFrom($from);
         $inbound->to = $mynumber;
         $inbound->text = $body;
         $inbound->type = 'whatsapp';
         $inbound->save();
     });
     $wa->eventManager()->bind("onPresenceAvailable", function ($mynumber, $from) {
         $from = $this->getFrom($from);
         // todo // add or update wa-contact
     });
     $wa->eventManager()->bind("onPresenceUnavailable", function ($mynumber, $from, $last) {
         $from = $this->getFrom($from);
         // todo // add or update wa-contact
     });
     $wa->eventManager()->bind("onMessageReceivedClient", function ($mynumber, $from, $id) {
         $outbound_chunk = OutboundChunk::where('message_id', $id)->first();
         if (!$outbound_chunk) {
             return;
         }
         $outbound_chunk->dn_error_code = 0;
         $outbound_chunk->dn_status = 'delivered';
         $outbound_chunk->save();
     });
     $time = time();
     while (true) {
         sleep(1);
         $wa->pollMessage();
         $this->processMessages($wa);
         if (time() - $time >= 8) {
             $wa->sendActiveStatus();
             $time = time();
             // whatsapp command action
             $whatsAppAction = Cache::get('whatsAppAction_' . $number->number, false);
             if ($whatsAppAction) {
                 $whatsAppActionInput = Cache::get('whatsAppActionInput_' . $number->number, false);
                 Cache::forget('whatsAppAction_' . $number->number);
                 Cache::forget('whatsAppActionInput_' . $number->number);
                 switch (strtolower($whatsAppAction)) {
                     case 'updatestatus':
                         $wa->sendStatusUpdate($whatsAppActionInput);
                         break;
                     case 'setprofilepicture':
                         try {
                             $wa->sendSetProfilePicture($whatsAppActionInput);
                         } catch (Exception $e) {
                         }
                         break;
                     case 'stop':
                         $wa->disconnect();
                         exit('whatsapp is stopped');
                 }
             }
             // end whatsapp command action
         }
     }
 }
Exemple #10
0
function setupWhatsappHandler()
{
    global $wa, $whatsappAuth;
    //bind event handler & login
    // Setup new Whatsapp session
    $wa = new WhatsProt($whatsappAuth['number'], "", "WhatsApp", false);
    $wa->eventManager()->bind('onGetRequestLastSeen', 'onGetRequestLastSeen');
    $wa->eventManager()->bind('onGetError', 'onGetError');
    $wa->eventManager()->bind('onDisconnect', 'onDisconnect');
    $wa->eventManager()->bind("onPresence", "onPresenceReceived");
    $wa->eventManager()->bind("onGetStatus", "onGetStatus");
    $wa->eventManager()->bind('onGetSyncResult', 'onSyncResultNumberCheck');
    $wa->eventManager()->bind("onGetProfilePicture", "onGetProfilePicture");
    $wa->eventManager()->bind("onSendPong", "onSendPong");
    $wa->connect();
    $wa->loginWithPassword($whatsappAuth['secret']);
}
Exemple #11
0
function setupWhatsappHandler()
{
    global $wa, $whatsappAuth;
    // bind event handler & tracker_login
    // Setup new Whatsapp session
    // change the "false" to "true" if you want debug information about the WhatsApp connection.
    $wa = new WhatsProt($whatsappAuth['number'], "WhatsApp", $whatsappAuth['debug']);
    $wa->eventManager()->bind('onGetRequestLastSeen', 'onGetRequestLastSeen');
    $wa->eventManager()->bind('onGetError', 'onGetError');
    $wa->eventManager()->bind('onDisconnect', 'onDisconnect');
    $wa->eventManager()->bind("onPresenceAvailable", "onPresenceAvailable");
    $wa->eventManager()->bind("onPresenceUnavailable", "onPresenceUnavailable");
    $wa->eventManager()->bind("onGetStatus", "onGetStatus");
    $wa->eventManager()->bind('onGetSyncResult', 'onSyncResultNumberCheck');
    $wa->eventManager()->bind("onGetProfilePicture", "onGetProfilePicture");
    $wa->eventManager()->bind("onPing", "onPing");
    $wa->eventManager()->bind("onSendPong", "onSendPong");
    $wa->connect();
    $wa->loginWithPassword($whatsappAuth['secret']);
}
    echo "- Profile picture saved in " . Constants::PICTURES_FOLDER . "/" . $filename . "\n";
}
function onPresenceAvailable($username, $from)
{
    $dFrom = str_replace(array("@s.whatsapp.net", "@g.us"), "", $from);
    echo "<{$dFrom} is online>\n\n";
}
function onPresenceUnavailable($username, $from, $last)
{
    $dFrom = str_replace(array("@s.whatsapp.net", "@g.us"), "", $from);
    echo "<{$dFrom} is offline>\n\n";
}
echo "[] Logging in as '{$nickname}' ({$username})\n";
//Create the whatsapp object and setup a connection.
$w = new WhatsProt($username, $nickname, $debug);
if ($w->connect() == TRUE) {
    echo "CONNECTEI";
}
var_dump($w);
if ($w->isConnected() == TRUE) {
    echo "AINDA CONECTADO";
}
// 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);
//Print when the user goes online/offline (you need to bind a function to the event onPressence
//so the script knows what to do)
$w->eventManager()->bind("onPresenceAvailable", "onPresenceAvailable");
<?php

require_once 'WhatsAPI/src/whatsprot.class.php';
require_once 'wa_config.php';
$wa_debug = false;
// Create a instance of WhastPort.
$wa_handler = new WhatsProt($wa_username, $wa_nickname, $wa_debug);
$wa_handler->connect();
// Connect to WhatsApp network
$wa_handler->loginWithPassword($wa_password);
// logging in with the password we got!
function sendMessageViaWhatsapp($to, $message, $secret)
{
    global $wa_handler;
    if ($secret == "mysecret") {
        $wa_handler->sendMessage($to, $message);
        sleep(1);
    }
}
 public function send_whatsapp_msg()
 {
     if (!empty($_FILES['image']['name'][0])) {
         $this->upload_files('image');
         exit;
     }
     if (!empty($_FILES['audio']['name'][0])) {
         $this->upload_files('audio');
     }
     if (!empty($_FILES['video']['name'][0])) {
         $this->upload_files('video');
         exit;
     }
     if ($this->input->post('doSend')) {
         require_once 'business_services/whatsapp/vendor/autoload.php';
         $username = $this->config->item('WhatsAppNumber');
         //Mobile Phone prefixed with country code so for india it will be 91xxxxxxxx
         $password = $this->config->item('WhatsAppPassword');
         $w = new WhatsProt($username, 'Mahajyothis', "Mahajyothis", true);
         //Name your application by replacing "WhatsApp Messaging"
         $w->connect();
         $w->loginWithPassword($password);
         $target = $this->input->post('reciepient');
         //Target Phone,reciever phone
         $message = $this->input->post('message');
         $location = $this->input->post('location');
         $latitude = $this->input->post('latitude');
         $longitude = $this->input->post('longitude');
         $w->SendPresenceSubscription($target);
         //Let us first send presence to user
         if ($latitude && $longitude) {
             $w->sendBroadcastLocation($target, $latitude, $longitude, $location);
             // Send Location
         }
         if ($message) {
             $w->sendMessage($target, $message);
         }
         // Send Message
         $this->send_files($w, $target);
         echo json_decode(1);
         exit;
     }
 }