SView Help Center
English (US)

创建发图链接

Author: sviewngts Last Updated: 2026-09-09 11:00
接口名 POST: /login-register/open-api/documents/share-url
入参:(body传值) application/json
是否必传 默认值 描述 备注
fileId 是 - 文件的唯一ID 该文件在企业看图平台内的唯一ID,可在同步文件元信息接口返回值中获取
fileScope 是 - 文件归属域,此处固定填写project 我的空间->personal 
项目空间(企业空间)->project
projectCode 是 - 该项目在外部平台的唯一编码,需提前创建项目 fileScope为project时需要传递
extParams 是 - 附加参数,通过键值对传递 扩展参数,Map 结构,可根据业务需求灵活传入。所有 key 均为可选,未传入的字段使用服务端默认值。详见下方 extParams 扩展参数说明
入参:(Header传值)
Authorization 是 - 传递AccessToken 格式:Bearer {AccessToken}
入参示例:(application/json)

 

{
    "fileId": "57d3d64aa54e4a20a1544879e1d50b6c",
    "projectCode": "7bbebe688f6b4816828a5f80204066db",
    "fileScope": "project",
    "extParams": {
        "permanent": false,
        "validDays": 30,
        "accessMode": "LOGIN_REQUIRED",
        "passwordEnabled": true,
        "password": "123456",
        "remark": "测试用",
        "commentEnabled": true,
        "downloadMode": "DIRECT",
        "downloadLimitType": "LIMITED",
        "downloadLimitCount": 10
    }
}
回参示例:(application/json)

 

{
    "code": 0,
    "msg": null,
    "data": {
        "shareUrl": "release.ngts.ai/#/external-share/ziLO_Zexz73yakBXqeR1AsaG-Owk3OLp_TqYOCF9E-I",
        "shareId": "2090026107145379841"
    },
    "ok": true
}

 

extParams 扩展参数说明
extParams 是一个 Map<String, Object> 类型的可扩展参数容器,支持以下 key。所有 key 均为可选,未传入时使用服务端默认值。后续业务新增字段只需在此 Map 中追加对应 key,无需修改接口签名。
key 类型 枚举值 / 约束 默认值 说明
permanent Boolean true / false false 是否永久有效
validDays Integer 正整数 - 有效天数(permanent=false 时必填)
accessMode String LOGIN_REQUIRED 
AUTO_GUEST
LOGIN_REQUIRED 访问模式 
LOGIN_REQUIRED --> 需要登录访问
AUTO_GUEST --> 游客模式
passwordEnabled Boolean true / false false 是否启用访问密码
游客模式下不支持(无需传递该参数)
password String 任意字符串 - 访问密码(passwordEnabled=true 时传入)
游客模式下不支持(无需传递该参数)
remark String 最多 10 字符,无空白 - 分享备注
commentEnabled Boolean true / false false 是否允许评论
downloadMode String DIRECT(直接下载)
APPROVAL_REQUIRED(申请下载)
- 下载模式
游客模式下不支持APPROVAL_REQUIRED
downloadLimitType String LIMITED / UNLIMITED UNLIMITED 下载次数策略 
UNLIMITED 不限次数(默认) 
LIMITED 限制次数
downloadLimitCount Integer 正整数 - 下载次数上限 
LIMITED 时必填 
UNLIMITED 时为空
package com.hoteam.sview.demo;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.ContentType;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 创建发图链接Demo
 * 接口:POST /login-register/open-api/documents/share-url
 * <p>
 * 成功判定:HTTP 200 且 code=0,返回data中包含shareUrl、shareId
 * 失败:HTTP 401 / 非 2xx / code!=0 / 网络异常,返回 null
 */
@Slf4j
public class CreateShareUrlHutoolDemo {

    /** 接口地址(按实际环境替换 host) */
    private static final String CREATE_SHARE_URL =
            "http://your-host/login-register/open-api/documents/share-url";

    /** AccessToken(按实际值替换,可通过 /auth/oauth2/token 接口预先获取) */
    private static final String ACCESS_TOKEN = "your_access_token";

