old mode 100644
new mode 100755
| | |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Text; |
| | | using Shared.Phone.UserCenter.Abount; |
| | | |
| | | namespace Shared.Common |
| | | { |
| | | public class CommonPage : FrameLayout |
| | | public class CommonPage : UIDrawerLayout |
| | | { |
| | | static CommonPage commonPage; |
| | | public static CommonPage Instance |
| | |
| | | public static Loading Loading = new Loading(); |
| | | public void Show() |
| | | { |
| | | //if (Application.IsPad) |
| | | //{ |
| | | // Application.DesignWidth = 2048; |
| | | // Application.DesignHeight = 1536; |
| | | // Pad.MainPage.Instance .Show(); |
| | | // } |
| | | //else |
| | | //{ |
| | | Application.DesignWidth = 1080; |
| | | Application.DesignHeight = 1920; |
| | | Application.MainPage.AddChidren(this); |
| | | AddChidren(Phone.UserView.HomePage.Instance); |
| | | Application.MainPage.AddChidren(Loading); |
| | | //} |
| | | |
| | | Phone.UserView.HomePage.Instance.InitPage(); |
| | | } |
| | | |
| | | public static string SoftTitle = "ZigBee"; |
| | | /// <summary> |
| | | /// 短信模板编号 |
| | | /// </summary> |
| | | public static int SoftSmsType = 0; |
| | | public static string LogoString = @"Logo/Logo.png"; |
| | | public static string RegisterLogoString = @"Logo/Register_logo.png"; |
| | | public static string RequestHttpsHost = "https://global.hdlcontrol.com/HangZhouHdlCloudApi"; |
| | | //public static string RequestHttpsHost = "http://172.16.2.225:13061"; |
| | | //public static string RequestHttpsHost = "https://global.hdlcontrol.com/HangZhouHdlCloudApi"; |
| | | public static string RequestHttpsHost = "https://global.hdlcontrol.com/ProposedProductionApi"; |
| | | /// <summary> |
| | | /// 版本号 |
| | | /// </summary> |
| | | public static string CodeIDString = "1.0.19071001"; |
| | | public static string CodeIDString = "1.1.0120070302"; |
| | | /// <summary> |
| | | /// 注册来源(0:HDL On 1:Zigbee) |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 请求版本号 |
| | | /// </summary> |
| | | public static string RequestVersion = "1.0"; |
| | | public static string RequestVersion = "2.0"; |
| | | /// <summary> |
| | | /// 左边距离屏幕的宽度--50 |
| | | /// 左边距离屏幕的宽度--58 |
| | | /// </summary> |
| | | public static int XLeft = 50; |
| | | /// <summary> |
| | | /// button高度--110 |
| | | /// </summary> |
| | | public static int ButtonHeight = 110; |
| | | public static int XLeft = 58; |
| | | /// <summary> |
| | | /// 使用的语言 |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 大控件圆角 --- 10。不是不半圆那种。 |
| | | /// </summary> |
| | | public static uint BigFormRadius = 10; |
| | | /// <summary> |
| | | /// 默认手机区号为86中国大陆 |
| | | /// </summary> |
| | | public static string PhoneZoneStr = "86"; |
| | | /// <summary> |
| | | /// 手机区名称 |
| | | /// </summary> |
| | | public static string ZoneNameStr = "中国大陆"; |
| | | /// <summary> |
| | | /// 距离顶端高度--80 状态栏高度 |
| | | /// </summary> |
| | | public static int NavigationTitle_Y = 80; |
| | | /// <summary> |
| | | /// 行高--180 |
| | | /// </summary> |
| | | public static int RowHeight = 180; |
| | | /// <summary> |
| | | /// APP宽度 -- 1080 |
| | | /// </summary> |
| | | public static int AppRealWidth = 1080; |
| | | /// <summary> |
| | | /// APP高度 -- 1920 |
| | | /// </summary> |
| | | public static int AppRealHeight = 1920; |
| | | /// <summary> |
| | | /// 返回键距离左边的距离 30 |
| | | /// </summary> |
| | | public static int Navigation_X = 30; |
| | | /// <summary> |
| | | /// 导航栏高度-220 |
| | | /// </summary> |
| | | public static int Navigation_Height = 220; |
| | | /// <summary> |
| | | /// 底边栏高度 160 |
| | | /// </summary> |
| | | public static int TabbarHeight = 160; |
| | | /// <summary> |
| | | /// 线条的高度--实际像素3 |
| | | /// </summary> |
| | | public static int LineHeight = 3; |
| | | /// <summary> |
| | | /// 整个场景延时时间--60秒 |
| | | /// </summary> |
| | | public static int SceneDelayTime = 60; |
| | | |
| | | /// <summary> |
| | | /// 间隔多长时间读取设备状态 单位 秒 --默认30 |
| | | /// </summary> |
| | | public static int ReadDeviceStatuSpan = 30; |
| | | /// <summary> |
| | | /// 读取多少页--999 |
| | | /// </summary> |
| | | public static int PageSize = 999; |
| | | |
| | | /// <summary> |
| | | /// 用于中国大陆验证手机号正则表达式 |
| | | /// 等同于--- "^[1]+\\d{10}" |
| | | /// </summary> |
| | | public static string PhoneRegexStr = "^[1]+[0,1,2,3,4,5,6,7,8,9]+\\d{9}"; |
| | | public static string PhoneRegexStr = "^[1][0-9]{10}$"; |
| | | /// <summary> |
| | | /// 用于验证非中国大陆手机号正则表达式 |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | public static string EmailRegexStr = "^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$"; |
| | | /// <summary> |
| | | /// 下载安卓apk的byte长度 |
| | | /// </summary> |
| | | public static long ApkBytesTotalLength = 0; |
| | | |
| | | //public static Encoding EncodingUTF8 = Encoding.UTF8; |
| | | //public static Encoding EncodingGB2312 = Encoding.GetEncoding("gb2312"); |
| | | public static bool IsRemote = false; |
| | | public static bool FindGateway = false; |
| | | /// <summary> |
| | | /// 当前网络连接的模式 0:没有网络 1:远程连接,也叫3G,4G 2:WIFI |
| | | /// </summary> |
| | | public static int nowNetworkMode = 0; |
| | | |
| | | |
| | | /// <summary>
|
| | | /// 安卓的系统返回按键能否按下(比如在备份还原时,不能按下返回键)
|
| | | /// </summary> |
| | | public static bool BackKeyCanClick = true; |
| | | |
| | | /// <summary> |
| | | /// 请求服务器方法 |
| | |
| | | /// </summary> |
| | | /// <param name="requestUrl">请求Url</param> |
| | | /// <param name="byteData">请求的的数据</param> |
| | | /// <param name="timeout">超时,默认10秒</param> |
| | | /// <returns>得到响应的数据</returns> |
| | | public async System.Threading.Tasks.Task<Shared.Common.ResponseEntity.ResponsePack> RequestHttpsZigbeeAsync(string requestUrl, byte[] byteData) |
| | | public ResponseEntity.ResponsePack RequestHttpsZigbeeAsync(string requestUrl, byte[] byteData, int timeout = 10) |
| | | { |
| | | string result = await this.RequestHttpsZigbeeResultAsync(requestUrl, byteData); |
| | | string result = this.RequestHttpsZigbeeResultAsync(requestUrl, byteData, timeout); |
| | | if (result != null) |
| | | { |
| | | try |
| | |
| | | /// </summary> |
| | | /// <param name="requestUrl">请求Url</param> |
| | | /// <param name="byteData">请求的的数据</param> |
| | | /// <param name="timeout">超时,默认10秒</param> |
| | | /// <returns>得到响应的数据</returns> |
| | | public async System.Threading.Tasks.Task<string> RequestHttpsZigbeeResultAsync(string requestUrl, byte[] byteData) |
| | | public string RequestHttpsZigbeeResultAsync(string requestUrl, byte[] byteData, int timeout = 10) |
| | | { |
| | | var result = await RequestHttpsZigbeeBytesResultAsync(requestUrl, byteData); |
| | | if (result != null) |
| | | { |
| | | return Encoding.UTF8.GetString(result); |
| | | var result = RequestHttpsZigbeeBytesResultAsync(requestUrl, byteData, "POST", timeout); |
| | | if (result != null)
|
| | | {
|
| | | return Encoding.UTF8.GetString(result);
|
| | | } |
| | | return null; |
| | | } |
| | |
| | | /// </summary> |
| | | /// <param name="requestUrl">请求Url</param> |
| | | /// <param name="byteData">请求的的数据</param> |
| | | /// <param name="requestMethod">POST 或者 GET 等等</param> |
| | | /// <param name="timeout">超时,默认10秒</param> |
| | | /// <returns>得到响应的数据</returns> |
| | | public async System.Threading.Tasks.Task<byte[]> RequestHttpsZigbeeBytesResultAsync(string requestUrl, byte[] byteData) |
| | | public byte[] RequestHttpsZigbeeBytesResultAsync(string requestUrl, byte[] byteData, string requestMethod = "POST", int timeout = 10) |
| | | { |
| | | //请求Url的完成路径 |
| | | var fullUrl = $"{RequestHttpsHost}/{requestUrl}"; |
| | | return this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.Token, requestMethod, timeout); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// <pra>请求服务器方法,指定一个Url,和请求方法,数据,Cookie,得到响应的数据</pra> |
| | | /// <pra>注意!!此方法仅限【拥有管理员权限的成员】调用</pra> |
| | | /// </summary>
|
| | | /// <param name="requestUrl">请求Url</param> |
| | | /// <param name="byteData">请求的的数据</param> |
| | | /// <param name="requestMethod">POST 或者 GET 等等</param> |
| | | /// <param name="timeout">超时,默认10秒</param> |
| | | /// <returns>得到响应的数据</returns> |
| | | public byte[] RequestZigbeeHttpsByAdmin(string requestUrl, byte[] byteData, string requestMethod = "POST", int timeout = 10) |
| | | {
|
| | | //请求Url的完成路径 |
| | | var fullUrl = $"{Config.Instance.AdminRequestBaseUrl}/{requestUrl}";
|
| | | return this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.AdminRequestToken, requestMethod, timeout); |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 请求服务器方法 |
| | | /// 指定一个Url,和请求方法,数据,Cookie,得到响应的数据 |
| | | /// </summary> |
| | | /// <param name="requestFullUrl">请求Url的完成路径</param> |
| | | /// <param name="byteData">请求的的数据</param> |
| | | /// <param name="token">token</param> |
| | | /// <param name="requestMethod">POST 或者 GET 等等</param> |
| | | /// <param name="timeout">超时,默认10秒</param> |
| | | /// <returns>得到响应的数据</returns> |
| | | public byte[] DoRequestZigbeeHttpsInterface(string requestFullUrl, byte[] byteData, string token, string requestMethod = "POST", int timeout = 10) |
| | | {
|
| | | try |
| | | { |
| | | //初始化新的webRequst |
| | | //1. 创建httpWebRequest对象 |
| | | HttpWebRequest webRequest = null; |
| | | if (Config.Instance.isAdministrator == true)
|
| | | {
|
| | | webRequest = (HttpWebRequest)WebRequest.Create(new Uri($"{Config.Instance.AdminRequestBaseUrl}/{requestUrl}"));
|
| | | } |
| | | else
|
| | | {
|
| | | webRequest = (HttpWebRequest)WebRequest.Create(new Uri($"{RequestHttpsHost}/{requestUrl}"));
|
| | | } |
| | | HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(requestFullUrl));
|
| | | |
| | | //2. 初始化HttpWebRequest对象 |
| | | webRequest.Method = "POST"; |
| | | webRequest.ContentType = "application/json"; |
| | | webRequest.Timeout = 10*1000; |
| | | webRequest.ContentLength = byteData.Length; |
| | | webRequest.Timeout = 10*1000; |
| | | webRequest.Headers.Add(HttpRequestHeader.Authorization, Config.Instance.Token); |
| | | //3. 附加要POST给服务器的数据到HttpWebRequest对象(附加POST数据的过程比较特殊,它并没有提供一个属性给用户存取,需要写入HttpWebRequest对象提供的一个stream里面。) |
| | | var newStream = webRequest.GetRequestStream();//创建一个Stream,赋值是写入HttpWebRequest对象提供的一个stream里面 |
| | | newStream.Write(byteData, 0, byteData.Length); |
| | | newStream.Flush(); |
| | | newStream.Close(); |
| | | webRequest.Method = requestMethod; |
| | | webRequest.Timeout = timeout * 1000; |
| | | //取消使用代理访问 |
| | | webRequest.Proxy = null; |
| | | if (token != null)
|
| | | {
|
| | | //对应微信网址
|
| | | webRequest.Headers.Add(HttpRequestHeader.Authorization, token);
|
| | | } |
| | | if (requestMethod == "GET") |
| | | { |
| | | //webRequest.ContentType = "text/html"; |
| | | webRequest.ContentType = "application/json"; |
| | | } |
| | | else |
| | | { |
| | | webRequest.ContentType = "application/json"; |
| | | webRequest.ContentLength = byteData.Length; |
| | | |
| | | //3. 附加要POST给服务器的数据到HttpWebRequest对象(附加POST数据的过程比较特殊,它并没有提供一个属性给用户存取,需要写入HttpWebRequest对象提供的一个stream里面。) |
| | | var newStream = webRequest.GetRequestStream();//创建一个Stream,赋值是写入HttpWebRequest对象提供的一个stream里面 |
| | | newStream.Write(byteData, 0, byteData.Length); |
| | | newStream.Flush(); |
| | | newStream.Close(); |
| | | } |
| | | |
| | | //4. 读取服务器的返回信息 |
| | | var response = (HttpWebResponse)webRequest.GetResponse(); |
| | | using (var stream = response.GetResponseStream()) |
| | | { |
| | | if(stream==null) |
| | | if (stream == null)
|
| | | { |
| | | return null; |
| | | } |
| | |
| | | return ms.ToArray(); |
| | | } |
| | | } |
| | | catch (WebException e) |
| | | {
|
| | | if (e.Status == WebExceptionStatus.ConnectFailure//由有网络切换到无网络时触发
|
| | | || e.Status == WebExceptionStatus.Timeout//超时
|
| | | || e.Status == WebExceptionStatus.NameResolutionFailure)//本身就是无网络时启动时触发
|
| | | {
|
| | | Phone.UserCenter.HdlWifiLogic.Current.CanAccessHttp = false;
|
| | | }
|
| | | return null;
|
| | | } |
| | | catch (Exception e) |
| | | { |
| | | System.Console.WriteLine(e.Message); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | #if iOS |
| | | /// <summary> |
| | | /// 获取iOS-APP版本信息 |
| | | /// </summary> |
| | | /// <returns>The https app version async.</returns> |
| | | public async System.Threading.Tasks.Task<ResponseEntity.ResultPack> RequestHttpsiOSAppVersionAsync() |
| | | { |
| | | try |
| | | { |
| | | var webClient = new WebClient { }; |
| | | var result = await webClient.DownloadDataTaskAsync("https://itunes.apple.com/lookup?id=1461693569"); |
| | | if (result == null) |
| | | { |
| | | return null; |
| | | } |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseEntity.ResultPack>(Encoding.UTF8.GetString(result)); |
| | | } |
| | | catch |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 跳转到APP Store |
| | | /// </summary> |
| | | public void OpenUrl() |
| | | { |
| | | Uri url = new Uri("https://itunes.apple.com/cn/app/hdl-home/id1461693569?mt=8"); |
| | | UIKit.UIApplication.SharedApplication.OpenUrl(url); |
| | | } |
| | | #elif Android |
| | | /// <summary> |
| | | /// 获取 Android-APP 版本信息 |
| | | /// </summary> |
| | | /// <returns>The https app version async.</returns> |
| | | public async System.Threading.Tasks.Task<ResponseEntity.ApkInfoOBJ> RequestHttpsAndroidAppVersionAsync() |
| | | { |
| | | try |
| | | { |
| | | var requestOBJ = new SendDataToServer.GetAndroidApkInfoOBJ |
| | | { |
| | | Name = "ZigbeeApp", |
| | | RequestVersion = CodeIDString |
| | | }; |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestOBJ); |
| | | var result = await RequestHttpsZigbeeAsync("FirmwareMana/DetectionPlatformUploadFirmware", System.Text.Encoding.UTF8.GetBytes(requestJson)); |
| | | if (result == null) |
| | | { |
| | | return null; |
| | | } |
| | | if (result.StateCode.ToUpper() == "SUCCESS") |
| | | { |
| | | if (result.ResponseData == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | var responeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseEntity.ApkInfoRes>(result.ResponseData.ToString()); |
| | | if (responeData == null || responeData.pageData == null || responeData.pageData.Count==0) |
| | | { |
| | | return null; |
| | | } |
| | | int MaxIndex = 0; |
| | | int NewID = 0; |
| | | for (int i = 0; i < responeData.pageData.Count; i++) |
| | | { |
| | | var apkInfo = responeData.pageData[i]; |
| | | if (int.Parse(apkInfo.Id) > NewID) |
| | | { |
| | | NewID = int.Parse(apkInfo.Id); |
| | | MaxIndex = i; |
| | | } |
| | | } |
| | | return responeData.pageData[MaxIndex]; |
| | | } |
| | | return null; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载安装apk |
| | | /// </summary> |
| | | /// <returns>The load apk async.</returns> |
| | | /// <param name="requestUrl">请求链接</param> |
| | | /// <param name="byteData">请求参数</param> |
| | | public System.Threading.Tasks.Task<byte[]> DownLoadApkAsync(string requestUrl, byte[] byteData) |
| | | { |
| | | try |
| | | { |
| | | AbountForm.instance.webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json"); |
| | | AbountForm.instance.webClient.Headers.Add(HttpRequestHeader.Authorization, Config.Instance.Token); |
| | | AbountForm.instance.webClient.UploadProgressChanged += Client_DownloadProgressChanged; |
| | | AbountForm.instance.webClient.UploadDataCompleted += Client_UploadCompleted; |
| | | var result = AbountForm.instance.webClient.UploadDataTaskAsync($"{RequestHttpsHost}/{requestUrl}", "POST", byteData); |
| | | if (result == null) |
| | | { |
| | | return null; |
| | | } |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return null; |
| | | } |
| | | finally |
| | | { |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// apk下载进度 |
| | | /// </summary> |
| | | /// <param name="sender">Sender.</param> |
| | | /// <param name="e">E.</param> |
| | | void Client_DownloadProgressChanged(object sender, UploadProgressChangedEventArgs e) |
| | | { |
| | | System.Console.WriteLine($"当前进度--{(int)(e.BytesReceived / (float)ApkBytesTotalLength * 100)} % --BytesReceived--{e.BytesReceived}--totalByte{e.TotalBytesToReceive}"); |
| | | if (e.BytesReceived <= ApkBytesTotalLength) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | //Loading.Start($"{(int)(e.BytesReceived / (float)ApkBytesTotalLength * 100)} %"); |
| | | AbountForm.instance.seekBar.Progress = (int)(e.BytesReceived / (float)ApkBytesTotalLength * 100); |
| | | AbountForm.instance.seekBarTitle.Text = $"{(int)(e.BytesReceived / (float)ApkBytesTotalLength * 100)}%"; |
| | | }); |
| | | } |
| | | } |
| | | void Client_UploadCompleted(object sender, UploadDataCompletedEventArgs e) |
| | | { |
| | | System.Console.WriteLine("下载apk完成"); |
| | | //Application.RunOnMainThread(Loading.Hide); |
| | | } |
| | | /// <summary> |
| | | /// 取消下载apk |
| | | /// </summary> |
| | | public static void CancelDownLoadApkAsync() |
| | | { |
| | | AbountForm.instance.webClient?.CancelAsync(); |
| | | System.Console.WriteLine("取消下载apk"); |
| | | } |
| | | |
| | | #endif |
| | | /// <summary> |
| | | /// 服务器获取数据失败提示 |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | } |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 登出
|
| | | /// </summary>
|
| | | public void SingOut()
|
| | | {
|
| | | try
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | //设定一个时间
|
| | | Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
|
| | | Config.Instance.Save();
|
| | | CommonPage.Instance.RemoveAll();
|
| | | CommonPage.Instance.Show();
|
| | | var login = new Phone.Login.AccountLoginForm();
|
| | | CommonPage.Instance.AddChidren(login);
|
| | | login.ShowForm();
|
| | | });
|
| | | }
|
| | | catch { }
|
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 登出 |
| | | /// </summary> |
| | | public void SingOut() |
| | | { |
| | | try |
| | | { |
| | | Application.RunOnMainThread( () => |
| | | { |
| | | //设定一个时间 |
| | | Config.Instance.LoginDateTime = new DateTime(1970, 1, 1); |
| | | Config.Instance.Save(); |
| | | CommonPage.Instance.RemoveAll(); |
| | | CommonPage.Instance.Show(); |
| | | var login = new Phone.Device.Account.AccountLogin(); |
| | | CommonPage.Instance.AddChidren(login); |
| | | login.Show(); |
| | | }); |
| | | } |
| | | catch { } |
| | | } |
| | | /// <summary> |
| | | /// 退出登录时调用,清除推送数据 |
| | | /// </summary> |
| | |
| | | /// 登录成功后上报设备id等相关信息给后端 |
| | | /// </summary> |
| | | /// <returns>返回状态码</returns> |
| | | public async System.Threading.Tasks.Task<string> PushRegID() |
| | | public string PushRegID() |
| | | { |
| | | try |
| | | { |
| | |
| | | DeviceType = deviceType |
| | | }; |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(RegIDObj); |
| | | var reverObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/SignZigbeeNeedPushRegID", System.Text.Encoding.UTF8.GetBytes(requestJson)); |
| | | var reverObj = CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/SignZigbeeNeedPushRegID", System.Text.Encoding.UTF8.GetBytes(requestJson)); |
| | | if (reverObj == null) |
| | | { |
| | | return null; |