Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/venomous0x/WhatsAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
cdesjardins committed Sep 12, 2012
2 parents 7c53e95 + ecc1847 commit aa19fee
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 22 deletions.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion php/protocol.class.php → src/php/protocol.class.php
Expand Up @@ -243,7 +243,7 @@ protected function readList($token)
protected function readListSize($token)
{
$size = 0;
if ($token = 0xf8)
if ($token == 0xf8)
{
$size = $this->readInt8();
}
Expand Down
File renamed without changes.
File renamed without changes.
28 changes: 26 additions & 2 deletions php/whatsprot.class.php → src/php/whatsprot.class.php
Expand Up @@ -20,6 +20,7 @@ class WhatsProt
protected $_disconnectedStatus = "disconnected";
protected $_connectedStatus = "connected";
protected $_loginStatus;
protected $_accountinfo;

protected $_messageQueue = array();

Expand Down Expand Up @@ -57,9 +58,15 @@ protected function addAuth()
return $node;
}

protected function encryptPassword()
public function encryptPassword()
{
return md5(strrev($this->_imei));
if(stripos($this->_imei, ":") !== false){
$this->_imei = strtoupper($this->_imei);
return md5($this->_imei.$this->_imei);
}
else {
return md5(strrev($this->_imei));
}
}

protected function authenticate($nonce)
Expand Down Expand Up @@ -188,12 +195,14 @@ protected function processInboundData($data)
else if (strcmp($node->_tag, "success") == 0)
{
$this->_loginStatus = $this->_connectedStatus;
$this->_accountinfo = array('status'=>$node->getAttribute('status'),'kind'=>$node->getAttribute('kind'),'creation'=>$node->getAttribute('creation'),'expiration'=>$node->getAttribute('expiration'));
}
if (strcmp($node->_tag, "message") == 0)
{
array_push($this->_messageQueue, $node);
$this->sendMessageReceived($node);
}
print_r($node);
$node = $this->_reader->nextTree();
}
}
Expand All @@ -203,6 +212,15 @@ protected function processInboundData($data)
}
}

public function accountInfo(){
if(is_array($this->_accountinfo)){
print_r($this->_accountinfo);
}
else{
echo "No information available";
}
}

public function Connect(){
$Socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
socket_connect( $Socket, $this->_whatsAppHost, $this->_port );
Expand Down Expand Up @@ -267,6 +285,12 @@ protected function DebugPrint($debugMsg)
print($debugMsg);
}
}
/**
* TODO
*/
public function RequestLastSeen($var){
return null;
}
}

?>
File renamed without changes.
2 changes: 1 addition & 1 deletion py/whatsapi.py → src/py/whatsapi.py
Expand Up @@ -149,7 +149,7 @@ def sendMedia(i, to, path, size, link, b64thumb):
def login():
global s
#Login
Logindata = "WA\x01\x00\x00\x19\xf8\x05\x01\xa0\x8a\x84\xfc\x11iPhone-2.6.9-5222\x00\x08\xf8\x02\x96\xf8\x01\xf8\x01\x7e\x00\x07\xf8\x05\x0f\x5a\x2a\xbd\xa7"
Logindata = "WA\x01\x01\x00\x19\xf8\x05\x01\xa0\x8a\x84\xfc\x11iPhone-2.6.9-5222\x00\x08\xf8\x02\x96\xf8\x01\xf8\x01\x7e\x00\x07\xf8\x05\x0f\x5a\x2a\xbd\xa7"
s.send(Logindata)
data = s.recv(1024)
nonce = getnonce(data)
Expand Down
47 changes: 29 additions & 18 deletions whatsapp → tests/whatsapp.php 100755 → 100644
@@ -1,6 +1,6 @@
#!/usr/bin/php
<?php
require "php/whatsapp.class.php";
require "../src/php/whatsprot.class.php";

function fgets_u($pStdn) {
$pArr = array($pStdn);
Expand All @@ -13,11 +13,13 @@ function fgets_u($pStdn) {
}
}

$nickname = "Your Name";
$sender = "346xxxxxxxx";
$imei = "35xxxxxxxxxxxxx";
$nickname = "WhatsAPI Test";
$sender = ""; // Mobile number with country code (but without + or 00)
$imei = ""; // MAC Address for iOS IMEI for other platform (Android/etc)

$password = md5(strrev($imei));

$countrycode = substr($sender, 0, 2);
$phonenumber=substr($sender, 2);

if ($argc < 2) {
echo "USAGE: ".$_SERVER['argv'][0]." [-l] [-s <phone> <message>] [-i <phone>]\n";
Expand All @@ -29,21 +31,33 @@ function fgets_u($pStdn) {
}

$dst=$_SERVER['argv'][2];
$msg="";
$msg = "";
for ($i=3; $i<$argc; $i++) {
$msg.=$_SERVER['argv'][$i]." ";
$msg .= $_SERVER['argv'][$i]." ";
}

echo "[] Logging in as '$nickname' ($sender)\n";
$wa = new WhatsApp("$sender", "$password", "$nickname");
$wa = new WhatsProt($sender, $imei, $nickname, true);

$url = "https://r.whatsapp.net/v1/exist.php?cc=".$countrycode."&in=".$phonenumber."&udid=".$wa->encryptPassword();
$content = file_get_contents($url);
if(stristr($content,'status="ok"') === false){
echo "Wrong Password\n";
exit(0);
}

$wa->Connect();
$wa->Login();

if ($_SERVER['argv'][1] == "-i") {
echo "\n[] Interactive conversation with $dst:\n";
stream_set_timeout(STDIN,1);
while(TRUE) {
$buff = $wa->read();
$wa->PollMessages();
$buff = $wa->GetMessages();
if(!empty($buff)){
print_r($buff);
}
$line = fgets_u(STDIN);
if ($line != "") {
if (strrchr($line, " ")) {
Expand All @@ -67,32 +81,29 @@ function fgets_u($pStdn) {
break;
default:
echo "[] Send message to $dst: $line\n";
$wa->Message(time()."-1","$dst","$line");
$wa->Message(time()."-1", $dst , $line);
break;
}
}
}
exit(0);
}

//echo "\n[] Account Info: ";
//$wa->accountInfo();

if ($_SERVER['argv'][1] == "-l") {
echo "\n[] Listen mode:\n";
while (TRUE) {
$buff = $wa->read();
if (strlen($buff) != 0)
echo "\n";
$wa->PollMessages();
$data = $wa->GetMessages();
if(!empty($data)) print_r($data);
sleep(1);
}
exit(0);
}

echo "\n[] Request last seen $dst: ";
$wa->RequestLastSeen("$dst");
$wa->RequestLastSeen($dst);

echo "\n[] Send message to $dst: $msg\n";
$wa->Message(time()."-1","$dst","$msg");
$wa->Message(time()."-1", $dst , $msg);
echo "\n";
?>

0 comments on commit aa19fee

Please sign in to comment.