如何使用 php 來回噗一些噗友...Say 早安/午安/晚安 呢?!
程式如下:
上述 php 程式請自行修改第 4, 6, 8 行...
如果懶得打上述程式,
可至 http://sites.google.com/site/dvsseed/php/response2all.php?attredirects=0&d=1 下載...
程式如下:
<?php //Plurk 的暱稱 define('NICKNAME', 'your nickname'); //Plurk 的密碼 define('PASSWORD', 'your password'); //Plurk 的系統編號, 在你的 Plurk 頁面檢視網頁原始碼, 找 "user_id": define('USER_ID', 'your user id'); //Plurk qualifier: default is 'says' define('DQUALIFIER', 'says'); //Plurk qualifier: define('QUALIFIER', 'says'); function unescape($str) { $str = rawurldecode($str); $str = str_replace("\\u", "%u", $str); preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U", $str, $r); $ar = $r[0]; foreach($ar as $k=>$v) { if(substr($v, 0, 2) == "%u") $ar[$k] = iconv("UCS-2", "BIG5", pack("H4", substr($v, -4))); elseif(substr($v, 0, 3) == "&#x") $ar[$k] = iconv("UCS-2", "BIG5", pack("H4", substr($v, 3, -1))); elseif(substr($v, 0, 2) == "&#") { $ar[$k] = iconv("UCS-2", "BIG5", pack("n", substr($v, 2, -1))); } } return join("",$ar); } //Plurk message $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($curl_handle, CURLOPT_COOKIEFILE, 'cookie.txt'); //Plurk login curl_setopt($curl_handle, CURLOPT_URL, 'http://www.plurk.com/Users/login'); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, 'nick_name='.NICKNAME.'&password='.PASSWORD); curl_exec($curl_handle); //Plurk getPlurks, to find the string="plurk_id" curl_setopt($curl_handle, CURLOPT_URL, 'http://www.plurk.com/TimeLine/getPlurks'); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, 'user_id='.USER_ID); $string = curl_exec($curl_handle); //convert ucn to unicode $string = unescape($string); $i = 0; $idx1 = 0; $idx2 = 0; $tok = explode("{", $string); foreach($tok as $value) { //remove the end of }, $value = str_replace("},", "", $value); $i++; $j = 0; $subtok = explode(",", $value); foreach($subtok as $subvalue) { $j++; if (substr($subvalue, 1, 11) == "\"plurk_id\":") { //store to array $pkid[$idx1] = substr($subvalue, 13); $idx1++; } if (substr($subvalue, 1, 10) == "\"content\":") { $responseall[$idx2] = substr($subvalue, 12); $idx2++; } } } //response to all plurk_id -- say 早安 or 午安 or 晚安 foreach($responseall as $key => $mid) { if (strpos($mid, "早安")) { $rmessage = iconv("BIG5", "UTF-8", "早安(wave)"); } elseif (strpos($mid, "午安")) { $rmessage = iconv("BIG5", "UTF-8", "午安(wave)"); } elseif (strpos($mid, "晚安")) { $rmessage = iconv("BIG5", "UTF-8", "晚安(wave)"); } //to seek the plurk_id $plurk_id = $pkid[$key]; //Plurk response curl_setopt($curl_handle, CURLOPT_URL, 'http://www.plurk.com/Responses/add'); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, 'qualifier='.DQUALIFIER.'&content='.urlencode($rmessage).'&p_uid='.USER_ID.'&plurk_id='.$plurk_id.'&lang=tr_ch&uid='.USER_ID); curl_exec($curl_handle); } curl_close($curl_handle); exit(0); ?>
上述 php 程式請自行修改第 4, 6, 8 行...
如果懶得打上述程式,
可至 http://sites.google.com/site/dvsseed/php/response2all.php?attredirects=0&d=1 下載...
留言