WAP版百度投票

0

Comments

百度贴吧的投票不支持手机,连 UCWEB 和 Opera Mini 都看不了,于是就自己写了个,不过只能查看,不能投票就是了……

其实我一直很奇怪,连我当时的音乐投票站点用的全 AJAX 那俩浏览器都能完全支持,为什么百度这个却不行呢?经过研究,我在投票的地方发现如下代码:

1
document.write('<iframe id="vote_iframe" id="vote_iframe" width="100%" frameborder="0"  height="0" scrolling="no"  src="http://toupiao.baidu.com/sys/dtview/1/299ffee9f95d723176f722e6?bu='+r_url+'&t='+Math.random()+'"></iframe>')

这段代码出现在投票信息出现的地方,很明显,这就是投票信息。所以就打开 http://toupiao.baidu.com/sys/dtview/1/299ffee9f95d723176f722e6 看到了那个投票信息,再研究代码,便写出了下面程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
header('Content-Type: text/vnd.wap.wml;charset=UTF-8');
 
$id = $_GET['id'];
$id = preg_replace('/[^0-9a-f]/i', '', $id);
 
if (! $id) exit('错误的投票 id !');
 
$file = './cache/'.$id;
 
if (file_exists($file)) {
	include $file;
 
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, 'http://toupiao.baidu.com/sys/rsview/1/'.$id.'?t='.rand());
	curl_setopt($curl, CURLOPT_HEADER, 0);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$content = curl_exec($curl);
	curl_close($curl);
 
	preg_match('/vtVoterSum:(\d+),/i', $content, $match);
	if (! $match) exit('错误!');
	$total = $match[1];
 
	preg_match_all('/{vtVoteNum:(\d+),vtVotePt:(\d+\.\d+)}/', $content, $match, PREG_SET_ORDER);
	if (! $match) exit('错误!');
	for ($i = 0; isset($match[$i]); ++$i) {
		$item[$i][1] = $match[$i][1];
		$item[$i][2] = $match[$i][2].'%';
	}
 
} else {
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, 'http://toupiao.baidu.com/sys/dtview/1/'.$id.'?t='.rand());
	curl_setopt($curl, CURLOPT_HEADER, 0);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$content = iconv('gb2312', 'utf-8', curl_exec($curl));
	curl_close($curl);
 
	preg_match_all('/vote_desc_array\[\d+\]=new Array\("(.+?)",\d+\);/i', $content, $match, PREG_SET_ORDER);
	if (! $match) exit('错误!');
	$fp = fopen($file, 'wb');
	fwrite($fp, "<?php\n");
	for ($i = 0; isset($match[$i]); ++$i) {
		$item[$i][0] = $match[$i][1];
		fprintf($fp, '$item[%d][0]=%s;', $i, var_export($item[$i][0], true));
	}
	fwrite($fp, "\n?>");
	fclose($fp);
 
	preg_match('/<span class="fB">(\d+)<\/span>/i', $content, $match);
	//if (! $match) exit('错误!');
	$total = $match[1];
 
	preg_match_all('/{optVoNum:(\d+),vtVotePt:(\d+\.\d+)}/i', $content, $match, PREG_SET_ORDER);
	if (! $match) header('Location: index.php?id='.$id);
	for ($i = 0; isset($match[$i]); ++$i) {
		$item[$i][1] = $match[$i][1];
		$item[$i][2] = $match[$i][2].'%';
	}
}
 
include './userface.php';

至于 userface.php 就自己写 wml 界面就好了~

Leave a Reply