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