QQ空间秒赞PHP脚本

2018年04月22日 1848点热度 0人点赞 0条评论

[title]简介[/title]

这是一个用php写的QQ动态秒赞脚本

使用的项目: wcurl、 simple_html_dom

[title]运行环境[/title]

开发环境:php 7.1 windows

貌似linux上也能用

[title]更新日志[/title]

  • 2018-04-23 修复了一些bug(下面的代码没更新)

[title]文件结构[/title]

qzz
├── lib
│   ├── htmldom.class.php
│   └── wcurl.class.php
├── tmp
│   ├── list.json
│   └── log.txt
└── run.php

[title]实例代码[/title]

<?php
/**
 * Author: kamino
 * CreateTime: 2018/4/21,上午 08:57
 * Description: QQ空间秒赞
 * Version: v1.0
 */

error_reporting( E_ALL || ~E_NOTICE );

define( "ROOT_PATH", __DIR__ );

require_once ROOT_PATH . "/lib/wcurl.class.php";
require_once ROOT_PATH . "/lib/htmldom.class.php";

$cookie = "";

$gmt = "Sat, 21 Apr 2018 02:25:28 GMT";

$qq = "";

$header = array(
	"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
	"Accept-Encoding: gzip, deflate, br",
	"Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
	"Cache-Control: no-cache",
	"Connection: keep-alive",
	"Cookie: " . $cookie,
	"Host: rc.qzone.qq.com",
	"If-Modified-Since: " . $gmt,
	"Upgrade-Insecure-Requests: 1",
	"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
);

/*
 * 获取动态页面
 */
function getHtml() {
	$url = "https://rc.qzone.qq.com/im";

	$wch = new wcurl();
	$wch->setUrl( $url )->setHeader( $GLOBALS["header"] )->set( CURLOPT_HEADER, 0 )->set( CURLOPT_ENCODING, "gzip" );
	$html = $wch->get();
	if ( strpos( $html, "QQ空间-分享生活,留住感动" ) ) {
		errReport( "登录失败" );
		sLog( "登录失败", "通知" );
		die();
	}

	return $html;
}

/*
 * simple html dom
 */
function fHtml( $html, $tag, $id = - 1 ) {
	$shd = new simple_html_dom();
	$shd->load( $html );
	if ( $id >= 0 ) {
		return $shd->find( $tag, $id );
	} else {
		return $shd->find( $tag );
	}
}

/*
 * cookie过期提醒
 */
function errReport( $desp, $text = "秒赞error" ) {
	//推荐 server酱 http://sc.ftqq.com/3.version
}

/*
 * 日志记录
 */
function sLog( $msg, $fun = null ) {
	$log = "[" . date( 'Y-m-d H:i:s' ) . "] ";
	if ( empty( $fun ) ) {
		$log .= $msg;
	} else {
		$log .= "( " . $fun . " ) ";
		$log .= $msg;
	}
	$log .= "\r\n";
	echo $log;
	$f = fopen( ROOT_PATH . "/tmp/log.txt", "a" );
	fwrite( $f, $log );
	fclose( $f );
}

/*
 * 点赞
 */
function giveZan( $key ) {
	$url    = "https://rc.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?&g_tk=1109856371";
	$fields = array(
		"qzreferrer"  => "https://rc.qzone.qq.com/im",
		"opuin"       => $GLOBALS["qq"],
		"unikey"      => $key,
		"curkey"      => $key,
		"from"        => "1",
		"appid"       => "311",
		"typeid"      => "0",
		"abstime"     => time(),
		"active"      => 0,
		"fupdate"     => 1,
		"page_source" => 1
	);
	$wch    = new wcurl();
	$wch->setUrl( $url )->setHeader( $GLOBALS["header"] )->set( CURLOPT_HEADER, 0 )->set( CURLOPT_ENCODING, "gzip" );

	$re = $wch->post( $fields );
	if ( checkResult( $re ) ) {
		sLog( "点赞成功" );
	} else {
		sLog( "点赞失败,重试3次" );
		for ( $i = 0; $i < 3; $i ++ ) {
			if ( checkResult( $wch->post( $fields ) ) ) {
				sLog( "点赞成功" );
				break;
			}
		}
	}

	return true;
}

/*
 * 检测点赞结果
 */
function checkResult( $msg ) {
	if ( strpos( $msg, "succ" ) ) {

		return true;
	}

	if ( strpos( $msg, "您还未登录,请先登录再试" ) ) {
		errReport( "cookie过期了吧" );
		sLog( "cookie过期", "通知" );
		die();
	}

	return false;
}

/*
 * 获取点赞所需参数
 */
function getValues( $content ) {
	$values         = array();
	$values["id"]   = $content->id;
	$t              = explode( "_", $values["id"] );
	$values["time"] = $t[3];
	$values["name"] = fHtml( $content, "img", 0 )->alt;
	$values["text"] = fHtml( $content, "div.f_title", 0 )->innertext;
	$b              = fHtml( $content, "i.none", 0 );
	$str            = '/data-likecurkey="(.*?)"/';
	preg_match( $str, $b, $res );
	$values["key"] = $res[1];

	return $values;
}

/*
 * 进行一次
 */
function work() {
	$html = getHtml();
	$dts  = fHtml( $html, "div.fn_feeds", 0 );
	$dt   = fHtml( $dts, "li" );
	$list = array();

	foreach ( $dt as $item ) {
		$list[] = getValues( $item );
	}

	if ( $new = checkNew( $list ) ) {
		foreach ( $new as $i ) {
			giveZan( $i["key"] );
		}
	}
}

/*
 * 判断是否为新动态
 */
function checkNew( $list_new ) {
	if ( file_exists( ROOT_PATH . "/tmp/list.json" ) ) {
		$list_old = json_decode( file_get_contents( ROOT_PATH . "/tmp/list.json" ), true );
		if ( $list_new == $list_old ) {

			return false;
		}
		$last = $list_old[0]["time"];
		$new  = array();
		foreach ( $list_new AS $s ) {
			if ( $s["time"] > $last ) {
				sLog( "from: " . $s["name"] . " text: " . $s["text"], "新动态" );
				$new[] = $s;
			}
		}
		if ( count( $new, true ) > 0 ) {
			@file_put_contents( ROOT_PATH . "/tmp/list.json", json_encode( $list_new ) );

			return $new;
		} else {
			return false;
		}
	} else {
		@file_put_contents( ROOT_PATH . "/tmp/list.json", json_encode( $list_new ) );

		return false;
	}
}

//无限运行!
while ( true ) {
	work();
	//sleep( 1 );
}

[title]代码文件[/title]

立即下载

AIKAMINO

暂无