CODE NÀY MÌNH VỌC ĐÂU ĐÓ TRÊN BLOG CHẲNG NHỚ NHƯNG MÀ SÀI THẤY CŨNG ĐƯỢC . CRON 10-15P ĐỂ TRÁNH BLOCK .
Tạo file log.txt cho nó lưu log vào
Tạo file log.txt cho nó lưu log vào
PHP:
<?php
set_time_limit(0);
error_reporting(0);
define('HASHTAG_NAMESPACE', '#tristanadata_');/* đừng quan tâm*/
$arraytoken = array('Thay Token Của Bạn', 'Token 2', 'Token 3', 'Token 4', 'Token 5', 'Token 6'); /*Bỏ Token vào từng ô nhe */
$random_token = array_rand($arraytoken);
$token = $arraytoken[$random_token];
$camsuc = 'LOVE'; /* icon cần thả nếu bạn muốn cảm súc là haha thì sửa lại lại : vd> $camsuc = 'LIKE'; thành $camsuc = 'HAHA' ( các cảm xúc cần chọn 'LIKE','WOW','LOVE','ANGRY','HAHA','SAD','PRIDE'*/
$limit = '5'; /* sô bài cần like & CMT*/
$post = json_decode(request('https://graph.facebook.com/me/home?fields=id,message,created_time,from&limit=' . $limit . '&access_token=' . $token), true); /* Get Data Post*/
$timelocpost = date('Y-m-d');
$logpost = file_get_contents("log.txt");
for ($i = 0; $i < 100; $i++) {
$idpost = $post['data'][$i]['id'];
if ($idpost != '364997627165697' ) { /* Đề Phòng Boss */
$messagepost = $post['data'][$i]['message'];
$time = $post['data'][$i]['created_time'];
$getinfo_user = json_decode(request('https://graph.facebook.com/' . $idpost . '?access_token=' . $token), true);
$name = $getinfo_user["from"]["name"];
/* Check time Post */
if (strpos($time, $timelocpost) !== false) {
/* Check hashtag */
if (strpos(strtolower($messagepost), HASHTAG_NAMESPACE) === FALSE) {
/* Check trùng */
if (strpos($logpost, $idpost) === FALSE) {
/* Send Comment */
$arraycmt = array('Chào, ' . $post['data'][$i]['from']['name'] . '!' . "\n\n" . ' Đã xem và like', 'hello ' . $post['data'][$i]['from']['name'] . '!' . "\n\n" . 'Chúc một ngày tốt lành', 'Ý ' . $name . ' Ra Bài Viết mới Rồi !' . "\n\n" . '.TYM Thôi', 'ý Ông ' . $name . ' Lại Ra Bài Viết mới ^_^');
$random_cmt = array_rand($arraycmt);
$comment = $arraycmt[$random_cmt];
request('https://graph.fb.me/' . urlencode($idpost) . '/comments?method=post&message=' . urlencode($comment) . '&access_token=' . $token);
$luulog = fopen("log.txt", "a");
fwrite($luulog, $idpost . "\n");
fclose($luulog);
} else {
echo 'CMT Thành Công';
}
}
}
}
}
//đây là like bài viết
for ($i = 0; $i < 100; $i++) {
$idpost = $post['data'][$i]['id'];
$time = $post['data'][$i]['created_time'];
/* Check time Post */
if (strpos($time, $timelocpost) !== false) {
/* Check hashtag */
/* Check trùng */
if (strpos($logpost, $idpost) === FALSE) {
/* Send Comment */
request('https://graph.facebook.com/' . urlencode($idpost) . '/reactions?type=' . $camsuc . '&method=post&access_token=' . $token);
$luulog = fopen("log.txt", "a");
fwrite($luulog, $idpost . "\n");
fclose($luulog);
} else {
echo 'like thành công';
}
}
}
exec("php test.php"); /* Chạy lại file */
function request($url)
{
if (!filter_var($url, FILTER_VALIDATE_URL)) {
return FALSE;
}
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_ENCODING => '',
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36',
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_CONNECTTIMEOUT => 15,
CURLOPT_TIMEOUT => 15,
CURLOPT_MAXREDIRS => 5,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => 0
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
unset($options);
return $http_code === 200 ? $response : FALSE;
}
?>