123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using PDF_Office.Properties;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Management;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- namespace PDF_Office.Helper
- {
- /// <summary>
- /// 注册登陆相关的工具类
- /// </summary>
- ///
- public static class ServiceHelper
- {
- public static bool IsLogin=false;
- public static string ALLEmail = "";
- public static string ALLPassword = "";
- public static string access_token = "";
- public static string outemail = "";
- public static string outcode = "";
- public static string outregister = "";
- public static string outlogin = "";
- public static string code = "";
- public static string okcode = "";
- public static string remsg = "";
- public static string state = "";
- public static string AppCode = "com.brother.pdfreaderprofree.windows";
- public static string RequestHost = "http://139.196.160.101:8081";
- //验证邮箱
- public static string OKemailUrl = "/pdf-office-sso/auth/validUser";
- //验证验证码
- public static string OKcodeUrl = "/pdf-office-sso/auth/isEmailCodeValid";
- //发送验证码
- public static string GetcodeUrl = "/pdf-office-sso/auth/getVerifyCode";
- //注册邮箱
- public static string registerUrl = "/pdf-office-sso/auth/emailRegister";
- //登录
- public static string LoginUrl = "/pdf-office-sso/auth/emailLogin";
- //登出
- public static string LogoutUrl = "/pdf-office-sso/user/logout";
- //注销
- public static string UseroutUrl = "/pdf-office-sso/user/logOffForUser";
- //重置密码
- public static string RebirthUrl = "/pdf-office-sso/auth/resetPassword";
- //获取用户信息
- public static string GetUserUrl = "/pdf-office-sso/user/me";
- private static string computerInfo;
- /// <summary>
- /// 电脑品牌信息
- /// </summary>
- public static string ComputerInfo
- {
- get {
- if (computerInfo == null)
- {
- computerInfo = GetComputerInfo();
- }
- return computerInfo;
-
- }
- set { computerInfo = value; }
- }
- private static string systemInfo;
- /// <summary>
- /// 系统信息
- /// </summary>
- public static string SystemInfo
- {
- get
- {
- if (systemInfo == null)
- {
- systemInfo = GetSystemInfo();
- }
- return systemInfo;
- }
- set { systemInfo = value; }
- }
- private static string GetSystemInfo()
- {
- try
- {
- string s = "";
- SelectQuery sq = new SelectQuery("Win32_OperatingSystem");
- ManagementObjectSearcher mos = new ManagementObjectSearcher(sq);
- ManagementObjectCollection moc = mos.Get();
- foreach (ManagementObject mo in moc)
- {
- s = mo.Properties["Version"].Value.ToString();
- }
- moc.Dispose();
- sq = null;
- return s;
- }
- catch { return ""; }
- }
- private static string GetComputerInfo()
- {
- try
- {
- string s = "";
- System.Windows.Controls.TextBox text = new System.Windows.Controls.TextBox();
- SelectQuery sq = new SelectQuery("Win32_ComputerSystem");
- ManagementObjectSearcher mos = new ManagementObjectSearcher(sq);
- ManagementObjectCollection moc = mos.Get();
- foreach (ManagementObject mo in moc)
- {
- s = mo.Properties["Manufacturer"].Value + " " + mo.Properties["Model"].Value;
- }
- moc.Dispose();
- sq = null;
- return s;
- }
- catch { return ""; }
- }
- //超时同步为20秒
- public static String GetUser()
- {
-
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + GetUserUrl+"");
- request.Method = "Get";
- request.Headers.Add("Authorization", $"Bearer {Settings.Default.AppProperties.LoginToken}");
- request.ContentType = "text/html;charset=UTF-8";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- JToken jToken;
- if(jobject.TryGetValue("msg" ,out jToken)==false)
- {
- App.IsLogin = true;
- return jobject["email"].ToObject<string>().ToLower();
- }
- else
- {
- return "false";
- }
- }
- }
- catch
- {
- return "网络不稳定请重试";
- }
-
-
-
- }
- public static String Ok_email(string intemail,string validType)
- {
-
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + OKemailUrl);
- request.Method = "Post";
- request.ContentType = "application/json";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- StringWriter sw = new StringWriter();
- using (JsonWriter writer = new JsonTextWriter(sw))
- {
- writer.WriteStartObject();
- writer.WritePropertyName("appId");
- writer.WriteValue(16);
- writer.WritePropertyName("platformType");
- writer.WriteValue(0);
- writer.WritePropertyName("username");
- writer.WriteValue(intemail);
- writer.WritePropertyName("validType");
- writer.WriteValue(validType);
- writer.WriteEndObject();
- }
- string postBody = sw.ToString();
- using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
- {
- writer.Write(postBody);
- writer.Close();
- }
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- //outemail = jobject["msg"].ToObject<string>().ToLower();
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- return jobject["msg"].ToObject<string>().ToLower();
- }
- }
- catch
- {
- return "网络不稳定请重试";
- }
-
- }
- //⑤报错
- public static void Get_code(string action, string email)
- {
- string post = $"?action={action}&appId=16&receiver={email}&type=0";
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + GetcodeUrl + post);
- request.Method = "Get";
- request.ContentType = "text/html;charset=UTF-8";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- }
- }
- catch
- {
-
- }
-
- }
- public static String Ok_code(string email, string code, string type)
- {
-
- string post = $"?account={email}&code={code}&type={type}&appId=16";
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + OKcodeUrl + post);
- request.Method = "Get";
- request.ContentType = "text/html;charset=UTF-8";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- return jobject["msg"].ToObject<string>().ToLower();
- }
- }
- catch
- {
- return "网络不稳定请重试";
- }
-
- }
- public static String Register_email(string intemail, string intpassword, string intcode, string uuid)
- {
-
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + registerUrl);
- request.Method = "Post";
- request.ContentType = "application/json";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- StringWriter sw = new StringWriter();
- using (JsonWriter writer = new JsonTextWriter(sw))
- {
- writer.WriteStartObject();
- writer.WritePropertyName("appId");
- writer.WriteValue(16);
- writer.WritePropertyName("deviceSign");
- writer.WriteValue(uuid);
- writer.WritePropertyName("password");
- writer.WriteValue(intpassword);
- writer.WritePropertyName("platformType");
- writer.WriteValue(0);
- writer.WritePropertyName("username");
- writer.WriteValue(intemail);
- writer.WritePropertyName("verifyCode");
- writer.WriteValue(intcode);
- writer.WriteEndObject();
- }
- string postBody = sw.ToString();
- using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
- {
- writer.Write(postBody);
- writer.Close();
- }
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- if (jobject["msg"].ToObject<string>().ToLower() == "success")
- {
- App.IsLogin =true;
- access_token = jobject["result"]["access_token"].ToObject<string>().ToLower();
- Settings.Default.AppProperties.LoginToken = jobject["result"]["access_token"].ToObject<string>().ToLower();
- Settings.Default.Save();
- }
- return jobject["msg"].ToObject<string>().ToLower();
- }
- }
- catch
- {
- return "网络不稳定请重试";
- }
-
- }
- public static String Login(string intemail, string intpassword, string uuid)
- {
-
- string postBody = $"?appId=16&deviceSign={uuid}&email={intemail}&password={intpassword}&platformType=0";
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + LoginUrl + postBody);
- request.Method = "Post";
- request.ContentType = "application/x-www-form-urlencoded";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- outlogin = jobject["msg"].ToObject<string>().ToLower();
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- if (jobject["msg"].ToObject<string>().ToLower() == "success")
- {
- App.IsLogin = true;
- access_token = jobject["result"]["access_token"].ToObject<string>().ToLower();
- Settings.Default.AppProperties.LoginToken = jobject["result"]["access_token"].ToObject<string>().ToLower();
- Settings.Default.Save();
- }
- return jobject["msg"].ToObject<string>().ToLower();
- }
- }
- catch
- {
- return "网络不稳定请重试";
- }
-
- }
- //⑤报错
- public static void Logout(string uuid)
- {
-
- string postBody = $"?deviceSign={uuid}&appId=16";
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + LogoutUrl + postBody);
- request.Method = "Post";
- request.Headers.Add("Authorization", $"Bearer {Settings.Default.AppProperties.LoginToken}");
- request.ContentType = "application/x-www-form-urlencoded";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- App.IsLogin = false;
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- }
- }
- catch
- {
-
- }
-
- }
- public static String Usergout(string code)
- {
-
- string postBody = $"?code={code}";
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + UseroutUrl + postBody);
- request.Method = "Post";
- request.Headers.Add("Authorization", $"Bearer {Settings.Default.AppProperties.LoginToken}");
- request.ContentType = "application/x-www-form-urlencoded";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- return jobject["msg"].ToObject<string>().ToLower();
- }
- }
- catch
- {
- return "网络不稳定请重试";
- }
-
- }
- public static String Rebirth(string intemail, string firstpassword, string secondPassword, string intcode)
- {
-
- HttpWebResponse response = null;
- ServicePointManager.DefaultConnectionLimit = 200;
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestHost + RebirthUrl);
- request.Method = "Post";
- request.ContentType = "application/json";
- //request.Accept = "application/vnd.api+json;version=1";
- request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
- request.Timeout = 20000;
- request.ServicePoint.Expect100Continue = false;
- StringWriter sw = new StringWriter();
- using (JsonWriter writer = new JsonTextWriter(sw))
- {
- writer.WriteStartObject();
- writer.WritePropertyName("account");
- writer.WriteValue(intemail);
- writer.WritePropertyName("appId");
- writer.WriteValue(16);
- writer.WritePropertyName("firstPassword");
- writer.WriteValue(firstpassword);
- writer.WritePropertyName("platformType");
- writer.WriteValue(0);
- writer.WritePropertyName("secondPassword");
- writer.WriteValue(secondPassword);
- writer.WritePropertyName("verifyCode");
- writer.WriteValue(intcode);
- writer.WriteEndObject();
- }
- string postBody = sw.ToString();
- using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
- {
- writer.Write(postBody);
- writer.Close();
- }
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- string responseData = reader.ReadToEnd();
- Console.WriteLine(responseData);
- reader.Close();
- JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- return jobject["msg"].ToObject<string>().ToLower();
- }
- }
- catch
- {
- return "网络不稳定请重试";
- }
-
- }
-
- }
- }
|