使用PHP同时更新Twitter、饭否、嘀咕和做啥

在线演示: http://fdszlzl.web.dns12580.com/mblog.php

 

<?php
/*=============================================
Writen by http://cnblogs.com/fdszlzl
===============================================
*/
if(isset($_GET['action']) && $_GET['action']=='post'){
    
$mblog=array(
        
'twitter'=>"http://twitter.com/statuses/update.xml",
        
'fanfou'=>"http://api.fanfou.com/statuses/update.xml",
        
'digu'=>"http://api.digu.com/statuses/update.xml",
        
'zuosa'=>"http://api.zuosa.com/statuses/update.xml"
    );
    
foreach($_POST['m'as $key=>$value){
        
if($key=='digu')
            
$data="content=".urlencode($_POST['data']);
        
else
            
$data="status=".urlencode($_POST['data']);
        
$s=postMblog($mblog[$key],$_POST['username'],$_POST['password'],$data);
        
echo $key.":".getResult($key,$s)."<br/>";
    }
}
function getResult($mblog,$result){
    
$match="";
    
switch($mblog){
        
case "twitter":
        
case "fanfou":
            
$reg="/<error>(.*?)<\/error>/";
            
preg_match($reg,$result,$match);
            
break;
        
case "digu":
            
$reg="/<h3>(.*?)<\/h3>/";
            
preg_match($reg,$result,$match);
            
break;
        
case "zuosa":
            
if($result!='0')
                
$match=array("更新不成功","更新不成功");
            
break;
    }
    
$match=$match?$match[1]:"成功更新";
    
return $match;
}
function postMblog($mblog,$user,$pass,$data){
    
$curl=curl_init();
    curl_setopt(
$curl,CURLOPT_URL,$mblog);
    curl_setopt(
$curl,CURLOPT_USERPWD,$user.":".$pass);
    curl_setopt(
$curl,CURLOPT_RETURNTRANSFER,1);
    curl_setopt(
$curl,CURLOPT_POSTFIELDS,$data);
    
$s=curl_exec($curl);
    curl_close(
$curl);
    
return $s;
}

?>
<form method="post" name="mblog" action="?action=post">
<textarea name="data" maxlength="140" rows="6" cols="60"></textarea><br/>
用户名:
<input name="username" /><br/>
&nbsp;&nbsp;码:<input name="password" type="password"/><br/>
<input type="checkbox"  name="m[twitter]" value="1" checked="checked"/> Twitter 
<input type="checkbox" name="m[fanfou]" value="1" checked="checked"/> 饭否 
<input type="checkbox" name="m[digu]" value="1" checked="checked"/> 嘀咕 
<input type="checkbox" name="m[zuosa]" value="1" checked="checked"/> 做啥
<br/><br/>
<input type="submit" value=" 发 布 "/>
</form>

 

posted @ 2009-06-16 13:03  _拖鞋_  阅读(694)  评论(2编辑  收藏  举报