替wiz筆記寫了一個sdk,https://github.com/jiankers/WizSDK
主要功能介紹:php
登陸wiz。 提取用戶信息。 提取筆記目錄列表。 提取筆記列表。 提取筆記內容。
誰須要fork吧git
<?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'] ); }
WizSDK.class.phpgithub
<?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); } }