///
///获取文件元数据///
///
[Route("v1/3rd/file/info")]
[HttpGet]public JsonResult info(string _w_signature,string_w_appid)
{var res = newJsonResult();
response_wpsModel wpsModel= newresponse_wpsModel();
userModel user= newuserModel();
user.id= "576590854";
user.name= "kls-dev";
//用户权限
user.permission= "write";
user.avatar_url= "http://XXXXX.com/图片20180813135932.jpg";
fileModel f= newfileModel();
//文件主键,要确保唯一
f.id= "id2019110609261";
f.name= "文件名.xlsx";
f.version= 1;
f.size= 200;
f.creator=user.name;
f.create_time= long.Parse(TimeHelper.GetCurrentTimestamp(false));
f.modifier=user.name;
f.modify_time=long.Parse(TimeHelper.GetCurrentTimestamp(false)) ;
//文件的云地址
f.download_url= "";
user_aclModel acl= newuser_aclModel();
acl.rename= 1;
acl.history= 1;
f.user_acl=acl;
f.watermark=newwatermarkModel();
wpsModel.file=f;
wpsModel.user=user;returnJson(wpsModel,JsonRequestBehavior.AllowGet);
}
//补充时间戳帮助类
///
/// 时间相关
///
public static class TimeHelper
{
///
/// 获取当前时间戳
///
/// 精度(毫秒)设置 true,则生成13位的时间戳;精度(秒)设置为 false,则生成10位的时间戳;默认为 true
///
public static string GetCurrentTimestamp(bool millisecond = true)
{
return DateTime.Now.ToTimestamp(millisecond);
}
///
/// 转换指定时间得到对应的时间戳
///
///
/// 精度(毫秒)设置 true,则生成13位的时间戳;精度(秒)设置为 false,则生成10位的时间戳;默认为 true
/// 返回对应的时间戳
public static string ToTimestamp(this DateTime dateTime, bool millisecond = true)
{
return dateTime.ToTimestampLong(millisecond).ToString();
}
///
/// 转换指定时间得到对应的时间戳
///
///
/// 精度(毫秒)设置 true,则生成13位的时间戳;精度(秒)设置为 false,则生成10位的时间戳;默认为 true
/// 返回对应的时间戳
public static long ToTimestampLong(this DateTime dateTime, bool millisecond = true)
{
var ts = dateTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return millisecond ? Convert.ToInt64(ts.TotalMilliseconds) : Convert.ToInt64(ts.TotalSeconds);
}
///
/// 转换指定时间戳到对应的时间
///
/// (10位或13位)时间戳
/// 返回对应的时间
public static DateTime ToDateTime(this string timestamp)
{
var tz = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
return timestamp.Length == 13
? tz.AddMilliseconds(Convert.ToInt64(timestamp))
: tz.AddSeconds(Convert.ToInt64(timestamp));
}
}