コード例 #1
0
ファイル: WhatsAppApi.php プロジェクト: djade007/WhatsApp
 /**
  * Sends a message to a contact.
  *
  * Depending on the inputs sends a
  * message/video/image/location message to
  * a contact.
  *
  * @param $toNumbers
  * @param $message
  * @param $type
  * @return array
  */
 public function sendMessage($toNumbers, $message, $type)
 {
     $this->connectToWhatsApp();
     if (!is_array($toNumbers)) {
         $toNumbers = array($toNumbers);
     }
     $messagesId = array();
     foreach ($toNumbers as $to) {
         $id = null;
         if ($type === self::MESSAGE_TYPE_TEXT) {
             $this->wa->sendMessageComposing($to);
             $id = $this->wa->sendMessage($to, $message);
         }
         if ($type === self::MESSAGE_TYPE_IMAGE) {
             $id = $this->wa->sendMessageImage($to, $message);
         }
         if ($type === self::MESSAGE_TYPE_AUDIO) {
             $id = $this->wa->sendMessageAudio($to, $message);
         }
         if ($type === self::MESSAGE_TYPE_VIDEO) {
             $id = $this->wa->sendMessageVideo($to, $message);
         }
         if ($type === self::MESSAGE_TYPE_LOCATION) {
             $id = $this->wa->sendMessageLocation($to, $message['userlong'], $message['userlat'], $message['locationname'], null);
         }
         $messagesId[$to] = $id;
     }
     return $messagesId;
 }
コード例 #2
0
 /** IMPLEMENTS SEND MESSAGES **/
 protected function sendFiles($to, $files)
 {
     set_time_limit(600);
     $explode = explode('.', $files['image']['name']);
     $extensao = end($explode);
     $extensao = strtolower($extensao);
     define('CAMINHO_MIDIA', 'c:/xampp5-6/htdocs/whatsApi/public/img/send-messages/');
     if (in_array($extensao, array('3gp', 'mp4', 'mov', 'avi'))) {
         $newName = md5($files['image']['name'] . date('Ymdhis')) . "." . $extensao;
         $pathImage = CAMINHO_MIDIA . $newName;
         $urlMain = $_SERVER['HTTP_ORIGIN'] . '/img/send-messages/' . $newName;
         if (move_uploaded_file($files['image']['tmp_name'], $pathImage)) {
             $this->managerWhats->sendMessageVideo($to, $urlMain);
             $this->managerWhats->pollMessage();
         } else {
             $this->setLogTalk("Enviar image:" . $to, "Não foi possível enviar a mídia");
         }
     }
     if (in_array($extensao, array('jpg', 'jpeg', 'gif', 'png'))) {
         $newName = md5($files['image']['name'] . date('Ymdhis')) . "." . $extensao;
         $pathImage = CAMINHO_MIDIA . $newName;
         $urlMain = $_SERVER['HTTP_ORIGIN'] . '/img/send-messages/' . $newName;
         if (move_uploaded_file($files['image']['tmp_name'], $pathImage)) {
             $this->managerWhats->sendMessageImage($to, $urlMain);
             $this->managerWhats->pollMessage();
         } else {
             $this->setLogTalk("Enviar image:" . $to, "Não foi possível enviar a mídia");
         }
     }
     if (in_array($extensao, array('3gp', 'caf', 'wav', 'mp3', 'wma', 'ogg', 'aif', 'aac', 'm4a'))) {
         $newName = md5($_FILES['image']['name'] . date('Ymdhis')) . "." . $extensao;
         $pathImage = CAMINHO_MIDIA . $newName;
         $urlMain = $_SERVER['HTTP_ORIGIN'] . '/img/send-messages/' . $newName;
         if (move_uploaded_file($files['image']['tmp_name'], $pathImage)) {
             $this->managerWhats->sendMessageAudio($to, $urlMain);
             $this->managerWhats->pollMessage();
         } else {
             $this->setLogTalk("Enviar image:" . $to, "Não foi possível enviar a mídia");
         }
     }
     return true;
 }
コード例 #3
0
        fclose($fp);
    }
}
//Create the whatsapp object and setup a connection.
$w = new WhatsProt($username, $identity, $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);
//update your profile picture
$w->sendSetProfilePicture("demo/venom.jpg");
//send picture
$w->sendMessageImage($target, "demo/x3.jpg");
//send video
//$w->sendMessageVideo($target, 'http://techslides.com/demos/sample-videos/small.mp4');
//send Audio
//$w->sendMessageAudio($target, 'http://www.kozco.com/tech/piano2.wav');
//send Location
//$w->sendLocation($target, '4.948568', '52.352957');
// Implemented out queue messages and auto msgid
$w->sendMessage($target, "Sent from WhatsApi at " . time());
/**
 * You can create a ProcessNode class (or whatever name you want) that has a process($node) function
 * and pass it through setNewMessageBind, that way everytime the class receives a text message it will run
 * the process function to it.
 */
