分类: 系统运维
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 测试通过