| | |
| | | /// <summary> |
| | | /// 版本号 |
| | | /// </summary> |
| | | public static string CodeIDString = "1.0.19112901"; |
| | | public static string CodeIDString = "1.0.20011001"; |
| | | /// <summary> |
| | | /// 注册来源(0:HDL On 1:Zigbee) |
| | | /// </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"); |
| | |
| | | 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 NewVersion = 0; |
| | | for (int i = 0; i < responeData.pageData.Count; i++) |
| | | { |
| | | var apkInfo = responeData.pageData[i]; |
| | | var version = int.Parse(apkInfo.FirmwareVersion.Replace(".", "")); |
| | | if (version > NewVersion) |
| | | { |
| | | NewVersion = version; |
| | | 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> |