$pn = new ProcessNode($w, $target);
$w->setNewMessageBind($pn);
コード例 #4
0
$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);
//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');
$w->eventManager()->bind('onPresenceUnavailable', 'onPresenceUnavailable');
echo "[*] Connected to WhatsApp\n\n";
//update your profile picture
$w->sendSetProfilePicture('demo/venom.jpg');
//send picture
$w->sendMessageImage($target, 'demo/x3.jpg');
//send video
//$w->sendMessageVideo($target, 'http://techslides.com/demos/sample-videos/small.mp4');
//send Audio
//$w->sendMessageAudio($target, 'http://www.kozco.com/tech/piano2.wav');
//send Location
//$w->sendMessageLocation($target, '4.948568', '52.352957');
// Implemented out queue messages and auto msgid
$w->sendMessage($target, 'Guess the number :)');
$w->sendMessage($target, 'Sent from WhatsApi at ' . date('H:i'));
while ($w->pollMessage()) {
}
/*
 * You can create a ProcessNode class (or whatever name you want) that has a process($node) function
 * and pass it through setNewMessageBind, that way everytime the class receives a text message it will run
 * the process function to it.
コード例 #5
0
ファイル: client.php プロジェクト: MattPorto/Chat-API
     $nickname = findNicknameByPhone($contact);
     echo "[] Interactive conversation with {$nickname}:\n";
     break;
 case '/lastseen':
     echo "[] Last seen {$contact}: ";
     $w->sendMessagePaused($contact);
     $compose = true;
     $w->sendPresenceSubscription($contact);
     break;
 case '/sendimage':
     echo "\nEnter the URL or path of the image > ";
     $filepath = trim(fgets(STDIN));
     echo "\nSay something about the image > ";
     $caption = trim(fgets(STDIN));
     $target = $contact;
     $w->sendMessageImage($target, $filepath, false, $fsize, $fhash, $caption);
     $w->pollMessage();
     break;
 case '/sendvideo':
     echo "\nEnter the URL or path of the video > ";
     $filepath = trim(fgets(STDIN));
     echo "\nSay something about the video > ";
     $caption = trim(fgets(STDIN));
     $target = $contact;
     $w->sendMessageVideo($target, $filepath, false, $fsize, $fhash, $caption);
     $w->pollMessage();
     break;
     ////////////////////////// test ///////////////////
 ////////////////////////// test ///////////////////
 case '/block':
     echo "< User is now blocked >\n";
コード例 #6
0
ファイル: client.php プロジェクト: cadwmaster/chatty
                     break;
                 case '/help':
                     echo "Available commands\n";
                     echo "==================\n\n";
                     echo "/query      - Shows the number you are chatting with\n";
                     echo "/lastseen   - Last seen of the user\n";
                     echo "/block      - Blocks the user\n";
                     echo "/unblock    - Unblocks user\n";
                     echo "/time       - Current time\n";
                     echo "/back       - Return to main menu\n\n";
                     break;
                 default:
                     $w->sendMessagePaused($contact);
                     if (!filter_var($line, FILTER_VALIDATE_URL) === false) {
                         if (@getimagesize($line) !== false) {
                             $w->sendMessageImage($contact, $line);
                         }
                     } else {
                         $w->sendMessage($contact, $line);
                     }
                     $compose = true;
                     break;
             }
         }
     }
     break;
 case '/time':
     echo date("l jS \\of F Y h:i:s A") . "\n\n";
     break;
 case '/help':
     echo "Available commands\n";
コード例 #7
0
    $file_size = $_FILES['image']['size'];
    $file_tmp = $_FILES['image']['tmp_name'];
    $file_type = $_FILES['image']['type'];
    $file_ext = strtolower(end(explode('.', $_FILES['image']['name'])));
    $extensions = array("jpeg", "jpg", "png", "gif");
    if (in_array($file_ext, $extensions) === false) {
        $errors[] = "extension not allowed, please choose a JPEG or PNG file.";
    }
    if ($file_size > 2097152) {
        $errors[] = 'File size must be excately 2 MB';
    }
    if (empty($errors) == true) {
        move_uploaded_file($file_tmp, "demo/" . $file_name);
        echo "Success";
    } else {
        print_r($errors);
    }
}
// $img = $_POST['img'];
// $target = $receiver; //Target Phone,reciever phone
// $message = $message;
$filepath = "demo/" . $file_name;
// $pathToVideo = "media/Canon.mp4";
// $w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($receiver, $message);
// Send Message
$w->sendMessageImage($receiver, $filepath);
// $w->sendMessageVideo($receiver, $pathToVideo);
$w->pollMessage();
echo 'Message Sent Successfully';
header("Location: send.php?success=1");
コード例 #8
0
ファイル: sendwasa.php プロジェクト: eescallon/upload
$wa = new WhatsProt($sender, $nickname, TRUE);
$wa->connect();
$wa->loginWithPassword($password);
echo "\n[] Setting status:\n";
$wa->sendStatusUpdate($status);
$tpl = "Estimado cliente, \n ARAUJO Y SEGOVIA SA, le recuerda el pago de su obligación, la cual a la fecha presenta mora por valor de \$ %saldo%. \n\nLa mora en el pago de sus obligaciones acarrea reportes negativos en centrales de riesgos, así como el cobro de cargos adicionales.\nSi ya ha efectuado su pago, envíenos el comprobante al correo cartera@araujoysegovia.com , cualquier información adicional en el teléfono 0356501190.\n\nPara realizar su pago en linea : http://www.araujoysegovia.com/pagos\n\nNo responda este mensaje, fue generado automáticamente.";
### obtener
//$list = array(array('tel_celular'=>'3175102281','saldo_a'=>2050030),
//   array('tel_celular'=>'3013248324','saldo_a'=>2050030),
//  array('tel_celular'=>'3164539256','saldo_a'=>2050030),
//     );
foreach ($list as $row) {
    $dst = '57' . $row['tel_celular'];
    $msg = str_replace('%saldo%', number_format($row['saldo_a']), $tpl);
    echo "\n[] Send message to {$dst}: {$msg}\n";
    $wa->sendMessage($dst, $msg);
    $wa->sendMessageImage($dst, "pse.jpg");
    //$wa->sendGetRequestLastSeen($dst);
    sleep($seconds);
}
/*
echo "\n[] Request last seen $dst: ";

$wa->sendGetRequestLastSeen($dst);



echo "\n[] Send message to $dst: $msg\n";
$wa->sendMessage($dst , $msg);
echo "\n";
 * */