微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xmlrpc应用metaweblogAPI

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan

MetaweblogAPI类
整个项目部分内容,看看意思.其实很简单.关键部分略掉

Xmlrpc_encode不是那么好用,有的东西不能使用.例如struct类型
所以如果有需要的话,还是自己写一个xml结构,然后发过去.OK.

class Send extends SysLOG
{
 private $blogid = "xxx"; //博ID
 private $username = "xxx"; //用户名
 private $userpassword = "xxx"; //用户密码
 private $url = " http://blog.csdn.net/mayongzhan/services/metablogapi.aspx"; //地址  function __construct($blogid,$username,$userpassword,$url) {  $this->blogid = $blogid;  $this->username = $username;  $this->userpassword = $userpassword;  $this->url = $url; }  //添加类别 public function addCate($cateName) {  //MetaWeblog.newCategory 新增类别  $request = xmlrpc_encode_request(      'MetaWeblog.newCategory',      array($this->blogid,        $this->username,        $this->userpassword,        $cateName),      array('encoding' => 'UTF-8')          );  return $this->xmlRPCSend($request); //类别ID }  //添加文章 public function addPage($title,$content,$down,$cate) {  略 }  //其他暂时用不到的操作 private function otherOP() {  //MetaWeblog.getCategories 显示类别  //MetaWeblog.getPost 得到文章  //MetaWeblog.editPost 编辑文章  //blogger.deletePost 删除文章  //blogger.getRecentPosts  //blogger.getUsersBlogs  //MetaWeblog.getCategoryPosts   //MetaWeblog.getPostByID   //MetaWeblog.getRecentPosts  //MetaWeblog.newComment  //MetaWeblog.newMediaObject  //mt.getCategoryList  //mt.getPostCategories  //mt.setPostCategories }  private function xmlRPCSend($request) {  try  {   $context = stream_context_create(array('http' => array(   'method' => "POST",   'header' => "Content-Type: text/xml",   'content' => $request   )));   $file = file_get_contents($this->url,false,$context);      if(!$file) {    throw new Exception('错误:得不到webservice的response');   }      $response = xmlrpc_decode($file);      if (is_array($response) && xmlrpc_is_fault($response))   {    throw new Exception($response['faultString'],    $response['faultCode']);   }      return $response;  }  catch (Exception $e)  {   $this->sys_log($e->getMessage(),'errorSend.log');  } }}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