onlyoffice协作页面里有个文档下载地址,这个地址是第一个人打开这个文档的时候,服务器会根据这个文档地址,将文档管理服务器里的文档下载到onlyoffice document server的内存中,第二个人打开就直接用key打开了……
问题是,这个文档地址,如何确权呢,因为onlyoffice在请求这个地址的时候,估计请求头里没有带sessionid,所以即使用户登录了,文档无服务器端也无法取得用户的登录信息。
将这个文档地址,带上sessionid就行了。
"document": {
"fileType": "{{.fileType}}",
"key": "{{.Key}}",//"Khirz6zTPdfd7"
"title": "{{.Doc.FileName}}",
"url": "http://192.168.99.1/attachment/onlyoffice/{{.Doc.FileName}}?hotqinsessionid={{.Sessionid}}",
"info": {
这样,在文档服务器端,可以直接取得用户登录名了。
beego:
//用户登录后,服务器端将信息写入session
func (c *LoginController) LoginPost() {
if err == nil {
c.SetSession("uname", user.Username)
c.SetSession("pwd", user.Password)
…………
//浏览器请求下载文档
func (c *AttachController) Attachment() {
var useridstring string
_, _, uid, isadmin, _ := checkprodRole(c.Ctx)
// if uid != 0 {
useridstring = strconv.FormatInt(uid, 10)
//根据请求携带的sessionid获取用户登录信息
func checkprodRole(ctx *context.Context) (uname, role string, uid int64, isadmin, islogin bool) {
v := ctx.Input.CruSession.Get("uname")
当然,官方推荐的是token方式。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有