Qiniu.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | 查看图片的几个方法
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace Upload\Src;
  8. use Dever;
  9. Dever::apply('sdk/qiniu', 'upload');
  10. class Qiniu
  11. {
  12. public function callback()
  13. {
  14. $body = file_get_contents('php://input');
  15. file_put_contents(Dever::data() . "test.txt",$body);
  16. $body = json_decode($body, true);
  17. $fname = $body['filename'];
  18. $fkey = $body['fkey'];
  19. $filesize = $body['filesize'];
  20. $width = $body['width'];
  21. $height = $body['height'];
  22. $arr=array("date"=>"test");
  23. echo json_encode($arr);
  24. }
  25. public function token()
  26. {
  27. $key = Dever::input('key');
  28. $upload = Dever::db('upload/upload')->one($key);
  29. if (!$upload) {
  30. return;
  31. }
  32. $config = Dever::db('upload/yun')->one($upload['yun']);
  33. $accessKey = $config['appkey'];
  34. $secretKey = $config['appsecret'];
  35. $host = $config['host'];
  36. $auth = new \Qiniu\Auth($accessKey, $secretKey);
  37. $bucket = $upload['bucket'];
  38. $policy = array(
  39. 'callbackUrl' => Dever::url('qiniu.callback', 'upload'),
  40. 'callbackBody' => 'filename=$(fname)&fkey=$(key)&filesize=$(fsize)&width=$(imageInfo.width)&height=$(imageInfo.height)'
  41. );
  42. // 生成上传Token
  43. $token = $auth->uploadToken($bucket, null, 3600);
  44. $domain = 'http://up-z1.qiniup.com/';
  45. $ret = array('uptoken' => $token, 'domain' => $domain, 'host' => $config['host']);
  46. echo json_encode($ret);die;
  47. }
  48. }