>php教程 >php手册 >Wiz笔记SDK

Wiz笔记SDK

WBOY
WBOY원래의
2016-06-06 19:32:271054검색

替wiz笔记写了一个sdk,https://github.com/jiankers/WizSDK 主要功能介绍: 登录wiz。 提取用户信息。 提取笔记目录列表。 提取笔记列表。 提取笔记内容。 谁需要fork吧 无 源码与演示: 源码出处 ?phpinclude "WizSDK.class.php";$username = "example@examp

替wiz笔记写了一个sdk,https://github.com/jiankers/WizSDK
主要功能介绍:

    登录wiz。

    提取用户信息。

    提取笔记目录列表。

    提取笔记列表。
    
    提取笔记内容。
谁需要fork吧

源码与演示:源码出处

<?php
include "WizSDK.class.php";

$username = "example@example.com";  //wiz账号
$password = "";       //wiz密码

$wiz  = new WizSDK($username,$password);

$wiz->debug = true;

//登录
$info    = $wiz->login();
$token   = $info['token'];
$kb_guid = $info['kb_guid'];


//获取用户信息
$userinfo = $wiz->getUserInfo($token);

//获取目录列表
$dirinfo = $wiz->getDirList($token, $kb_guid);


if(!isset($_GET['dir']) && !isset($_GET['id'])){
	echo "<ul>";
	foreach($dirinfo['list'] as $dirs){

		 $dir =  urlencode($dirs['location']);
		  
		 echo "<li><a href='?dir=".$dir."'>".$dirs['category_name']."</a></li>";
	}
	echo "</ul>";
}


if(isset($_GET['dir'])){

	 //获取每个目录下笔记列表
	$doclist[] = $wiz->getDirDocList($token, $kb_guid, $_GET['dir']);

   echo "<ul>";
	foreach($doclist as $doc){
   
		 foreach($doc['list'] as $note){

			   
		     echo "<li><a href='?id=".$note['document_guid']."'>".$note['document_title']."</a></li>";
		 }
	}
	
    echo "</ul>";
}



if(isset($_GET['id'])){
     $document_guid = $_GET['id'];
     $info = $wiz->getDirDocShow($token, $kb_guid, $document_guid);
     
     //针对wiz笔记图片相对路径进行补全 
     echo preg_replace ( "/src\='\/unzip\//", "src='http://beta.note.wiz.cn/unzip/", $info['document_info']['document_body'] );
	 
}



<?php

/**
 *  WizSDK.class.php  为知笔记api操作类
 *
 * @author              LuJunjian <CmsSuper@163.com>
 * @license				http://www.php0.net/
 * @version             0.1
 * @lastmodify			2013-10-25
 */

 
class WizSDK{
	  
	  private $apiurl   = 'http://beta.note.wiz.cn';
	  private $username = '';
	  private $passwd   = '';
	  public  $debug     = true;    //开启debug则每次都执行登录 
 	  
      function __construct($username,$passwd){
	
	      $this->username = $username;
	      $this->passwd = $passwd;
	  }
	  
	  
	  /**
	   *   登录验证 
	   *  该方法执行一次即可,因为wiz笔记内部不需要验证登录,此方法的作用是获取token&kb_guid备其他方法使用
	   */
      public function login(){
            

			if(!file_exists('./user.ini') || $this->debug == false){
	
				ob_start();//开启缓存
				
				//登陆认证
				$url = "http://note.wiz.cn/api/login";

				$post_data = array( "user_id" =>$this->username,"password" =>$this->passwd,"isKeep_password"=>"off","debug"=>"");

				$cookie_jar = tempnam('./temp','cookie');//存放COOKIE的文件

				$ch = curl_init();

				curl_setopt($ch, CURLOPT_URL, $url);

				curl_setopt($ch, CURLOPT_POST, 1);

				curl_setopt($ch, CURLOPT_HEADER, 0);

				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);

				curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);  

				curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);  //保存cookie信息

				curl_exec($ch);

				curl_close($ch);
				
				$json = ob_get_contents();
				
				//写进配置文件
				@file_put_contents('./user.ini',$json);

				ob_clean();
				
			}else{
			    $json = file_get_contents('./user.ini');
			}
			
			return json_decode($json,true);
	   }
	   
	   
	    //获取用户信息
	   public function getUserInfo($token){
	   
			$token = isset($_GET['token'])?$_GET['token']:$token;
			$url   = $this->apiurl."/api/user/info?client_type=web2.0&api_version=3&token={$token}&_=1385364125279";
			$info  = @file_get_contents($url);
			
			return json_decode($info,true);
	   }

	   
	    //获取目录列表
		public function getDirList($token, $kb_guid){

			$token = isset($_GET['token'])?$_GET['token']:$token;
			$kb_guid = isset($_GET['kb_guid'])?$_GET['kb_guid']:$kb_guid;
			$url   = $this->apiurl."/api/category/all?client_type=web2.0&api_version=3&token={$token}&kb_guid={$kb_guid}&_=1385364126264";
			$info  = @file_get_contents($url);
			
			return json_decode($info,true);
		}

		
		//获取目录下文章列表
		public function getDirDocList($token, $kb_guid, $dir){

			$token   = isset($_GET['token'])?$_GET['token']:$token;
			$kb_guid = isset($_GET['kb_guid'])?$_GET['kb_guid']:$kb_guid;
			$dir     = isset($_GET['dir'])?urlencode($_GET['dir']):$dir;
			$url     = $this->apiurl."/api/document/list?client_type=web2.0&api_version=3&token={$token}&action_cmd=category&action_value={$dir}&kb_guid={$kb_guid}&_=1385366664005";
			$info    = @file_get_contents($url);
			  
			return json_decode($info,true);
		}


		//获取目录下文章详情
		public function getDirDocShow($token, $kb_guid, $document_guid){

	        $token   = isset($_GET['token'])?$_GET['token']:$token;
			$kb_guid = isset($_GET['kb_guid'])?$_GET['kb_guid']:$kb_guid;
			$document_guid = isset($_GET['document_guid'])?$_GET['document_guid']:$document_guid;
			$url     = $this->apiurl."/api/document/info?client_type=web2.0&api_version=3&token={$token}&kb_guid={$kb_guid}&document_guid={$document_guid}&_=1385370541346";
			$info    = @file_get_contents($url);
			
			return json_decode($info,true);
		}
	 
}


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.