/**
* PHP to Yahoo Messenger
* @version 1.0
* @author Halim PN <halimpn@gmail.com>
* @copyright (c) 2010 http://www.jogjashop.com
* @license http://www.gnu.org/licenses/gpl-3.0.txt
**/
class ymMobile
{
function ymLogin($ymdata)
{
//pisahkan user dan password
$ymdata = explode('l', $ymdata);
if(count($ymdata)<>2) die("Data ID YM/Password wajib diisikan");
//lakukan proses dekode
$this->id_ym = $this->dekode($ymdata[0]);
$this->password_ym = $this->dekode($ymdata[1]);
$xml = $this->phpSend('http://us.m.yahoo.com/w/bp-messenger', '', '', getcwd() . '/cookies_yahoo_messenger.cookie');
$xmlDoc = new DOMDocument();
@$xmlDoc->loadHTML($xml);
$login_URL = $xmlDoc->getElementsByTagName("form")->item(0)->getAttribute("action");
foreach ($xmlDoc->getElementsByTagName("input") as $input)
{
if($input->getAttribute("name") == "_done")
{
$_done = $input->getAttribute("value");
}
if($input->getAttribute("name") == "_ts")
{
$_ts = $input->getAttribute("value");
}
if($input->getAttribute("name") == "_crumb")
{
$_crumb = $input->getAttribute("value");
}
}
// lakukan proses login
$this->curlData = $this->phpSend($login_URL, "_authurl=auth&_done=" . $_done . "&_sig=&_src=&_ts=" . $_ts . "&_crumb=" . $_crumb . "&_pc=&_send_userhash=0&_partner_ts=&id=" . $this->id_ym . "&password=" . $this->password_ym . "&__submit=Sign+in", getcwd() . '/cookies_yahoo_messenger.cookie', getcwd() . '/cookies_yahoo_messenger.cookie');
$error = strpos($this->curlData, 'Invalid ID/Password');
if($error>0) die("ID Yahoo/Password salah");
}
function kirimPesan($ym_tujuan, $pesan)
{
if(!empty($this->curlData))
{
$msg_URL = $this->curlData;
$msg_URL = substr($this->curlData, strpos($this->curlData, "<a href=\"/w/bp-messenger/sendmessage") + 9);
$msg_URL = substr($msg_URL, 0, strpos($msg_URL, "\""));
$msg_URL = str_replace("&", "&", $msg_URL);
$msg_URL = "http://us.m.yahoo.com" . $msg_URL;
//buka alamat pengiriman pesan
$xml = $this->phpSend($msg_URL, '', getcwd() . '/cookies_yahoo_messenger.cookie', getcwd() . '/cookies_yahoo_messenger.cookie');
$xmlDoc = new DOMDocument();
@$xmlDoc->loadHTML($xml);
$sendmsg_URL = $xmlDoc->getElementsByTagName("form")->item(0)->getAttribute("action");
$sendmsg_URL = "http://us.m.yahoo.com" . $sendmsg_URL;
//kirim pesan
$this->phpSend($sendmsg_URL, "id=" . $ym_tujuan . "&message=" . $pesan . "&__submit=Send", getcwd() . '/cookies_yahoo_messenger.cookie', getcwd() . '/cookies_yahoo_messenger.cookie');
}
else die("Gagal mengakses server Yahoo!");
}
function phpSend($url, $post, $cookie, $cookie2)
{
if(function_exists(curl_init))
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if(!empty($post))
{
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6");
if(!empty($cookie))
{
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
}
if(!empty($cookie2))
{
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie2);
}
$curlData = curl_exec($curl);
curl_close($curl);
return $curlData;
}
else die("cURL not active");
}
function encrypt($pwd, $data)
{
$key[] = '';
$box[] = '';
$pwd_length = strlen($pwd);
$data_length = strlen($data);
for ($i = 0; $i < 256; $i++)
{
$key[$i] = ord($pwd[$i % $pwd_length]);
$box[$i] = $i;
}
for ($j = $i = 0; $i < 256; $i++)
{
$j = ($j + $box[$i] + $key[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $data_length; $i++)
{
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipher .= chr(ord($data[$i]) ^ $k);
}
return $cipher;
}
function decrypt($pwd, $data)
{
return $this->encrypt($pwd, $data);
}
function hex2bin($kodehexa)
{
for ($i=0;$i<strlen($kodehexa);$i+=2)
{
$biner.=chr(hexdec(substr($kodehexa,$i,2)));
}
return $biner;
}
function enkode($u)
{
$p = 'www.jogjashop.com';
$u = htmlspecialchars($u);
$a = $this->encrypt($p, $u);
$d = bin2hex($a);
return $d;
}
function dekode($u)
{
$p = 'www.jogjashop.com';
$u = $this->hex2bin($u);
$a = $this->decrypt($p, $u);
$a = html_entity_decode($a);
return $a;
}
}
|