BaiduYunSync/NetDisk/Credential.cs

75 lines
1.9 KiB
C#
Raw Permalink Normal View History

2017-02-05 16:11:10 +08:00
using System.Net;
namespace NetDisk
{
public class Credential
{
private string baiduid;
public string Baiduid
{
get
{
return baiduid;
}
}
private string bduss;
public string Bduss
{
get
{
return bduss;
}
}
private string stoken;
public string Stoken
{
get
{
return stoken;
}
}
private long uid;
public long Uid
{
get
{
return uid;
}
}
private string cookieString;
public Credential(string baiduid, string bduss, string stoken, long uid)
{
this.baiduid = baiduid;
this.bduss = bduss;
this.stoken = stoken;
this.uid = uid;
cookieString = "BAIDUID=" + baiduid + "; BDUSS=" + bduss + "; STOKEN=" + stoken;
}
public static implicit operator string(Credential credential)
{
return credential.cookieString;
}
public static implicit operator CookieCollection(Credential credential)
{
var c = new CookieCollection();
c.Add(new Cookie("BAIDUID", credential.baiduid, "/", ".baidu.com"));
c.Add(new Cookie("BDUSS", credential.bduss, "/", ".baidu.com"));
c.Add(new Cookie("STOKEN", credential.stoken, "/", ".pan.baidu.com"));
return c;
}
public string Serialize()
{
return baiduid + "$" + bduss + "$" + stoken + "$" + uid;
}
public static Credential Deserialize(string str)
{
var tokens = str.Split('$');
return new Credential(tokens[0], tokens[1], tokens[2], long.Parse(tokens[3]));
}
}
}