| | |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Text; |
| | | using Shared.Phone.UserCenter.Abount; |
| | | |
| | | namespace Shared.Common |
| | | { |
| | | public class CommonPage : UIDrawerLayout |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | /// <summary> |
| | | /// 版本号 |
| | | /// </summary> |
| | | public static string CodeIDString = "1.1.0120062401"; |
| | | public static string CodeIDString = "1.1.0120070302"; |
| | | /// <summary> |
| | | /// 注册来源(0:HDL On 1:Zigbee) |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | public static string PhoneZoneStr = "86"; |
| | | /// <summary> |
| | | /// 手机区名称 |
| | | /// </summary> |
| | | public static string ZoneNameStr = "中国大陆"; |
| | | /// <summary> |
| | | /// APP宽度 -- 1080 |
| | | /// </summary> |
| | | public static int AppRealWidth = 1080; |
| | | /// <summary> |
| | | /// 读取多少页--999 |
| | | /// </summary> |
| | | public static int PageSize = 999; |
| | | |
| | | /// <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); |
| | | var result = RequestHttpsZigbeeBytesResultAsync(requestUrl, byteData, "POST", timeout); |
| | | if (result != null)
|
| | | {
|
| | | return Encoding.UTF8.GetString(result);
|
| | |
| | | /// <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, string requestMethod = "POST") |
| | | public byte[] RequestHttpsZigbeeBytesResultAsync(string requestUrl, byte[] byteData, string requestMethod = "POST", int timeout = 10) |
| | | { |
| | | //请求Url的完成路径 |
| | | var fullUrl = $"{RequestHttpsHost}/{requestUrl}"; |
| | | return await this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.Token, requestMethod); |
| | | return this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.Token, requestMethod, timeout); |
| | | } |
| | | |
| | | /// <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[]> RequestZigbeeHttpsByAdmin(string requestUrl, byte[] byteData, string requestMethod = "POST") |
| | | public byte[] RequestZigbeeHttpsByAdmin(string requestUrl, byte[] byteData, string requestMethod = "POST", int timeout = 10) |
| | | {
|
| | | //请求Url的完成路径 |
| | | var fullUrl = $"{Config.Instance.AdminRequestBaseUrl}/{requestUrl}";
|
| | | return await this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.AdminRequestToken, requestMethod); |
| | | } |
| | | return this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.AdminRequestToken, requestMethod, timeout); |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 请求服务器方法 |
| | |
| | | /// <param name="byteData">请求的的数据</param> |
| | | /// <param name="token">token</param> |
| | | /// <param name="requestMethod">POST 或者 GET 等等</param> |
| | | /// <param name="timeout">超时,默认10秒</param> |
| | | /// <returns>得到响应的数据</returns> |
| | | public async System.Threading.Tasks.Task<byte[]> DoRequestZigbeeHttpsInterface(string requestFullUrl, byte[] byteData, string token, string requestMethod = "POST") |
| | | public byte[] DoRequestZigbeeHttpsInterface(string requestFullUrl, byte[] byteData, string token, string requestMethod = "POST", int timeout = 10) |
| | | {
|
| | | try |
| | | { |
| | |
| | | |
| | | //2. 初始化HttpWebRequest对象 |
| | | webRequest.Method = requestMethod; |
| | | webRequest.Timeout = 10 * 1000; |
| | | webRequest.Timeout = timeout * 1000; |
| | | //取消使用代理访问 |
| | | webRequest.Proxy = null; |
| | | if (token != null)
|
| | | {
|
| | | //对应微信网址
|
| | |
| | | return ms.ToArray(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | catch (WebException e) |
| | | {
|
| | | #if DEBUG |
| | | System.Console.WriteLine(e.Message);
|
| | | #endif |
| | | if (e.Status == WebExceptionStatus.ConnectFailure//由有网络切换到无网络时触发
|
| | | || e.Status == WebExceptionStatus.Timeout//超时
|
| | | || e.Status == WebExceptionStatus.NameResolutionFailure)//本身就是无网络时启动时触发
|
| | | {
|
| | | Phone.UserCenter.HdlWifiLogic.Current.CanAccessHttp = false;
|
| | | }
|
| | | return null;
|
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | |
| | | /// 登录成功后上报设备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; |