HDL Home App 第二版本 旧平台金堂用 正在使用
wjc
2022-12-01 351bdda734832d821a9764b0cde8be5d83c4ec50
ZigbeeApp/Shared/Common/CommonPage.cs
old mode 100755 new mode 100644
@@ -4,7 +4,7 @@
using System.Linq;
using System.Net;
using System.Text;
using Shared.Phone.UserCenter.Abount;
namespace Shared.Common
{
    public class CommonPage : UIDrawerLayout
@@ -28,21 +28,16 @@
        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();
            Phone.UserView.HomePage.Instance.InitPage();
            //设置顶部状态栏文字为黑色
            Application.SetStatusBarTextBlack(true);
        }
        //public static string RequestHttpsHost = "https://global.hdlcontrol.com/HangZhouHdlCloudApi";
@@ -50,12 +45,11 @@
        /// <summary>
        /// 版本号
        /// </summary>
        public static string CodeIDString = "1.1.0120061701";
        public static string CodeIDString = "1.1.0121070801";
        /// <summary>
        /// 注册来源(0:HDL On 1:Zigbee)
        /// </summary>
        public static int RegisterSoruceFromZIGBEE = 0;
        public static string Source = "ZIGBEE";
        /// <summary>
        /// Company 用户公司用于公司App定制版  默认0
        /// </summary>
@@ -87,17 +81,9 @@
        /// </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>
        /// 用于中国大陆验证手机号正则表达式
@@ -111,10 +97,6 @@
        /// 用于验证邮箱正则表达式
        /// </summary>
        public static string EmailRegexStr = "^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$";
        /// <summary>
        /// 当前网络连接的模式  0:没有网络  1:远程连接,也叫3G,4G  2:WIFI
        /// </summary>
        public static int nowNetworkMode = 0;
        /// <summary>
        /// 安卓的系统返回按键能否按下(比如在备份还原时,不能按下返回键)
        /// </summary>
@@ -126,10 +108,11 @@
        /// </summary>
        /// <param name="requestUrl">请求Url</param>
        /// <param name="byteData">请求的的数据</param>
        /// <param name="timeout">超时,默认5秒</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 = 5)
        {
            string result = await this.RequestHttpsZigbeeResultAsync(requestUrl, byteData);
            string result = this.RequestHttpsZigbeeResultAsync(requestUrl, byteData, timeout);
            if (result != null)
            {
                try
@@ -151,10 +134,11 @@
        /// </summary>
        /// <param name="requestUrl">请求Url</param>
        /// <param name="byteData">请求的的数据</param>
        /// <param name="timeout">超时,默认5秒</param>
        /// <returns>得到响应的数据</returns>
        public async System.Threading.Tasks.Task<string> RequestHttpsZigbeeResultAsync(string requestUrl, byte[] byteData)
        public string RequestHttpsZigbeeResultAsync(string requestUrl, byte[] byteData, int timeout = 5)
        {
            var result = await RequestHttpsZigbeeBytesResultAsync(requestUrl, byteData);
            var result = RequestHttpsZigbeeBytesResultAsync(requestUrl, byteData, "POST", timeout);
            if (result != null)
            {
                return Encoding.UTF8.GetString(result);
@@ -169,12 +153,13 @@
        /// <param name="requestUrl">请求Url</param>
        /// <param name="byteData">请求的的数据</param>
        /// <param name="requestMethod">POST 或者 GET 等等</param>
        /// <param name="timeout">超时,默认5秒</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 = 5)
        {
            //请求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>
@@ -184,13 +169,14 @@
        /// <param name="requestUrl">请求Url</param>
        /// <param name="byteData">请求的的数据</param>
        /// <param name="requestMethod">POST 或者 GET 等等</param>
        /// <param name="timeout">超时,默认5秒</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 = 5)
        {
            //请求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>
        /// 请求服务器方法
@@ -200,8 +186,9 @@
        /// <param name="byteData">请求的的数据</param>
        /// <param name="token">token</param>
        /// <param name="requestMethod">POST 或者 GET 等等</param>
        /// <param name="timeout">超时,默认5秒</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 = 5)
        {
            try
            {
@@ -211,7 +198,10 @@
                //2. 初始化HttpWebRequest对象
                webRequest.Method = requestMethod;
                webRequest.Timeout = 10 * 1000;
                webRequest.Timeout = timeout * 1000;
                //取消使用代理访问
                webRequest.Proxy = null;
                webRequest.UseDefaultCredentials = false;
                if (token != null)
                {
                    //对应微信网址
@@ -253,11 +243,18 @@
                    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;
            }
        }
@@ -359,8 +356,12 @@
        /// 登录成功后上报设备id等相关信息给后端
        /// </summary>
        /// <returns>返回状态码</returns>
        public async System.Threading.Tasks.Task<string> PushRegID()
        public string PushRegID()
        {
#if DEBUG
            //调试不需要发送这个东西
            return null;
#endif
            try
            {
                string deviceAlias;
@@ -370,8 +371,9 @@
                deviceType = "iphone";
#elif Android
                deviceAlias = Android.OS.Build.Manufacturer;
                deviceType = "android";
#endif
                deviceType = "android";
#endif
                var RegIDObj = new SendDataToServer.SignZigbeeNeedPushRegIDObj()
                {
                    RegID = Shared.Common.Config.Instance.RegistrationID,
@@ -379,11 +381,16 @@
                    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), 4);
                if (reverObj == null)
                {
                {
                    //调试:记录极光ID
                    Phone.UserCenter.HdlLogLogic.Current.WriteOtherText(Shared.Phone.UserCenter.DirNameResourse.JiguangFile, "send:" + RegIDObj.RegID + " fail,receive obj is null", false, true);
                    return null;
                }
                }
                //调试:记录极光ID
                Phone.UserCenter.HdlLogLogic.Current.WriteOtherText(Shared.Phone.UserCenter.DirNameResourse.JiguangFile, "send:" + RegIDObj.RegID + " result:" + reverObj.StateCode, false, true);
                return reverObj.StateCode;
            }
            catch