Index.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace addons\alioss\controller;
  3. use app\common\model\Attachment;
  4. use think\addons\Controller;
  5. /**
  6. * Ucloud
  7. *
  8. */
  9. class Index extends Controller
  10. {
  11. public function index()
  12. {
  13. $this->error("当前插件暂无前台页面");
  14. }
  15. public function params()
  16. {
  17. $name = $this->request->post('name');
  18. $md5 = $this->request->post('md5');
  19. $auth = new \addons\alioss\library\Auth();
  20. $params = $auth->params($name, $md5);
  21. $this->success('', null, $params);
  22. return;
  23. }
  24. public function notify()
  25. {
  26. $size = $this->request->post('size');
  27. $name = $this->request->post('name');
  28. $md5 = $this->request->post('md5');
  29. $type = $this->request->post('type');
  30. $signature = $this->request->post('signature');
  31. $policy = $this->request->post('policy');
  32. $url = $this->request->post('url');
  33. $suffix = substr($name, stripos($name, '.') + 1);
  34. $auth = new \addons\alioss\library\Auth();
  35. if ($auth->check($signature, $policy))
  36. {
  37. $attachment = Attachment::getBySha1($md5);
  38. if (!$attachment)
  39. {
  40. $params = array(
  41. 'filesize' => $size,
  42. 'imagewidth' => 0,
  43. 'imageheight' => 0,
  44. 'imagetype' => $suffix,
  45. 'imageframes' => 0,
  46. 'mimetype' => $type,
  47. 'url' => $url,
  48. 'uploadtime' => time(),
  49. 'storage' => 'alioss',
  50. 'sha1' => $md5,
  51. );
  52. Attachment::create($params);
  53. }
  54. $this->success();
  55. }
  56. else
  57. {
  58. $this->error(__('You have no permission'));
  59. }
  60. return;
  61. }
  62. }