|
// 获取 账号游戏数据
private async Task<string> recover(string token)
{
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("channel", channel);
headers.Add("token", token);
headers.Add("version", "9.9.9");
HttpClient client = new HttpClient();
StringContent stringContent = new StringContent("data=" + Encrypt(JsonConvert.SerializeObject(headers)), Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage resp = await client.PostAsync(addr + "/recover", stringContent);
string str = await resp.Content.ReadAsStringAsync();
string ret = Decrypt(str);
if (ret.Contains("archive"))
{
JObject jobj = JObject.Parse(ret);
byte[] buff = Convert.FromBase64String(jobj["archive"].ToString());
MemoryStream _in = new MemoryStream(buff);
MemoryStream _out = new MemoryStream();
GZip.Decompress(_in, _out,false);
return Encoding.UTF8.GetString(_out.ToArray());
}
return ret;
}
// 请求 保存存档
private async Task<string> save(string token,string archive)
{
MemoryStream _in = new MemoryStream(Encoding.UTF8.GetBytes(archive));
MemoryStream _out = new MemoryStream();
GZip.Compress(_in, _out, false);
archive = Convert.ToBase64String(_out.ToArray());
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("channel", channel);
headers.Add("token", token);
headers.Add("version", version);
headers.Add("archive", archive);
HttpClient client = new HttpClient();
StringContent stringContent = new StringContent("data=" + Encrypt(JsonConvert.SerializeObject(headers)), Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage resp = await client.PostAsync(addr + "/save", stringContent);
string str = await resp.Content.ReadAsStringAsync();
string ret = Decrypt(str);
if (ret.Contains("succeed\":true"))
{
return "存档成功";
}
return ret;
}
//用到的加解密算法
private string Encrypt(string str)
{
byte[] data = Encoding.UTF8.GetBytes(str);
byte[] key = Encoding.UTF8.GetBytes("doqmjeqwcad");
Tool.exor(data, key);
return HttpUtility.UrlEncode(Convert.ToBase64String(data, Base64FormattingOptions.InsertLineBreaks));
}
public string Decrypt(string str)
{
byte[] data = Convert.FromBase64String(str);
byte[] key = Encoding.UTF8.GetBytes("doqmjeqwcad");
Tool.exor(data, key);
return Encoding.UTF8.GetString(data);
}
|
|