    public static void main(String[] args) {
        // 组装扩展参数 extParams
        Map<String, Object> extParams = new HashMap<>();
        extParams.put("permanent", false);
        extParams.put("validDays", 30);
        extParams.put("accessMode", "LOGIN_REQUIRED");
        extParams.put("passwordEnabled", true);
        extParams.put("password", "123456");
        extParams.put("remark", "测试试用");
        extParams.put("commentEnabled", true);
        extParams.put("downloadMode", "DIRECT");
        extParams.put("downloadLimitType", "LIMITED");
        extParams.put("downloadLimitCount", 10);

        // 调用创建分享链接接口
        JSONObject result = createShareUrl(
                "57d3d64aa54e4a20a1544879e1d50b6c", // fileId 文件唯一ID
                "project",                          // fileScope 文件归属域:personal/project
                "7bbebe688f6b4816828a5f80204066db", // projectCode 该项目在外部平台的唯一编码(fileScope=project必填)
                extParams
        );

        if (result == null) {
            log.warn("创建发图链接失败");
            return;
        }
        log.info("创建发图链接成功,返回data:{}", result);
        String shareUrl = result.getStr("shareUrl");
        String shareId = result.getStr("shareId");
        log.info("分享链接:{},分享ID:{}", shareUrl, shareId);
    }

    /**
     * 创建发图分享链接
     *
     * @param fileId     文件唯一ID(必填)
     * @param fileScope  文件归属域:personal(我的空间) / project(项目空间)(必填)
     * @param projectCode 该项目在外部平台的唯一编码,fileScope=project 时必须传入(必填)
     * @param extParams  扩展参数Map(必填,允许空map传默认值)
     * @return 成功返回data节点JSONObject(shareUrl、shareId);失败返回 null
     */
    public static JSONObject createShareUrl(String fileId,
                                           String fileScope,
                                           String projectCode,
                                           Map<String, Object> extParams) {
        // 1. 参数校验
        if (StrUtil.isBlank(fileId) || StrUtil.isBlank(fileScope) || extParams == null) {
            log.warn("创建发图链接必填参数缺失:fileId={}, fileScope={}", fileId, fileScope);
            return null;
        }
        if ("project".equals(fileScope) && StrUtil.isBlank(projectCode)) {
            log.warn("fileScope为project时,projectCode不能为空");
            return null;
        }

        // 2. 组装请求体
        Map<String, Object> requestMap = new HashMap<>();
        requestMap.put("fileId", fileId);
        requestMap.put("fileScope", fileScope);
        requestMap.put("projectCode", projectCode);
        requestMap.put("extParams", extParams);
        String requestBody = JSONUtil.toJsonStr(requestMap);
        log.info("创建发图链接请求报文:{}", requestBody);

        // 3. 发起请求
        try (HttpResponse response = HttpRequest.post(CREATE_SHARE_URL)
                // 公共 Header
                .header("tenant-id", "1")
                .header("deviceId", "web")
                .header("deviceModel", "web")
                .header("deviceType", "4")
                .header("lang", "zh-CN")
                // 认证 + Content-Type
                .header(Header.AUTHORIZATION, "Bearer " + ACCESS_TOKEN)
                .header(Header.CONTENT_TYPE, ContentType.JSON.getValue())
                .body(requestBody)
                .timeout(10_000)
                .execute()) {

            int status = response.getStatus();
            String body = response.body();
            log.info("创建发图链接响应:status={}, body={}", status, body);

            // 3.1 401 认证失败
            if (status == HttpStatus.HTTP_UNAUTHORIZED) {
                log.warn("创建发图链接认证失败(401),accessToken 可能失效,body={}", body);
                return null;
            }
            // 3.2 非 2xx 或响应体为空
            if (!response.isOk() || StrUtil.isBlank(body)) {
                log.warn("创建发图链接请求失败:status={}, body={}", status, body);
                return null;
            }

            // 4. 业务字段判定:仅以 code=0 为成功
            JSONObject json = JSONUtil.parseObj(body);
            Integer code = json.getInt("code");
            if (code == null || code != 0) {
                log.warn("创建发图链接业务失败:code={}, msg={}", code, json.getStr("msg"));
                return null;
            }

            // 返回data节点(包含shareUrl、shareId)
            return json.getJSONObject("data");
        } catch (Exception e) {
            log.error("调用创建发图链接接口异常", e);
            return null;
        }
    }
}