上個月介紹過用 Linux 系統自動發噗保卡馬。有人說他只有 Windows 可以用而已,所以這裡特地寫一篇用 Windows 實做的詳細步驟介紹供大家參考。

  1. 我們需要 PHP 。請到 AppServ 網站下載 AppServ 安裝檔並安裝。
  2. 啟用 cURL 模組。用記事本開啟 C:\Windows\php.ini ,找
    extension=php_curl.dll

    確認該行最前面沒有 ; 分號。如果有的話就把 ; 分號刪掉並存檔。

  3. 新增 plurkbot.php ,內容如下:
    <?php
    	header('Content-type:text/html; charset=utf-8');
    	define('NICKNAME', ''); //輸入 PLURK 的帳號
    	define('PASSWORD', ''); //輸入 PLURK 的密碼
    	$user_id = getid(NICKNAME);
    	define('USER_ID', "$user_id");
    	set_time_limit(240);
    
    	// login
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_COOKIEJAR, '\plurk_cookie_n.txt');
    	curl_setopt($ch, CURLOPT_URL, 'http://www.plurk.com/Users/login');
    	curl_setopt($ch, CURLOPT_POSTFIELDS, 'nick_name='.NICKNAME.'&password='.PASSWORD);
    	curl_exec($ch);
    	curl_close($ch);
    
    	//
    
    	date_default_timezone_set("Asia/Taipei");
    	$out = date("Y-m-d H:i:s");
    	echo $out;
    	post($out);
    
    	function post($message){
    		// post
    		$ch3 = curl_init();
    		curl_setopt($ch3, CURLOPT_COOKIEFILE, '\plurk_cookie_n.txt');
    		curl_setopt($ch3, CURLOPT_URL, 'http://www.plurk.com/TimeLine/addPlurk');
    		curl_setopt($ch3, CURLOPT_POSTFIELDS, 'qualifier=gives&limited_to=%5B'.USER_ID.'%5D&lang=tr_ch&uid='.USER_ID.'&no_comments=0&content='.$message);
    		curl_exec($ch3);
    		curl_close($ch3);
    	}
    
    	function getid($name){
    		$ourl= 'http://plurk.com/'.NICKNAME;
    		$fid = file_get_contents($ourl);
    		preg_match('/user_id\": (.*?)\,/s',$fid,$matches);
    		$u_id = $matches[1];
    		return($u_id);
    	}
    ?>

    別忘了設定帳號跟密碼的部份。如果你是使用 Windows 記事本存檔,請在輸入檔名畫面的「檔案類型」選擇「所有檔案」檔名才不會錯。確認一下 plurkbot.php 的位置,在這裡就以 C:\plurkbot\plurkbot.php 為例。

  4. 來測試一下剛剛寫好的檔案。執行 cmd 開啟命令提示字元,輸入指令:
    C:\AppServ\php5\php.exe C:\plurkbot\plurkbot.php

    指令執行結果
    出現像畫面中這樣的亂碼是正常的,不用擔心。接著開啟您的噗浪,檢查有沒有出現一則給自己,裡面寫著時間的私噗,有看到就是成功了。

  5. 之後再用 Windows 的工作排程,設定每四小時執行跟上一步驟相同的指令即可。
<?php
	header('Content-type:text/html; charset=utf-8');
	define('NICKNAME', ''); //輸入 PLURK 的帳號
	define('PASSWORD', ''); //輸入 PLURK 的密碼
	$user_id = getid(NICKNAME);
	define('USER_ID', "$user_id");
	set_time_limit(240);

	// login
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_COOKIEJAR, '\plurk_cookie_n.txt');
	curl_setopt($ch, CURLOPT_URL, 'http://www.plurk.com/Users/login');
	curl_setopt($ch, CURLOPT_POSTFIELDS, 'nick_name='.NICKNAME.'&password='.PASSWORD);
	curl_exec($ch);
	curl_close($ch);

	//

	date_default_timezone_set("Asia/Taipei");
	$out = date("Y-m-d H:i:s");
	echo $out;
	post($out);

	function post($message){
		// post
		$ch3 = curl_init();
		curl_setopt($ch3, CURLOPT_COOKIEFILE, '\plurk_cookie_n.txt');
		curl_setopt($ch3, CURLOPT_URL, 'http://www.plurk.com/TimeLine/addPlurk');
		curl_setopt($ch3, CURLOPT_POSTFIELDS, 'qualifier=gives&limited_to=%5B'.USER_ID.'%5D&lang=tr_ch&uid='.USER_ID.'&no_comments=0&content='.$message);
		curl_exec($ch3);
		curl_close($ch3);
	}

	function getid($name){
		$ourl= 'http://plurk.com/'.NICKNAME;
		$fid = file_get_contents($ourl);
		preg_match('/user_id\": (.*?)\,/s',$fid,$matches);
		$u_id = $matches[1];
		return($u_id);
	}
?>