/** * 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); }
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); }
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!</>'); }
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); }
{ $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 $pn = new ProcessNode($w, $target); $w->setNewMessageBind($pn);
<?php require_once 'src_register/whatsprot.class.php'; $debug = false; echo "####################\n"; echo "# #\n"; echo "# WA RESET #\n"; echo "# #\n"; echo "####################\n"; echo "\n\nUsername (country code + number without + or 00): "; $username = trim(fgets(STDIN)); // Create a instance of WhastPort. $w = new WhatsProt($username, '', $debug); echo "\n\nYour accounts password: "******"Failed to login, make sure your account is not blocked (use blockChecker.php) or check if your password is right\n\n"; exit(0); } $w->sendRemoveAccount(); $i = 0; for ($i; $i < 5; $i++) { $w->pollMessage(); } $w->disconnect(); unlink("../src/wadata/id.{$username}.dat"); unlink("../src/wadata/nextChallenge.{$username}.dat"); echo "\n\n OK! Now use registerTool.php \n\n";
/** CONNECT WITH PASSWORD CONFIGURE IN BASE **/ public function connectPassword() { $return = $this->managerWhats->connect(); $this->managerWhats->loginWithPassword($this->users->getSenhaWhatsapp()); return $this->managerWhats; }
public function loginWithPassword($password, $profileSubscribe = false) { parent::loginWithPassword($password, $profileSubscribe); }
/** * 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 } } }
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']); }
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 $group->whatsapp_mobile."".$group->whatsapp_password; require elgg_get_plugins_path() . 'enriver/vendors/whatsapi/whatsprot.class.php'; $wa = new WhatsProt($group->whatsapp_mobile, $group->whatsapp_imei, $group->whatsapp_name, false); $wa->connect(); $wa->loginWithPassword($group->whatsapp_password); // $wa->sendSetProfilePicture($group->getIconURL()); $wa->sendMessage($_POST['testmobile'], "You have done it,Visit http://enraiser.com visit http://Kindit.org "); for ($i = 0; $i < 5; $i++) { $wa->pollMessages(); } $content = "check now"; } elseif ($step == '5') { require elgg_get_plugins_path() . 'enriver/vendors/whatsapi/whatsprot.class.php'; $wa = new WhatsProt($group->whatsapp_mobile, $group->whatsapp_imei, $group->whatsapp_name, false); $wa->connect(); $wa->loginWithPassword($group->whatsapp_password); $members = $group->getMembers(); foreach ($members as $member) { if ($member->mobile and $member->mobile != "") { $targets[] = $member->mobile; $wa->sendMessage($member->mobile, $_POST['groupmessage']); } } for ($i = 0; $i < 5; $i++) { $wa->pollMessages(); } $content = "check now"; $content = "<h2 class='elgg-heading-main'>done</h2><br><br>"; } } else { $content = "<h2 class='elgg-heading-main'>No permission</h2><br><br>";
<?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; } }