Do thấy lâu rồi k ai share code này, nay mình code lại code này cho a e xài , treo nick Yahoo có status, không mất nội dung khi ngta gửi đến lúc treo.
Status có thể tùy chọn 3 trạng thái, ONline, Idle, Busy
Status có thể tùy chọn 3 trạng thái, ONline, Idle, Busy
Code:
<?php
#----------------------------------------------------->
# ToolName : Treo nick Yh
# Programmer : lythongac
# Version : 1.0
# Mysite : http://lythongac.com
# Home : http://xgrvn.net
# Date : 10/09/2012
#--------------------------
$username = ""; // Your usernameid
$password = ""; // Your password
$consumer_key = "dj0yJmk9bUNKZlNoMXFVYUZQJmQ9WVdrOVJWSlNRa0kyTlRJbWNHbzlNVGMwTnpNNE1qYzJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD03NQ--"; //có thể thay thế nếu muốn
$secret_key = "af4af35d2005e483e293f7afddfb2986d30f4c95"; // có thể thay thế nếu muốn
$state = 2; //0 : online //2 : busy //999 idle
$status = ""; //Status
$header[] = 'Content-type: application/json; charset=utf-8';
function curl($url, $method = 'get', $header = null, $postdata = null, $includeheader=false, $timeout = 60)
{
$s = curl_init();
$debug = false;
curl_setopt($s,CURLOPT_URL, $url);
if ($header)
curl_setopt($s,CURLOPT_HTTPHEADER, $header);
if ($debug)
curl_setopt($s,CURLOPT_VERBOSE, TRUE);
curl_setopt($s,CURLOPT_TIMEOUT, $timeout);
curl_setopt($s,CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($s,CURLOPT_MAXREDIRS, 3);
curl_setopt($s,CURLOPT_RETURNTRANSFER, true);
curl_setopt($s,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($s,CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($s,CURLOPT_COOKIEFILE, 'cookie.txt');
if(strtolower($method) == 'post')
{
curl_setopt($s,CURLOPT_POST, true);
curl_setopt($s,CURLOPT_POSTFIELDS, $postdata);
}
else if(strtolower($method) == 'delete')
{
curl_setopt($s,CURLOPT_CUSTOMREQUEST, 'DELETE');
}
else if(strtolower($method) == 'put')
{
curl_setopt($s,CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($s,CURLOPT_POSTFIELDS, $postdata);
}
curl_setopt($s,CURLOPT_HEADER, $includeheader);
curl_setopt($s,CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1');
curl_setopt($s, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec($s);
$status = curl_getinfo($s, CURLINFO_HTTP_CODE);
curl_close($s);
return $html;
}
$url1 = 'https://login.yahoo.com/WSLogin/V1/get_auth_token';
$url1 .= '?login='.$username;
$url1 .= '&passwd='.$password;
$url1 .= '&oauth_consumer_key='.$consumer_key;
$rs = curl($url1);
$rs = trim(str_replace('RequestToken=', '', $rs));
$url = 'https://api.login.yahoo.com/oauth/v2/get_token';
$url .= '?oauth_consumer_key='.$consumer_key;
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='.$secret_key.'%26';
$url .= '&oauth_signature_method=PLAINTEXT';
$url .= '&oauth_timestamp='. time();
$url .= '&oauth_token='. $rs;
$url .= '&oauth_version=1.0';
$rs1 = curl($url);
echo "<textarea>".$rs1."</textarea><br>";
echo $username.":".$password."<br>";
if (stripos($rs1, 'oauth_token') === false)
{
$rs1;
return false;
}
//parse access token
$tmp = explode('&', $rs1);
foreach ($tmp as $row)
{
$col = explode('=', $row);
$access_token[$col[0]] = $col[1];
}
//print_r ($access_token);
//fetch_crumb url
$url2 = 'http://developer.messenger.yahooapis.com/v1/session';
$url2 .= '?oauth_consumer_key='.$consumer_key;
$url2 .= '&oauth_nonce='. uniqid(rand());
$url2 .= '&oauth_signature='.$secret_key.'%26'. $access_token['oauth_token_secret'];
$url2 .= '&oauth_signature_method=PLAINTEXT';
$url2 .= '&oauth_timestamp='. time();
$url2 .= '&oauth_token='. $access_token['oauth_token'];
$url2 .= '&oauth_version=1.0';
$rs2 = curl($url2, 'get', $header);
echo "<textarea>".$rs2."</textarea><br>";
//signon url
$url3 = 'http://developer.messenger.yahooapis.com/v1/session';
$url3 .= '?oauth_consumer_key='.$consumer_key;
$url3 .= '&oauth_nonce='. uniqid(rand());
$url3 .= '&oauth_signature='.$secret_key.'%26'. $access_token['oauth_token_secret'];
$url3 .= '&oauth_signature_method=PLAINTEXT';
$url3 .= '&oauth_timestamp='. time();
$url3 .= '&oauth_token='. $access_token['oauth_token'];
$url3 .= '&oauth_version=1.0';
$url3 .= '¬ifyServerToken=1';
$postdata = '{"presenceState" : '. $state. ', "presenceMessage" : "'. $status. '"}';
$rs3 = curl($url3, 'post', $header, $postdata, true);
echo "<textarea>".$rs3."</textarea><br>";
?>