Source for file vdisk.ex.class.php

Documentation is available at vdisk.ex.class.php

  1. <?php
  2. /**
  3.  * vDisk sdk for SAE and Standard PHP
  4.  *
  5.  * @version $Id$
  6.  * @package sae
  7.  * @author Bruce Chen
  8.  */
  9.  
  10.  
  11. /**
  12.  * @ignore
  13.  */
  14. define('URL_GET_TOKEN''http://openapi.vdisk.me/?m=auth&a=get_token');
  15. /**
  16.  * @ignore
  17.  */
  18. define('URL_KEEP_TOKEN''http://openapi.vdisk.me/?m=user&a=keep_token');
  19. /**
  20.  * @ignore
  21.  */
  22. define('URL_UPLOAD_FILE''http://openapi.vdisk.me/?m=file&a=upload_file');
  23. /**
  24.  * @ignore
  25.  */
  26. define('URL_UPLOAD_SHARE_FILE''http://openapi.vdisk.me/?m=file&a=upload_share_file');
  27. /**
  28.  * @ignore
  29.  */
  30. define('URL_CREATE_DIR''http://openapi.vdisk.me/?m=dir&a=create_dir');
  31. /**
  32.  * @ignore
  33.  */
  34. define('URL_GET_LIST''http://openapi.vdisk.me/?m=dir&a=get_list');
  35. /**
  36.  * @ignore
  37.  */
  38. define('URL_GET_QUOTA''http://openapi.vdisk.me/?m=file&a=get_quota');
  39. /**
  40.  * @ignore
  41.  */
  42. define('URL_UPLOAD_WITH_SHA1''http://openapi.vdisk.me/?m=file&a=upload_with_sha1');
  43. /**
  44.  * @ignore
  45.  */
  46. define('URL_GET_FILE_INFO''http://openapi.vdisk.me/?m=file&a=get_file_info');
  47. /**
  48.  * @ignore
  49.  */
  50. define('URL_DELETE_DIR''http://openapi.vdisk.me/?m=dir&a=delete_dir');
  51. /**
  52.  * @ignore
  53.  */
  54. define('URL_DELETE_FILE''http://openapi.vdisk.me/?m=file&a=delete_file');
  55. /**
  56.  * @ignore
  57.  */
  58. define('URL_COPY_FILE''http://openapi.vdisk.me/?m=file&a=copy_file');
  59. /**
  60.  * @ignore
  61.  */
  62. define('URL_MOVE_FILE''http://openapi.vdisk.me/?m=file&a=move_file');
  63. /**
  64.  * @ignore
  65.  */
  66. define('URL_RENAME_FILE''http://openapi.vdisk.me/?m=file&a=rename_file');
  67. /**
  68.  * @ignore
  69.  */
  70. define('URL_RENAME_DIR''http://openapi.vdisk.me/?m=dir&a=rename_dir');
  71. /**
  72.  * @ignore
  73.  */
  74. define('URL_MOVE_DIR''http://openapi.vdisk.me/?m=dir&a=move_dir');
  75. /**
  76.  * @ignore
  77.  */
  78. define('URL_SHARE_FILE''http://openapi.vdisk.me/?m=file&a=share_file');
  79. /**
  80.  * @ignore
  81.  */
  82. define('URL_CANCEL_SHARE_FILE''http://openapi.vdisk.me/?m=file&a=cancel_share_file');
  83. /**
  84.  * @ignore
  85.  */
  86. define('URL_RECYCLE_GET_LIST''http://openapi.vdisk.me/?m=recycle&a=get_list');
  87. /**
  88.  * @ignore
  89.  */
  90. define('URL_TRUNCATE_RECYCLE_GET''http://openapi.vdisk.me/?m=recycle&a=truncate_recycle');
  91. /**
  92.  * @ignore
  93.  */
  94. define('URL_RECYCLE_DELETE_FILE''http://openapi.vdisk.me/?m=recycle&a=delete_file');
  95. /**
  96.  * @ignore
  97.  */
  98. define('URL_RECYCLE_DELETE_DIR''http://openapi.vdisk.me/?m=recycle&a=delete_dir');
  99. /**
  100.  * @ignore
  101.  */
  102. define('URL_RECYCLE_RESTORE_FILE''http://openapi.vdisk.me/?m=recycle&a=restore_file');
  103. /**
  104.  * @ignore
  105.  */
  106. define('URL_RECYCLE_RESTORE_DIR''http://openapi.vdisk.me/?m=recycle&a=restore_dir');
  107. /**
  108.  * @ignore
  109.  */
  110. define('URL_GET_DIRID_WITH_PATH''http://openapi.vdisk.me/?m=dir&a=get_dirid_with_path');
  111. /**
  112.  * @ignore
  113.  */
  114. define('URL_EMAIL_SHARE_FILE''http://openapi.vdisk.me/?m=file&a=email_share_file');
  115.  
  116.  
  117.  
  118. /**
  119.  * 微盘API
  120.  *
  121.  * 微盘Open API是为第三方开发者提供的一套REST接口,通过该接口任何第三方的公司和个人都可以创建基于微盘的应用.更多{@link http://vdisk.me/api 相关说明} .
  122.  * 
  123.  * 使用方法:
  124.  * <code>
  125.  * include_once('vdisk.ex.class.php');
  126.  * $appkey = 1234567;
  127.  * $appsecret = '123456739cc20556637a576ea1234567';
  128.  * $username = 'username@gmail.com';
  129.  * $password = '123456';
  130.  * 
  131.  * $vdisk = new vDisk($appkey, $appsecret);
  132.  * 
  133.  * $vdisk->get_token($username, $password);
  134.  * $_SESSION['token'] = $vdisk->token;
  135.  * 
  136.  * $vdisk->keep_token();
  137.  * 
  138.  * $r = $vdisk->upload_share_file('文件.txt', 0);
  139.  * $r = $vdisk->get_list(0);
  140.  * $r = $vdisk->get_quota();
  141.  * $r = $vdisk->upload_with_md5('测试.pdf', '03d5717869bb075e3bad73b527fabc8a');
  142.  * $r = $vdisk->get_file_info(219379);
  143.  * $r = $vdisk->create_dir('测试一下');
  144.  * $r = $vdisk->delete_dir(35647);
  145.  * $r = $vdisk->delete_file(123);
  146.  * $r = $vdisk->copy_file(219379, 0, '副本.txt');
  147.  * $r = $vdisk->move_file(219379, 0, '副本.txt');
  148.  * $r = $vdisk->rename_file(219379, '新的新的新的.z');
  149.  * $r = $vdisk->rename_dir(3929, '新的新的新的');
  150.  * $r = $vdisk->move_dir(3929, "我的图片们", 0);
  151.  * print_r($r);
  152.  * </code>
  153.  * 
  154.  * @link http://vdisk.me/api
  155.  * @package sae
  156.  * @version $Id$
  157.  * @author Bruce Chen
  158.  */
  159. class vDisk 
  160. {
  161.  
  162.     /**
  163.      * @ignore
  164.      */
  165.     public $appkey;
  166.     /**
  167.      * @ignore
  168.      */
  169.     public $appsecret;
  170.     /**
  171.      * @ignore
  172.      */
  173.     public $username;
  174.     /**
  175.      * @ignore
  176.      */
  177.     public $password;
  178.     /**
  179.      * @ignore
  180.      */
  181.     public $token;
  182.  
  183.     private $_errno;    
  184.     private $_error;
  185.  
  186.  
  187.     /**
  188.      * 构造函数
  189.      *
  190.      * @param string $app_key 分配给你的appkey
  191.      * @param string $app_secret 分配给你的appsecret
  192.      *
  193.      * @return void 
  194.      *
  195.      * @author Bruce Chen
  196.      *
  197.      */
  198.     public function __construct($app_key$app_secret)
  199.     {
  200.         if(!($app_key && $app_secret)) 
  201.         {    
  202.             $this->set_error(-2'app_key or app_secret empty');
  203.             return;
  204.         }
  205.  
  206.         $this->appkey $app_key;
  207.         $this->appsecret $app_secret;
  208.         $this->set_error(-1'empty');
  209.     }
  210.  
  211.  
  212.     /**
  213.      * 获得token
  214.      *
  215.      * @param string $username 
  216.      * @param string $password 
  217.      * @param string $app_type 可选参数, 如:$app_type=sinat (注意: 目前支持微博帐号)
  218.      *
  219.      * @return array 
  220.      *
  221.      * @author Bruce Chen
  222.      *
  223.      */
  224.     public function get_token($username$password$app_type=null)
  225.     {
  226.  
  227.         $this->username $username;
  228.         $this->password $password;
  229.  
  230.         $time time();
  231.         $param array
  232.  
  233.                 'account' => $username
  234.                 'password' => $password
  235.                 'time' => $time,
  236.                 'appkey' => $this->appkey,
  237.                 'signature' => hash_hmac('sha256'"account={$username}&appkey={$this->appkey}&password={$password}&time={$time}", $this->appsecretfalse)
  238.                 
  239.                 );
  240.                 
  241.         if($app_type$param['app_type'$app_type;
  242.  
  243.         $data $this->_request(URL_GET_TOKEN$param);
  244.  
  245.         if($data && $data['err_code'== 0)
  246.         {
  247.             $this->token $data['data']['token'];
  248.         }
  249.  
  250.         return $data;
  251.     }
  252.  
  253.  
  254.     /**
  255.      * 保持token
  256.      *
  257.      * @param string $token 可选参数
  258.      *
  259.      * @return array 
  260.      *
  261.      * @author Bruce Chen
  262.      *
  263.      */
  264.     public function keep_token($token=null)
  265.     {
  266.         if($token)
  267.         {
  268.             $this->token $token;
  269.         }
  270.  
  271.         if($this->token)
  272.         {
  273.             $param = array(
  274.  
  275.                     'token' => $this->
  276. token
  277.                     );
  278.  
  279.             $data $this->_request(URL_KEEP_TOKEN$param);
  280.  
  281.             return $data;
  282.         }
  283.         else
  284.         {
  285.             return false;
  286.         }
  287.     }
  288.  
  289.  
  290.     /**
  291.      * 上传文件(10M以下)
  292.      *
  293.      * @param string $file_path 本地文件真实路径
  294.      *
  295.      * @param int $dir_id 目录id
  296.      *
  297.      * @param string $cover 可选参数, yes:覆盖; no:如有重名返回错误信息
  298.      *
  299.      * @return array 
  300.      *
  301.      * @author Bruce Chen
  302.      *
  303.      */
  304.     public function upload_file($file_path, $dir_id, $cover='yes')
  305.     {
  306.  
  307.         if($this->token)
  308.         {
  309.             $param = array(
  310.  
  311.                     'file' => '@'.$file_path,
  312.                     'token' => $this->token,
  313.                     'dir_id' => $dir_id,
  314.                     'cover' => $cover
  315.                     );
  316.  
  317.             $data $this->_request(URL_UPLOAD_FILE$param);
  318.  
  319.             return $data;
  320.         }
  321.         else
  322.         {
  323.             return false;
  324.         }
  325.  
  326.     }
  327.  
  328.  
  329.     /**
  330.      * 上传并分享文件(10M以下)
  331.      *
  332.      * @param string $file_path 本地文件真实路径
  333.      *
  334.      * @param int $dir_id 目录id
  335.      *
  336.      * @param string $cover 可选参数, yes:覆盖; no:如有重名返回错误信息
  337.      *
  338.      * @return array 包含分享后的url
  339.      *
  340.      * @author Bruce Chen
  341.      *
  342.      */
  343.     public function upload_share_file($file_path, $dir_id, $cover='yes')
  344.     {
  345.         if($this->token)
  346.         {
  347.             $param = array(
  348.  
  349.                     'file' => '@'.$file_path,
  350.                     'token' => $this->token,
  351.                     'dir_id' => $dir_id,
  352.                     'cover' => $cover
  353.                     );
  354.  
  355.             $data $this->_request(URL_UPLOAD_SHARE_FILE$param);
  356.  
  357.             return $data;
  358.         }
  359.         else
  360.         {
  361.             return false;
  362.         }
  363.     }
  364.  
  365.  
  366.     /**
  367.      * 创建目录
  368.      *
  369.      * @param string $create_name 目录的名称
  370.      *
  371.      * @param int $parent_id 父目录的id
  372.      *
  373.      * @return array 
  374.      *
  375.      * @author Bruce Chen
  376.      *
  377.      */
  378.     public function create_dir($create_name, $parent_id=0)
  379.     {
  380.         if($this->token)
  381.         {
  382.             $param = array(
  383.  
  384.                     'token' => $this->token,
  385.                     'create_name' => $create_name,
  386.                     'parent_id' => $parent_id
  387.                     );
  388.  
  389.             $data $this->_request(URL_CREATE_DIR$param);
  390.  
  391.             return $data;
  392.         }
  393.         else
  394.         {
  395.             return false;
  396.         }
  397.  
  398.     }
  399.  
  400.  
  401.     /**
  402.      * 获得列表(包括文件和子目录)
  403.      *
  404.      * @param int $dir_id 目录的id
  405.      *
  406.      * @return array 
  407.      *
  408.      * @author Bruce Chen
  409.      *
  410.      */
  411.     public function get_list($dir_id)
  412.     {
  413.         if($this->token)
  414.         {
  415.             $param = array(
  416.  
  417.                     'token' => $this->token,
  418.                     'dir_id' => $dir_id
  419.                     );
  420.  
  421.             $data $this->_request(URL_GET_LIST$param);
  422.  
  423.             return $data;
  424.         }
  425.         else
  426.         {
  427.             return false;
  428.         }
  429.     }
  430.  
  431.  
  432.     /**
  433.      * 获得容量信息
  434.      *
  435.      * @return array 
  436.      *
  437.      * @author Bruce Chen
  438.      *
  439.      */
  440.     public function get_quota()
  441.     {
  442.         if($this->token)
  443.         {
  444.             $param = array(
  445.  
  446.                     'token' => $this->
  447. token
  448.                     );
  449.  
  450.             $data $this->_request(URL_GET_QUOTA$param);
  451.  
  452.             return $data;
  453.         }
  454.         else
  455.         {
  456.             return false;
  457.         }
  458.     }
  459.  
  460.  
  461.     /**
  462.      * 无文件上传(md5)
  463.      *
  464.      * @param string $file_name 上传以后的文件名
  465.      * @param string $md5 要上传文件的md5值
  466.      * @param int $dir_id 目标目录的id, 0为根目录
  467.      *
  468.      * @return array 
  469.      *
  470.      * @author Bruce Chen
  471.      *
  472.      */
  473.     public function upload_with_sha1($file_name, $sha1, $dir_id=0)
  474.     {
  475.         if($this->token)
  476.         {
  477.             $param = array(
  478.  
  479.                     'token' => $this->token,
  480.                     'file_name' => $file_name,
  481.                     'sha1' => $sha1,
  482.                     'dir_id' => $dir_id
  483.                     );
  484.  
  485.             $data $this->_request(URL_UPLOAD_WITH_SHA1$param);
  486.  
  487.             return $data;
  488.         }
  489.         else
  490.         {
  491.             return false;
  492.         }
  493.     }
  494.  
  495.  
  496.     /**
  497.      * 获得文件的信息
  498.      *
  499.      * @param int $fid 文件的id
  500.      *
  501.      * @return array 
  502.      *
  503.      * @author Bruce Chen
  504.      *
  505.      */
  506.     public function get_file_info($fid)
  507.     {
  508.         if($this->token)
  509.         {
  510.             $param = array(
  511.  
  512.                     'token' => $this->token,
  513.                     'fid' => $fid,
  514.                     );
  515.  
  516.             $data $this->_request(URL_GET_FILE_INFO$param);
  517.  
  518.             return $data;
  519.         }
  520.         else
  521.         {
  522.             return false;
  523.         }
  524.     }
  525.  
  526.  
  527.     /**
  528.      * 删除目录
  529.      *
  530.      * @param int $dir_id 目录的id
  531.      *
  532.      * @return array 
  533.      *
  534.      * @author Bruce Chen
  535.      *
  536.      */
  537.     public function delete_dir($dir_id)
  538.     {
  539.         if($this->token)
  540.         {
  541.             $param = array(
  542.  
  543.                     'token' => $this->token,
  544.                     'dir_id' => $dir_id,
  545.                     );
  546.  
  547.             $data $this->_request(URL_DELETE_DIR$param);
  548.  
  549.             return $data;
  550.         }
  551.         else
  552.         {
  553.             return false;
  554.         }
  555.     }
  556.  
  557.  
  558.     /**
  559.      * 删除文件
  560.      *
  561.      * @param int $fid 文件的id
  562.      *
  563.      * @return array 
  564.      *
  565.      * @author Bruce Chen
  566.      *
  567.      */
  568.     public function delete_file($fid)
  569.     {
  570.         if($this->token)
  571.         {
  572.             $param = array(
  573.  
  574.                     'token' => $this->token,
  575.                     'fid' => $fid,
  576.                     );
  577.  
  578.             $data $this->_request(URL_DELETE_FILE$param);
  579.  
  580.             return $data;
  581.         }
  582.         else
  583.         {
  584.             return false;
  585.         }
  586.     }
  587.  
  588.  
  589.     /**
  590.      * 复制文件
  591.      *
  592.      * @param int $fid 要复制文件的id
  593.      * @param int $to_dir_id 目标目录的id
  594.      * @param string $new_name 副本文件的名称
  595.      *
  596.      * @return array 
  597.      *
  598.      * @author Bruce Chen
  599.      *
  600.      */
  601.     public function copy_file($fid, $to_dir_id, $new_name)
  602.     {
  603.         if($this->token)
  604.         {
  605.             $param = array(
  606.  
  607.                     'token' => $this->token,
  608.                     'fid' => $fid,
  609.                     'to_dir_id' => $to_dir_id,
  610.                     'new_name' => $new_name
  611.                     );
  612.  
  613.             $data $this->_request(URL_COPY_FILE$param);
  614.  
  615.             return $data;
  616.         }
  617.         else
  618.         {
  619.             return false;
  620.         }
  621.     }
  622.  
  623.  
  624.     /**
  625.      * 移动文件
  626.      *
  627.      * @param int $fid 要移动文件的id
  628.      * @param int $to_dir_id 目标目录的id
  629.      * @param string $new_name 移动后的文件名称
  630.      *
  631.      * @return array 
  632.      *
  633.      * @author Bruce Chen
  634.      *
  635.      */
  636.     public function move_file($fid, $to_dir_id, $new_name)
  637.     {
  638.         if($this->token)
  639.         {
  640.             $param = array(
  641.  
  642.                     'token' => $this->token,
  643.                     'fid' => $fid,
  644.                     'to_dir_id' => $to_dir_id,
  645.                     'new_name' => $new_name
  646.                     );
  647.  
  648.             $data $this->_request(URL_MOVE_FILE$param);
  649.  
  650.             return $data;
  651.         }
  652.         else
  653.         {
  654.             return false;
  655.         }
  656.     }
  657.  
  658.  
  659.     /**
  660.      * 重命名文件
  661.      *
  662.      * @param int $fid 文件的id
  663.      * @param string $new_name 新文件名称
  664.      *
  665.      * @return array 
  666.      *
  667.      * @author Bruce Chen
  668.      *
  669.      */
  670.     public function rename_file($fid, $new_name)
  671.     {
  672.         if($this->token)
  673.         {
  674.             $param = array(
  675.  
  676.                     'token' => $this->token,
  677.                     'fid' => $fid,
  678.                     'new_name' => $new_name
  679.                     );
  680.  
  681.             $data $this->_request(URL_RENAME_FILE$param);
  682.  
  683.             return $data;
  684.         }
  685.         else
  686.         {
  687.             return false;
  688.         }        
  689.     }
  690.  
  691.  
  692.     /**
  693.      * 重命名目录
  694.      *
  695.      * @param int $dir_id 目录的id
  696.      * @param string $new_name 新名称
  697.      *
  698.      * @return array 
  699.      *
  700.      * @author Bruce Chen
  701.      *
  702.      */
  703.     public function rename_dir($dir_id, $new_name)
  704.     {
  705.         if($this->token)
  706.         {
  707.             $param = array(
  708.  
  709.                     'token' => $this->token,
  710.                     'dir_id' => $dir_id,
  711.                     'new_name' => $new_name
  712.                     );
  713.  
  714.             $data $this->_request(URL_RENAME_DIR$param);
  715.  
  716.             return $data;
  717.         }
  718.         else
  719.         {
  720.             return false;
  721.         }    
  722.     }
  723.  
  724.  
  725.     /**
  726.      * 移动目录
  727.      *
  728.      * @param int $dir_id 目录的id
  729.      * @param string $new_name 移动后的名称
  730.      * @param int $to_parent_id 目标目录的id
  731.      *
  732.      * @return array 
  733.      *
  734.      * @author Bruce Chen
  735.      *
  736.      */
  737.     public function move_dir($dir_id, $new_name, $to_parent_id)
  738.     {
  739.         if($this->token)
  740.         {
  741.             $param = array(
  742.  
  743.                     'token' => $this->token,
  744.                     'dir_id' => $dir_id,
  745.                     'new_name' => $new_name,
  746.                     'to_parent_id' => $to_parent_id
  747.                     );
  748.  
  749.             $data $this->_request(URL_MOVE_DIR$param);
  750.  
  751.             return $data;
  752.         }
  753.         else
  754.         {
  755.             return false;
  756.         }
  757.     }
  758.  
  759.  
  760.     /**
  761.      * 分享文件
  762.      *
  763.      * @param int $fid 文件的id
  764.      *
  765.      * @return array 
  766.      *
  767.      * @author Bruce Chen
  768.      *
  769.      */
  770.     public function share_file($fid)
  771.     {
  772.         if($this->token)
  773.         {
  774.             $param = array(
  775.  
  776.                     'token' => $this->token,
  777.                     'fid' => $fid
  778.                     );
  779.  
  780.             $data $this->_request(URL_SHARE_FILE$param);
  781.  
  782.             return $data;
  783.         }
  784.         else
  785.         {
  786.             return false;
  787.         }
  788.     }
  789.  
  790.  
  791.     /**
  792.      * 取消分享
  793.      *
  794.      * @param int $fid 文件的id
  795.      *
  796.      * @return array 
  797.      *
  798.      * @author Bruce Chen
  799.      *
  800.      */
  801.     public function cancel_share_file($fid)
  802.     {
  803.         if($this->token)
  804.         {
  805.             $param = array(
  806.  
  807.                     'token' => $this->token,
  808.                     'fid' => $fid
  809.                     );
  810.  
  811.             $data $this->_request(URL_CANCEL_SHARE_FILE$param);
  812.  
  813.             return $data;
  814.         }
  815.         else
  816.         {
  817.             return false;
  818.         }
  819.     }
  820.  
  821.  
  822.     /**
  823.      * 获得回收站列表
  824.      *
  825.      * @param int $page 第几页
  826.      * @param int $page_size 每页显示条数
  827.      *
  828.      * @return array 
  829.      *
  830.      * @author Bruce Chen
  831.      *
  832.      */
  833.     public function recycle_get_list($page=1, $page_size=25)
  834.     {
  835.         if($this->token)
  836.         {
  837.             $param = array(
  838.  
  839.                     'token' => $this->token,
  840.                     'page' => $page,
  841.                     'page_size' => $page_size
  842.                     );
  843.  
  844.             $data $this->_request(URL_RECYCLE_GET_LIST$param);
  845.  
  846.             return $data;
  847.         }
  848.         else
  849.         {
  850.             return false;
  851.         }
  852.     }
  853.  
  854.  
  855.     /**
  856.      * 清空回收站
  857.      *
  858.      * @return array 
  859.      *
  860.      * @author Bruce Chen
  861.      *
  862.      */
  863.     public function truncate_recycle()
  864.     {
  865.         if($this->token)
  866.         {
  867.             $param = array(
  868.  
  869.                     'token' => $this->
  870. token
  871.                     );
  872.  
  873.             $data $this->_request(URL_TRUNCATE_RECYCLE_GET$param);
  874.  
  875.             return $data;
  876.         }
  877.         else
  878.         {
  879.             return false;
  880.         }
  881.     }
  882.  
  883.     /**
  884.      * 从回收站中彻底删除一个文件
  885.      *
  886.      * @param int $fid 文件id
  887.      *
  888.      * @return array 
  889.      *
  890.      * @author Bruce Chen
  891.      *
  892.      */
  893.     public function recycle_delete_file($fid)
  894.     {
  895.         if($this->token)
  896.         {
  897.             $param = array(
  898.  
  899.                     'token' => $this->token,
  900.                     'fid' => $fid
  901.                     );
  902.  
  903.             $data $this->_request(URL_RECYCLE_DELETE_FILE$param);
  904.  
  905.             return $data;
  906.         }
  907.         else
  908.         {
  909.             return false;
  910.         }
  911.     }
  912.  
  913.     /**
  914.      * 从回收站中彻底删除一个目录
  915.      *
  916.      * @param int $dir_id 目录的id
  917.      *
  918.      * @return array 
  919.      *
  920.      * @author Bruce Chen
  921.      *
  922.      */
  923.     public function recycle_delete_dir($dir_id)
  924.     {
  925.         if($this->token)
  926.         {
  927.             $param = array(
  928.  
  929.                     'token' => $this->token,
  930.                     'dir_id' => $dir_id
  931.                     );
  932.  
  933.             $data $this->_request(URL_RECYCLE_DELETE_DIR$param);
  934.  
  935.             return $data;
  936.         }
  937.         else
  938.         {
  939.             return false;
  940.         }
  941.     }
  942.  
  943.  
  944.  
  945.     /**
  946.      * 从回收站中还原一个文件
  947.      *
  948.      * @param int $fid 文件id
  949.      *
  950.      * @return array 
  951.      *
  952.      * @author Bruce Chen
  953.      *
  954.      */
  955.     public function restore_file($fid)
  956.     {
  957.         if($this->token)
  958.         {
  959.             $param = array(
  960.  
  961.                     'token' => $this->token,
  962.                     'fid' => $fid
  963.                     );
  964.  
  965.             $data $this->_request(URL_RECYCLE_RESTORE_FILE$param);
  966.  
  967.             return $data;
  968.         }
  969.         else
  970.         {
  971.             return false;
  972.         }
  973.     }
  974.  
  975.  
  976.     /**
  977.      * 从回收站中还原一个目录
  978.      *
  979.      * @param int $dir_id 目录的id
  980.      *
  981.      * @return array 
  982.      *
  983.      * @author Bruce Chen
  984.      *
  985.      */
  986.     public function restore_dir($dir_id)
  987.     {
  988.         if($this->token)
  989.         {
  990.             $param = array(
  991.  
  992.                     'token' => $this->token,
  993.                     'dir_id' => $dir_id
  994.                     );
  995.  
  996.             $data $this->_request(URL_RECYCLE_RESTORE_DIR$param);
  997.  
  998.             return $data;
  999.         }
  1000.         else
  1001.         {
  1002.             return false;
  1003.         }
  1004.     }
  1005.  
  1006.     /**
  1007.      * 通过路径得到目录
  1008.      *
  1009.      * @param string $path 路径
  1010.      *
  1011.      * @return array 
  1012.      *
  1013.      * @author Bruce Chen
  1014.      *
  1015.      */
  1016.     public function get_dirid_with_path($path)
  1017.     {
  1018.         if($this->token)
  1019.         {
  1020.             $param = array(
  1021.  
  1022.                     'token' => $this->token,
  1023.                     'path' => $path
  1024.                     );
  1025.  
  1026.             $data $this->_request(URL_GET_DIRID_WITH_PATH$param);
  1027.  
  1028.             return $data;
  1029.         }
  1030.         else
  1031.         {
  1032.             return false;
  1033.         }
  1034.     }
  1035.  
  1036.  
  1037.     /**
  1038.      * 通过邮件发送文件链接
  1039.      *
  1040.      * @param int $fid
  1041.      * @param string $to_email
  1042.      *
  1043.      * @return array 
  1044.      *
  1045.      * @author Bruce Chen
  1046.      *
  1047.      */
  1048.     public function email_share_file($fid, $to_email)
  1049.     {
  1050.         if($this->token)
  1051.         {
  1052.             $param = array(
  1053.  
  1054.                     'token' => $this->token,
  1055.                     'fid' => $fid,
  1056.                     'to_email' => $to_email
  1057.                     );
  1058.  
  1059.             $data $this->_request(URL_EMAIL_SHARE_FILE$param);
  1060.  
  1061.             return $data;
  1062.         }
  1063.         else
  1064.         {
  1065.             return false;
  1066.         }
  1067.     }
  1068.  
  1069.  
  1070.     /**
  1071.      * 发送http请求, 兼容SEA的Fetchurl, 私有方法
  1072.      *
  1073.      * @param string $url 
  1074.      * @param array $array  POST DATA ($array=null为GET方式)
  1075.      *
  1076.      * @return array 
  1077.      *
  1078.      * @author Bruce Chen
  1079.      *
  1080.      */
  1081.     private function _request($url, $array=null)
  1082.     {
  1083.         $curl = curl_init();
  1084.         curl_setopt($curl, CURLOPT_URL, $url);
  1085.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  1086.         if($array != null)
  1087.         {
  1088.             curl_setopt($curl, CURLOPT_POST, true);
  1089.             curl_setopt($curl, CURLOPT_POSTFIELDS, $array);
  1090.         }
  1091.         $data = curl_exec($curl);
  1092.         curl_close($curl);
  1093.         if($arr = json_decode($data, true))
  1094.         {    
  1095.             $this->set_error($arr['err_code']$arr['err_msg']);
  1096.             return $arr;
  1097.         }
  1098.         else
  1099.         {
  1100.             $this->set_error(-1'empty');
  1101.             return false;
  1102.         }
  1103.     }
  1104.  
  1105.     /**
  1106.      * 返回SaeFetchurl object, 保证只new一次
  1107.      *
  1108.      * @return SaeFetchurl object 
  1109.      *
  1110.      * @author Bruce Chen
  1111.      *
  1112.      */
  1113.     private function _f()
  1114.     {
  1115.         if(!isset($this->_f)) 
  1116.             $this->_f new SaeFetchurl();
  1117.  
  1118.         return $this->_f;
  1119.     }
  1120.  
  1121.  
  1122.     private function set_error($errno, $error) 
  1123.     {
  1124.         $this->_errno $errno;
  1125.         $this->_error $error;    
  1126.     }
  1127.  
  1128.     public function errno() 
  1129.     {
  1130.         return $this->_errno;    
  1131.     }
  1132.  
  1133.     public function error() 
  1134.     {
  1135.         return $this->_error;
  1136.     }

Documentation generated on Wed, 03 Sep 2014 10:15:05 +0800 by phpDocumentor 1.4.3