dever 6 years ago
parent
commit
c651511aa0
1 changed files with 28 additions and 0 deletions
  1. 28 0
      src/View.php

+ 28 - 0
src/View.php

@@ -12,6 +12,34 @@ use Upload\Src\Lib\Img;
 
 class View
 {
+    public function token()
+    {
+        $key = Dever::input('key');
+        $upload = Dever::db('upload/upload')->one($key);
+        if (!$upload) {
+            return;
+        }
+        Dever::apply('sdk/qiniu', 'upload');
+        $config = Dever::db('upload/yun')->one($upload['yun']);
+        $accessKey = $config['appkey'];
+        $secretKey = $config['appsecret'];
+        $this->host = $config['host'];
+        $auth = new \Qiniu\Auth($accessKey, $secretKey);
+        $bucket = $this->config['bucket'];
+
+        $policy = array(
+            'callbackUrl' => 'http://your.domain.com/upload_verify_callback.php',
+            'callbackBody' => 'filename=$(fname)&filesize=$(fsize)'
+        );
+
+        // 生成上传Token
+        $token = $auth->uploadToken($bucket, null, 3600);
+
+        $ret = array('uptoken' => $token);
+
+        echo json_encode($ret);die;
+    }
+
     public function files()
     {
         $data = array();