Office.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\api\controller;
  15. use app\api\BaseController;
  16. use think\facade\Db;
  17. use Firebase\JWT\JWT;
  18. class Office extends BaseController
  19. {
  20. public function view($id=0,$mode='edit')
  21. {
  22. $file = Db::name('File')->where('id',$id)->find();
  23. if(empty($file)){
  24. return view('../../base/view/common/filetemplate');
  25. }
  26. $path = $file['filepath'];
  27. $title = $file['name'];
  28. $extension = pathinfo($path, PATHINFO_EXTENSION);
  29. $filename = pathinfo($path, PATHINFO_FILENAME);
  30. $office_config = get_system_config('other');
  31. $office_config['token'] = 'secret_8JFhzy';
  32. //$directory = substr($path, 0, 16);
  33. //$key = set_salt(10).str_replace("/", "T", $directory).$filename.'.'.$extension;
  34. $key = "key".$file['audit_time']."T".$id;
  35. $domain = $_SERVER['HTTP_HOST'];
  36. $url = "http://".$domain.$path;
  37. $callbackUrl = "http://".$domain."/office.php";
  38. $admin = Db::name('Admin')->where('id',$this->uid)->find();
  39. $config = [
  40. "document" => [
  41. "url" => $url,
  42. "key" => $key,
  43. "permissions" => [
  44. "chat"=> true,
  45. "comment"=> true,
  46. "copy"=> true,
  47. "deleteCommentAuthorOnly"=> false,
  48. "download"=> true,
  49. "edit"=> true,
  50. "editCommentAuthorOnly"=> false,
  51. "fillForms"=> true,
  52. "modifyContentControl"=> true,
  53. "modifyFilter"=> true,
  54. "print"=>true,
  55. "protect"=> true,
  56. "review"=> true
  57. ]
  58. ],
  59. "editorConfig"=>[
  60. "mode" => $mode,//view,edit
  61. "forcesave"=>true,
  62. "lang"=>"zh-CN",
  63. "createUrl" => '',
  64. "customization"=>[
  65. "autosave"=>true,//是否自动保存
  66. "comments"=>false,
  67. "help"=>false
  68. ],
  69. "user" => [
  70. "id" => $admin['id'],
  71. "name" => $admin['name']
  72. ],
  73. "callbackUrl"=>$callbackUrl
  74. ]
  75. ];
  76. $token = JWT::encode($config, $office_config['token'], 'HS256'); //输出Token 默认'HS256'
  77. return View('',['token'=>$token,'key'=>$key,'office'=>$office_config,'mode'=>$mode,'domain'=>$domain,'url'=>$url,'title'=>$title,'callbackUrl'=>$callbackUrl,'admin'=>$admin]);
  78. }
  79. public function officeapps($id=0,$mode='edit')
  80. {
  81. $file = Db::name('File')->where('id',$id)->find();
  82. if(empty($file)){
  83. return view('../../base/view/common/filetemplate');
  84. }
  85. $path = $file['filepath'];
  86. $domain = $_SERVER['HTTP_HOST'];
  87. $url = "//".$domain.$path;
  88. return View('',['url'=>$url]);
  89. }
  90. }