Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1145841
  • 博文数量: 1310
  • 博客积分: 3980
  • 博客等级: 中校
  • 技术积分: 8005
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-09 22:05
文章分类

全部博文(1310)

文章存档

2011年(1)

2008年(1309)

我的朋友

分类: 系统运维

2008-05-22 10:48:07

使用前需知:
1. 您必须对PHP以及XMLRPC有所了解;
2. 您必须对metaWeblog API有所了解, 并且必须按照博客蓝对博客搬家所作的三个扩展接口来实现您的服务端代码;
3. 您要对自己的行为负责, 不要在生产系统上测试您的代码, 不要利用API做不正当的行为, 由此产生的一切后果由您自己承担;
这里只写出博客蓝扩展的三个接口, 其他接口您可以在网上下载得到。
我们在这里只给出程序的大概样例, 您可以非常方便的集成到您自己的系统。
1. metaWeblog.newComment

function newComment($comment){$message = new xmlrpcmsg('metaWeblog.newComment',
($this->getStringValue($blogid),
$this->getStringValue($username),
$this->getStringValue($password),
$this->getCommentStruct($comment)));
$c = new xmlrpc_client($agent, $host, $port);
$c->setDebug(0);
$r = $c->send($message, TIMEOUT);
if(!$r->faultCode()){returntrue;
}else{"Fault: ";
"Code: " . $r->faultCode() . " Reason '";
"Reason: " . $r->faultString()."'n";
returnfalse;
} 
function getCommentStruct($comment){$xml_items = ();
 
$xml_items['postid'] = 
$this->getIntValue($comment->_id);
$xml_items['parentId'] = 
$this->getIntValue(0);
$xml_items['dateCreated'] = 
$this->getDateValue($comment->_date);
$xml_items['title'] = 
$this->getStringValue($comment->_topic);
$xml_items['description'] = 
$this->getStringValue($comment->_text);
$xml_items['commentUserName'] = 
$this->getStringValue($comment->_userName);
$xml_items['commentUserEmail'] = 
$this->getStringValue($comment->_userEmail);
$xml_items['commentUserUrl'] = 
$this->getStringValue($comment->_userUrl);
$xml_items['commentUserIp'] = 
$this->getStringValue($comment->_clientIp);
 
returnnew xmlrpcval($xml_items, "struct");    
} 
 

2. metaWeblog.newCategory

function newCategory($categoryname){if(($categoryname)){"Category name empty!n";
returnfalse;
}$f = new xmlrpcmsg('metaWeblog.newCategory',
($this->getStringValue($blogid),
$this->getStringValue($username),
$this->getStringValue($password),                        
$this->getStringValue($categoryname)));
 
$c = new xmlrpc_client($agent, $host, $port);
$c->setDebug(0);
$r = $c->send($message, TIMEOUT);
 
$v = $r->value();
if(!$r->faultCode()){return php_xmlrpc_decode($v);
}else{"Fault: ";
"Code: " . $r->faultCode() . " Reason '";
"Reason: " . $r->faultString()."'n";
returnfalse;
}} 

3. metaWeblog.getCategoryPosts

function getCategoryPosts($categoryid = 0, $amount = -1){$f = new xmlrpcmsg('metaWeblog.getCategoryPosts',
($this->getStringValue($blogid),
$this->getStringValue($username),
$this->getStringValue($password),
$this->getIntValue($categoryid),
$this->getIntValue($amount)));
 
$c = new xmlrpc_client($agent, $host, $port);
$c->setDebug(0);
$r = $c->send($message, TIMEOUT);
 
if(!$r->faultCode()){$v = $r->value();
$res = php_xmlrpc_decode($v);
// $res should depends on server side return, normaly it's a post array}else{"Fault: ";
"Code: " . $r->faultCode() . " Reason '";
"Reason: " . $r->faultString()."'n";
returnfalse;
}} 

本程序在PHP4 和XML-RPC for PHP version 2.0, final 测试通过

阅读(276) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~