ccruiの博客

ccruiの博客

OneDrive for Business直链提取

326
2022-10-09

直链获取

原理

原链接:https://xxxx-my.sharepoint.com/:x:/g/personal/xx_xx_xx/xxxxxxxxxx

直链:https://xxxx-my.sharepoint.com/personal/xx_xx_xx/_layouts/52/download.aspx?share=xxxxxxxxxx(这一种更有效)

或:https://xxxx-my.sharepoint.com/:x:/g/personal/xx_xx_xx/xxxxxxxxxx?download=1(这是重定向跳转至直链)

建议使用第一种直链方式

C#实现

//获取xxxx-my.sharepoint.com (域名)
var domainName = Regex.Match(url, @"(?<=://)(.*?)(?=/)").Value;

//获取:x: (文件类型)
var fileType = Regex.Match(url, $"(?<=/{domainName}/:)(.*?)(?=:/)").Value;

//获取xx_xx_xx (组织名_用户名)
var organizationName = Regex.Match(url, @"(?<=/personal/)(.*?)(?=/)").Value;

//获取xxxxxxxxxx (文件ID)
var fileId = Regex.Match(url, $"(?<=/{organizationName}/).+").Value;

string newUrl = "";

if (string.IsNullOrEmpty(domainName) || string.IsNullOrEmpty(fileType) || string.IsNullOrEmpty(organizationName) || string.IsNullOrEmpty(fileId))
{
    newUrl = "请输入正确链接";
}
else if (fileType == "f")
{
    newUrl = "抱歉,你所输入链接分享的是文件夹,直链生成仅对单文件有效。";
}
else
{
    newUrl = $"https://{domainName}/personal/{organizationName}/_layouts/52/download.aspx?share={fileId}";
}

云函数

使用微软云函数,通过Get方法或Post方法进行调用

Get: https://getonedrivelink.azurewebsites.net/api/GetLink?url={url}
Post: https://getonedrivelink.azurewebsites.net/api/GetLink Body:{"url":{url}}

在线调用

https://onedrivelink.ccrui.cn/

在线调用