From e87985ec1dcb69beedaf9f95e8e7aba14b7c08d6 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期三, 09 十二月 2020 18:50:14 +0800 Subject: [PATCH] 2020-12-09 1.信息中心,增加下划线和点击Alter提醒详情。 --- HDL_ON/DAL/Server/HttpServerRequest.cs | 2178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 2,069 insertions(+), 109 deletions(-) diff --git a/HDL_ON/DAL/Server/HttpServerRequest.cs b/HDL_ON/DAL/Server/HttpServerRequest.cs index 258ae85..f7166f9 100644 --- a/HDL_ON/DAL/Server/HttpServerRequest.cs +++ b/HDL_ON/DAL/Server/HttpServerRequest.cs @@ -1,4 +1,10 @@ -锘縰sing Shared; +锘縰sing System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Text; +using HDL_ON.Entity; +using Newtonsoft.Json.Linq; namespace HDL_ON.DAL.Server { @@ -11,163 +17,2117 @@ "\"sss\":" + "\"" + sss + "\"" + "," + "\"xxx\":" + xxx + "," + "}"; + + 鑾峰彇杩斿洖鐨勬暟鎹� + var sss = Newtonsoft.Json.Linq.JObject.FromObject("sss"); + var xxx = homeJsonStr.GetValue("xxx").ToString(), + + + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("Id", fId); + var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + + */ + + string severAddress = "https://global.hdlcontrol.com/ProposedProductionApi"; + + public HttpServerRequest() + { + } + + /// <summary> + /// 鑾峰彇浼犳劅鍣ㄥ巻鍙叉暟鎹� + /// </summary> + /// <param name="subnetId"></param> + /// <param name="deviceId"></param> + /// <param name="bigClass"></param> + /// <param name="minClass"></param> + /// <param name="queryType"></param> + /// <param name="loopId"></param> + /// <param name="nowMonth"></param> + /// <param name="mac"></param> + /// <returns></returns> + public ResponsePack GetSensorHistory(int subnetId, int deviceId, int bigClass, int minClass, int queryType, int loopId, int nowMonth, string mac) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("SubnetID", subnetId); + d.Add("DeviceID", deviceId); + d.Add("LargeType", bigClass); + d.Add("SmallType", minClass); + d.Add("QueryType", queryType); + d.Add("loopId", loopId); + d.Add("NowMonth", nowMonth); + d.Add("MAC", DB_ResidenceData.residenceData.residenceGatewayMAC); + d.Add("LocalTimeZone", 8); + var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + return RequestHttps("https://developer.hdlcontrol.com/api/GetSensorPushHistory", jsonString, true); + + } + + //public string GetRequestResultMsg(string resultCode) + //{ + // string result = ""; + // switch (resultCode.ToUpper()) + // { + // case "USERNAMEORPWDERROR": + // result = Language.StringByID(StringId.LoginFailed_AccountOrPasswordError); + // break; + // case "ACCOUNTNOEXISTS": + // result = Language.StringByID(StringId.ACCOUNTNOEXISTS); + // break; + // case "SENDFAIL": + // result = Language.StringByID(StringId.FailedToSendVerificationCode); + // break; + // case "EXIST": + // result = Language.StringByID(StringId.AccountAlreadyUse); + // break; + // case "Self:Net_Error": + // result = Language.StringByID(StringId.NetworkAnomaly); + // break; + // } + // return result; + //} + + #region 鈻� 閫氱敤璇锋眰鎺ュ彛_______________________ + /// <summary> + /// 鏍规鐢ㄦ埛璐﹀彿鑾峰彇娉ㄥ唽鍖哄煙 鍏嶇櫥褰� // 妫�娴嬭处鍙锋槸鍚︽敞鍐屼篃鐢ㄨ繖涓帴鍙� + /// </summary> + /// <param name="account"></param> + /// <returns></returns> + public ResponsePackNew GetRegionByAccount(string account) + { + var requestJson = HttpUtil.GetSignRequestJson(new RegionByAccountObj() { account = account }); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_GetRegionByAccount, requestJson, HttpUtil.GlobalRequestHttpsHost); + } + + /// <summary> + /// 鍒锋柊Token + /// </summary> + /// <returns></returns> + public bool RefreshToken() + { + var requestJson = HttpUtil.GetSignRequestJson(new RefreshTokenObj() + { + refreshToken = UserInfo.Current.RefreshToken, + }); + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Login, requestJson); + if (revertObj.Code.ToUpper() == StateCode.SUCCESS) + { + var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes>(revertObj.Data.ToString()); + UserInfo.Current.LoginTokenString = revertData.headerPrefix + revertData.accessToken; + UserInfo.Current.RefreshToken = revertData.refreshToken; + UserInfo.Current.LastTime = DateTime.Now; + UserInfo.Current.SaveUserInfo(); + return true; + } + return false; + } + + #endregion + + #region 娉ㄥ唽銆佺櫥褰曢儴鍒� + + + /// <summary> + /// 閫氱敤 鍙戦�侀獙璇佺爜鏂规硶 + /// </summary> + /// <param name="verifyType">1:娉ㄥ唽 2锛氭壘鍥炲瘑鐮� 3锛氱粦瀹�4:楠岃瘉鐮佺櫥闄� 5:鏁忔劅鏁版嵁</param> + /// <param name="account">閭鎴栬�呮墜鏈哄彿</param> + /// <param name="isPhone">鏄惁鎵嬫満</param> + /// <param name="phoneZoneCode">鎵嬫満鍥藉鍖哄彿</param> + /// <returns></returns> + public ResponsePackNew VerificationCodeSend(VerifyType verifyType, string account, bool isPhone = false, string phoneZoneCode = "86") + { + var requestObj = new VerifyCodeSendObj() + { + verifyType = (int)verifyType, + languageType = Utlis.GetPostLanguageType() + }; + // 鏄惁鏄墜鏈� + if (isPhone) + { + requestObj.phone = account; + requestObj.phonePrefix = phoneZoneCode; + } + else + { + requestObj.mail = account; + } + // 瓒呮椂鏃堕棿璁剧疆涓�20绉掞紝搴旇娴嬭瘯娴峰鏈嶅姟鍣ㄥ彂閫侀獙璇佺爜鍝嶅簲鏃堕棿寰堜箙 + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Verification_Send, requestJson, "", "", HttpUtil.TIME_OUT_LONG); + } + /// <summary> /// 璐﹀彿鐧诲綍-浣跨敤瀵嗙爜 /// </summary> - public ResponsePack LoginByPassword(string account, string password) + /// <param name="account">璐﹀彿</param> + /// <param name="password">瀵嗙爜</param> + /// <returns></returns> + public ResponsePackNew LoginByPassword(string account, string password) { - string jsonString = "{" + - "\"Account\":" + "\"" + account + "\"" + "," + - "\"Password\":" + "\"" + password + "\"" + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/Login", jsonString, false); + var requestJson = HttpUtil.GetSignRequestJson(new LoginObj() + { + account = account, + loginPwd = password + }); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Login, requestJson); } /// <summary> - /// 鎵嬫満鍙风爜娉ㄥ唽 + /// 楠岃瘉鐮佺櫥褰� /// </summary> - /// <param name="mobileNumber"></param> - /// <param name="password"></param> - /// <param name="language"></param> - public ResponsePack RegisterPhone(string mobileNumber, string password, string language) + /// <param name="account">璐﹀彿</param> + /// <param name="vCode">楠岃瘉鐮�</param> + /// <returns></returns> + public ResponsePackNew LoginValidCode(string account, string vCode) { - string jsonString = "{" + - "\"Account\":" + "\"" + mobileNumber + "\"" + "," + - "\"Password\":" + "\"" + password + "\"" + "," + - "\"Language\":" + "\"" + language + "\"" + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/SignIn", jsonString, false); - } - - public ResponsePack GetAreaCode() - { - string requestJson = "{}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/GetAreaCode", requestJson, false); + var requestJson = HttpUtil.GetSignRequestJson(new LoginObj() + { + account = account, + verifyCode = vCode, + grantType = "verify" + }); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Login, requestJson); } /// <summary> /// 楠岃瘉鐭俊鎴栬�呴偖绠遍獙璇佺爜锛屼箣鍚庢敞鍐� /// </summary> - /// <param name="account">璐﹀彿</param> + /// <param name="account">閭鎴栬�呮墜鏈哄彿</param> /// <param name="password">瀵嗙爜</param> - /// <param name="entryPassword">纭瀵嗙爜</param> /// <param name="code">楠岃瘉鐮�</param> - /// <param name="areaCode"></param> + /// <param name="isPhone">鏄惁鎵嬫満</param> /// <returns></returns> - public ResponsePack ValidataCodeAndRegister(string account, string password, string entryPassword, string code, int areaCode) + public ResponsePackNew ValidataCodeAndRegister(string account, string password, string code, bool isPhone = false) { - //var requestObj = new ValidateSmsCodeObj() { Phone = accout, Code = code }; - //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj); - string requestJson = "{" + - "\"Account\":" + "\"" + account + "\"" + "," + - "\"Password\":" + "\"" + password + "\"" + "," + - "\"EnterPassword\":" + "\"" + entryPassword + "\"" + "," + - "\"Language\":" + "\"" + Language.CurrentLanguage + "\"" + "," + - "\"Code\":" + "\"" + code + "\"" + "," + - "\"RegisterSoruce\":" + 0 + "," + - "\"AreaCode\":" + areaCode + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/ValidataCodeAndRegisterAccount", requestJson, false); - } - - - /// <summary> - /// 鑾峰彇娉ㄥ唽楠岃瘉鐮� - /// </summary> - public ResponsePack GetPhoneRegisterVerCode(string account) - { - string jsonString = "{" + - "\"Account\":" + "\"" + account + "\"" + "," + - "\"Company\":" + MainPage.Company + "," + - "\"Language\":" + "\"" + Language.CurrentLanguage + "\"" + "," + - "\"AreaCode\":" + UserConfig.Instance.CountryNumber + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/RegisterSendVerCode", jsonString, false); - - } - - - - /// <summary> - /// 鑾峰彇鐧诲綍楠岃瘉鐮� - /// </summary> - /// <param name="phoneNum">鎵嬫満鍙风爜</param> - public ResponsePack GetPhoneLoginVerCode(string phoneNum) - { - - string jsonString = "{" + - "\"Phone\":" + "\"" + phoneNum + "\"" + "," + - "\"Company\":" + MainPage.Company + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/LoginSendVerCode", jsonString, false); + var requestObj = new RegisterObj() { loginPwd = password, verifyCode = code, memberName = account }; + if (isPhone) + { + requestObj.memberPhone = account; + } + else + { + requestObj.memberEmail = account; + } + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_Register, requestJson); } /// <summary> - /// 鍙戦�侀獙璇佺爜 + /// 蹇樿瀵嗙爜锛岄噸缃瘑鐮� /// </summary> - public ResponsePack SendSms(string account) + /// <param name="account">閭鎴栬�呮墜鏈哄彿</param> + /// <param name="password">鏂板瘑鐮�</param> + /// <param name="vCode">楠岃瘉鐮�</param> + /// <param name="isPhone">鏄惁鎵嬫満璐﹀彿</param> + /// <returns></returns> + public ResponsePackNew ForgetPassword(string account, string password, string vCode, bool isPhone) { - string jsonString = "{" + - "\"Account\":" + "\"" + account + "\"" + "," + - "\"Company\":" + MainPage.Company + "," + - "\"Language\":" + "\"" + Language.CurrentLanguage + "\"" + "," + - "\"AreaCode\":" + UserConfig.Instance.CountryNumber + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/LoginSendVerCode", jsonString, false); + var requestObj = new ForgetPwdObj() { verifyCode = vCode, loginPwd = password }; + if (isPhone) + { + //鎵嬫満蹇樿瀵嗙爜 + requestObj.memberPhone = account; + } + else + { + //閭蹇樿瀵嗙爜 + requestObj.memberEmail = account; + } + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_ForgetPwd, requestJson); } /// <summary> /// 楠岃瘉楠岃瘉鐮� /// </summary> - /// <param name="account"></param> - /// <param name="code"></param> + /// <param name="verifyType">楠岃瘉绫诲瀷</param> + /// <param name="account">楠岃瘉璐﹀彿</param> + /// <param name="code">楠岃瘉鐮�</param> + /// <param name="isPhone">鏄惁鎵嬫満</param> + /// <param name="verifySuccessFail">楠岃瘉閫氳繃鍚庯紝楠岃瘉鐮佹槸鍚﹀け鏁�</param> /// <returns></returns> - public ResponsePack ValidatorCode(string account, string code, int countryIndex) + public ResponsePackNew ValidatorCode(VerifyType verifyType, string account, string code, bool isPhone, bool verifySuccessFail = true) { - string jsonString = "{" + - "\"Account\":" + "\"" + account + "\"" + "," + - "\"Code\":" + "\"" + code + "\"" + "," + - "\"Language\":" + "\"" + Language.CurrentLanguage + "\"" + "," + - "\"AreaCode\":" + countryIndex + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/ValidatorCode", jsonString, false); + var requestObj = new VerifyCodeCheckObj() { verifyCode = code, verifyType = (int)verifyType, verifySuccessFail = verifySuccessFail }; + if (isPhone) + { + //鎵嬫満 + requestObj.phone = account; + } + else + { + //閭 + requestObj.mail = account; + } + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Verification_Check, requestJson); + } + + #endregion + + #region 涓汉淇℃伅閮ㄥ垎 + /// <summary> + /// 鑾峰彇鐢ㄦ埛淇℃伅 + /// </summary> + /// <returns></returns> + public void GetUserInfo(bool bGetHeadImage = true) + { + var requestJson = HttpUtil.GetSignRequestJson(new NullObj()); + var resultObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_GetMemberInfo, requestJson); + if (resultObj.Code == StateCode.SUCCESS) + { + var info = Newtonsoft.Json.JsonConvert.DeserializeObject<MemberInfoRes>(resultObj.Data.ToString()); + UserInfo.Current.userEmailInfo = info.memberEmail; + UserInfo.Current.userMobileInfo = info.memberPhone; + UserInfo.Current.userName = info.memberName; + if (!string.IsNullOrEmpty(info.memberPhonePrefix)) + { + UserInfo.Current.areaCode = info.memberPhonePrefix; + } + //鏄惁闇�瑕佽幏鍙栧ご鍍� + if (bGetHeadImage) + { + var imageKey = ImageUtlis.Current.GetHeadImageKey(info.memberId); + + var headImageBytes = ImageUtlis.Current.DownHeadImage(info.memberId); + + if (headImageBytes != null && headImageBytes.Length > 0) + { + //UserInfo.Current.headImagePageBytes = headImageBytes; + UserInfo.Current.headImagePagePath = imageKey; + } + } + + UserInfo.Current.SaveUserInfo(); + MainPage.Log("鑾峰彇鐢ㄦ埛淇℃伅鎴愬姛銆�"); + } + + + // Dictionary<string, object> d = new Dictionary<string, object>(); + //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d); + //var revertObj = RequestHttps($"{severAddress}/ZigbeeUsers/GetAccountInfo", requestJson, true); + + //if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) + //{ + // var dataStr = JObject.FromObject(revertObj.ResponseData); + // //"DistributedMark": "96439601-fd26-4768-8440-1d9dfa32c109", < !--甯愬彿Id-- > + // UserInfo.Current.userEmailInfo = dataStr.GetValue("Email").ToString(); + // UserInfo.Current.userMobileInfo = dataStr.GetValue("Phone").ToString(); + // FileStream fs = null; + // try + // { + // var headImageString = dataStr.GetValue("HeadImage").ToString(); + // if (!string.IsNullOrEmpty(headImageString)) + // { + // var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(headImageString); + // var headImageBytes = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]>(jsonString); + // UserInfo.Current.headImagePageBytes = headImageBytes; + // var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/", "headImage.png"); + // fs = new FileStream(filePath, FileMode.Create, FileAccess.Write); + // fs.Write(headImageBytes, 0, headImageBytes.Length); + // fs.Flush(); + // UserInfo.Current.headImagePagePath = filePath; + // } + // } + // catch (Exception ex) + // { + // MainPage.Log($"download headImage error : {ex.Message}"); + // } + // finally + // { + // if (fs != null) + // { + // fs.Close(); + // } + // } + // // "GesturePwd": null, < !--鎵嬪娍瀵嗙爜-- > + // // "StringPwd": null , < !--瀛楃涓插瘑鐮�-- > + // UserInfo.Current.userName = dataStr.GetValue("UserName").ToString(); + + // Application.RunOnMainThread(() => + // { + // }); + + // UserInfo.Current.SaveUserInfo(); + // MainPage.Log("鑾峰彇鐢ㄦ埛淇℃伅鎴愬姛銆�"); + //} + } /// <summary> - /// 閲嶈瀵嗙爜 + /// 鑾峰彇鐢ㄦ埛澶村儚 /// </summary> - /// <returns></returns> - public ResponsePack ResetPassword(string account, string password, string rePassword, int countryIndex) + /// <param name="userId"></param> + public void GetUserHeadImage(string userId) { - string jsonString = "{" + - "\"Account\":" + "\"" + account + "\"" + "," + - "\"Password\":" + "\"" + password + "\"" + "," + - "\"AgainPassword\":" + "\"" + rePassword + "\"" + "," + - "\"AreaCode\":" + countryIndex + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/ResetPassword", jsonString, false); + var imageKey = ImageUtlis.Current.GetHeadImageKey(userId); + + var headImageBytes = ImageUtlis.Current.DownHeadImage(userId); + + if (headImageBytes != null && headImageBytes.Length > 0) + { + //UserInfo.Current.headImagePageBytes = headImageBytes; + UserInfo.Current.headImagePagePath = imageKey; + } } + + /// <summary> + /// 鏇存柊鐢ㄦ埛鏄电О + /// </summary> + /// <param name="userName"></param> + /// <returns></returns> + public ResponsePackNew EditUserName(string userName) + { + var requestJson = HttpUtil.GetSignRequestJson(new UpdateMemberNameRes() + { + memberName = userName + }); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UpdateMemberInfo, requestJson); + } + + ///// <summary> + ///// 鏇存柊鐢ㄦ埛澶村儚 + ///// </summary> + ///// <param name="vs"></param> + ///// <returns></returns> + //public string UpdataUserHeadImage(string fileName) + //{ + // byte[] bytes = Shared.IO.FileUtils.ReadFile(fileName); + // var revertObj = HttpUtil.RequestHttpsUpload(RestSharp.Method.POST, NewAPI.API_POST_Head_Upload, bytes); + // return revertObj.Code; + //} + + /// <summary> + /// 鏇存敼缁戝畾璐︽埛鐨勯偖绠辨垨鑰呮墜鏈哄彿 + /// 2020-11-16 寰呬慨鏀� + /// </summary> + /// <param name="account"></param> + /// <param name="code"></param> + /// <param name="isPhone"></param> + /// <returns></returns> + public string BindAccount(string account, string code = "", bool isPhone = false) + { + var requestObj = new BindWithAccountObj() { verifyCode = code }; + if (isPhone) + { + //鎵嬫満 + requestObj.memberPhone = account; + } + else + { + //閭 + requestObj.memberEmail = account; + } + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_BindWithAccount, requestJson).Code; + } + + /// <summary> + /// 瑙g粦鎵嬫満鎴栬�呴偖绠� + /// </summary> + /// <param name="isPhone"></param> + /// <returns></returns> + public string UnBindAccount(bool isPhone) + { + var requestObj = new UnBindAccountObj() { unBindLabel = isPhone ? "PHONE" : "EMAIL" }; + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UnbindWithAccount, requestJson).Code; + } + #endregion #region 浣忓畢閮ㄥ垎 /// <summary> /// 鑾峰彇浣忓畢鍒楄〃 /// </summary> - public ResponsePack GetHomePager() + public string GetHomePager(HomeTypeEnum homeType = HomeTypeEnum.ALL) { - string jsonString = "{" + - "\"RequestVersion\":" + "\"" + MainPage.VersionString + "\"" + "," + - "\"RequestSource\":" + "\"" + "1" + "\"" + "," + - "\"HomeType\":" + "\"" + "1" + "\"" + "," + - "\"LoginAccessToken\":" + "\"" + MainPage.LoginUser.LoginTokenString + "\"" + - "}"; - return RequestHttps(@"https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetHomePager", jsonString,false); + var requestJson = HttpUtil.GetSignRequestJson(new GetHomeListObj() { homeType = homeType.ToString() }); + var resultObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Gethomepager, requestJson); + if (resultObj.Code == StateCode.SUCCESS) + { + var homeList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoResNew>>(resultObj.Data.ToString()); + if (homeList == null || homeList.Count == 0) + { + + + } + else + { + UserInfo.Current.regionList = new List<RegionInfoRes>(); + + foreach (var mHome in homeList) + { + var home = new RegionInfoRes() + { + RegionID = mHome.Id, + Name = mHome.homeName, + IsOthreShare = mHome.IsOtherShare, + accountType = mHome.accountType, + isRemoteControl = mHome.isRemoteControl, + longitude = mHome.longitude, + latitude = mHome.latitude, + deliverstatus = mHome.deliverstatus, + homeType = mHome.homeType, + regionUrl = mHome.regionUrl, + emqUrl = mHome.emqUrl, + homeRegionName = mHome.homeRegionName, + homeRegionId = mHome.homeRegionId, + Address = mHome.homeAddress, + }; + if (home.IsOthreShare) + { + continue; + } + UserInfo.Current.regionList.Add(home); + } + + if (string.IsNullOrEmpty(DB_ResidenceData.residenceData.CurReginID)) + { + DB_ResidenceData.residenceData.CurReginID = UserInfo.Current.regionList[0].RegionID; + //鎭㈠澶囦唤 + HDLCommon.Current.RestoreHomeBackup(DB_ResidenceData.residenceData.CurReginID); + } + else + { + var curRegion = UserInfo.Current.regionList.Find((obj) => obj.RegionID == DB_ResidenceData.residenceData.CurReginID); + if(curRegion == null) + { + DB_ResidenceData.residenceData.CurReginID = UserInfo.Current.regionList[0].RegionID; + //鎭㈠澶囦唤 + HDLCommon.Current.RestoreHomeBackup(DB_ResidenceData.residenceData.CurReginID); + } + } + + + DB_ResidenceData.residenceData.SaveResidenceData(); + UserInfo.Current.SaveUserInfo(); + + //鍒锋柊涓�娆′綇瀹呯綉鍏� + GetHomeGatewayList(); + } + + } + + return resultObj.Code; + + //string jsonString = "{" + + // "\"RequestVersion\":" + "\"" + MainPage.VersionString + "\"" + "," + + // "\"RequestSource\":" + "\"" + "2" + "\"" + "," + + // "\"HomeType\":" + "\"" + "1" + "\"" + "," + + // "\"LoginAccessToken\":" + "\"" + UserInfo.Current.loginTokenString + "\"" + + // "}"; + //var responsePack = RequestHttps($"{severAddress}/App/GetHomePager", jsonString, false); + + //if (responsePack.StateCode.ToUpper() == StateCode.SUCCESS_CODE) + //{ + // var dataStr = JObject.FromObject(responsePack.ResponseData); + // //娌℃湁浣忓畢 + // if (dataStr.GetValue("PageData").ToString() == "[]") + // { + + // } + // else + // { + // //{ + // // { + // // "Id": "1107487", + // // "HomeStatus": 2, + // // "UserGuid": "22980", + // // "Name": "鍟�", + // // "Address": null, + // // "Longitude": 0.0, + // // "Latitude": 0.0, + // // "RegionName": null, + // // "Company": null, + // // "ContactPerson": null, + // // "ContactPersonPhone": null, + // // "Remarks": null, + // // "ChangeDate": null, + // // "AccountType": 0, + // // "CreatedOnUtc": "2020-05-27T06:52:03", + // // "IsOthreShare": false, + // // "MainUserDistributedMark": null, + // // "HomeGateways": [ + // // { + // // "GatewayUniqueId": "4E47323347591243" + // // } + // // ] + // //}} + // UserInfo.Current.regionList = new List<RegionInfoRes>(); + // foreach (var jsonData in dataStr.GetValue("PageData")) + // { + // var homeJsonStr = JObject.FromObject(jsonData); + // var home = new RegionInfoRes() + // { + // RegionID = homeJsonStr.GetValue("Id").ToString(), + // RegionName = homeJsonStr.GetValue("RegionName").ToString(), + // Name = homeJsonStr.GetValue("Name").ToString(), + // Address = homeJsonStr.GetValue("Address").ToString(), + // IsOthreShare = (bool)homeJsonStr.GetValue("IsOthreShare"), + // homeGateways = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HomeGateways>>(homeJsonStr.GetValue("HomeGateways").ToString()), + // }; + // if (home.IsOthreShare) + // { + // continue; + // } + // UserInfo.Current.regionList.Add(home); + // if (string.IsNullOrEmpty(DB_ResidenceData.residenceData.CurReginID)) + // { + // DB_ResidenceData.residenceData.CurReginID = UserInfo.Current.regionList[0].RegionID; + // } + // } + // DB_ResidenceData.residenceData.SaveResidenceData(); + // UserInfo.Current.SaveUserInfo(); + // } + //} + //return responsePack.StateCode; + } + + /// <summary> + /// 缂栬緫浣忓畢淇℃伅 + /// </summary> + /// <param name="editId">0 淇敼浣忓畢鍚嶅瓧銆�1 淇敼浣忓畢鍦板潃</param> + /// <param name="editName"></param> + /// <returns></returns> + public ResponsePackNew EditResidenceInfo(int editId, string editName) + { + var requestObj = new AddOrUpdateHomeObj() + { + homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, + }; + + if (editId == 0) + { + requestObj.homeName = editName; + } + else if (editId == 1) + { + requestObj.Address = editName; + } + + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Home_UpdateHome, requestJson); + } + + /// <summary> + /// 鑾峰彇鍒锋柊褰撳墠浣忓畢鐨勭綉鍏冲垪琛� + /// </summary> + public void GetHomeGatewayList() + { + try + { + if (string.IsNullOrEmpty(DB_ResidenceData.residenceData.residecenInfo.RegionID)) return; + var nowhomeId = DB_ResidenceData.residenceData.residecenInfo.RegionID; + var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = nowhomeId }); + var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_GetGatewayList, requestJson); + if (revertObj.Code == StateCode.SUCCESS) + { + var mHomeGatewayRes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HomeGatewayInfo>>(revertObj.Data.ToString()); + if (nowhomeId == DB_ResidenceData.residenceData.residecenInfo.RegionID) + { + if (mHomeGatewayRes != null) + { + if (mHomeGatewayRes.Count > 0) + { + DB_ResidenceData.residenceData.HomeGateway = mHomeGatewayRes[0]; + if(mHomeGatewayRes[0].gatewayStatus == "ON_LINE") + { + DriverLayer.Control.Ins.IsRemote = true; + DriverLayer.Control.Ins.GatewayOnline = true; + } + DB_ResidenceData.residenceData.SaveResidenceData(); + return; + } + } + //鍏朵綑鎯呭喌娓呯┖缃戝叧淇℃伅 + DB_ResidenceData.residenceData.HomeGateway = null; + DB_ResidenceData.residenceData.SaveResidenceData(); + } + } + else + { + //鎻愮ず閿欒 + } + } + catch + { + + } + } + + /// <summary> + /// 鑾峰彇浣忓畢涓嬬殑鎴愬憳璐﹀彿 + /// </summary> + /// <returns></returns> + public ResponsePackNew GetResidenceMemberAccount() + { + var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID }); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_FindAll, requestJson); + } + + /// <summary> + /// 鍒犻櫎浣忓畢涓嬬殑鎴愬憳璐﹀彿 + /// </summary> + /// <returns></returns> + public ResponsePackNew DeleteResidenceMemberAccount(ResidenceMemberInfo subaccount) + { + var requestObj = new ChildDeleteObj() + { + childAccountId = subaccount.childAccountId, + homeId = subaccount.homeId + }; + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Delete, requestJson); + } + + /// <summary> + /// 淇敼瀛愯处鍙锋樀绉� + /// </summary> + /// <param name="nickName"></param> + /// <param name="subAccountGuid"></param> + /// <returns></returns> + public ResponsePackNew EditSubAccountNickName(string nickName, string childAccountId) + { + var requestJson = HttpUtil.GetSignRequestJson(new UpdateChildNickNameObj() + { + homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, + childAccountId = childAccountId, + nickName = nickName, + }); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Update, requestJson); + + } + /// <summary> + /// 淇敼瀛愯处鍙峰垱寤哄満鏅潈闄� + /// </summary> + /// <param name="nickName"></param> + /// <param name="subAccountGuid"></param> + /// <returns></returns> + public ResponsePackNew ChangeCreateSceneState(bool isAllow, string childAccountId) + { + var requestJson = HttpUtil.GetSignRequestJson(new UpdateChildAllowCreateSceneObj() + { + homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, + childAccountId = childAccountId, + isAllowCreateScene = isAllow, + }); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Update, requestJson); + } + + #region 鏂版暟鎹垎浜� + /// <summary> + /// 娣诲姞鍒嗕韩 + /// </summary> + /// <param name="addShareObj"></param> + /// <returns></returns> + public ResponsePackNew AddShareData(AddShareObj addShareObj) + { + var requestJson = HttpUtil.GetSignRequestJson(addShareObj); + + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_Add, requestJson); + } + + /// <summary> + /// 鍒犻櫎鍒嗕韩 + /// </summary> + /// <param name="deleteShareObj"></param> + /// <returns></returns> + public ResponsePackNew DeleteShareData(DeleteShareObj deleteShareObj) + { + var requestJson = HttpUtil.GetSignRequestJson(deleteShareObj); + + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_Delete, requestJson); + } + + /// <summary> + /// 鑾峰彇鍒嗕韩 + /// </summary> + /// <param name="addShareObj"></param> + /// <returns></returns> + public ResponsePackNew GetShareDataByMemberAccount(string childAccountId) + { + var requestJson = HttpUtil.GetSignRequestJson(new GetShareObj() + { + homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, + childAccountId = childAccountId, + }); + + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_GetList, requestJson); + } + #endregion + + ///// <summary> + ///// 鑾峰彇浣忓畢涓嬪瓙璐﹀彿鐨勫叡浜暟鎹垪琛� + ///// </summary> + ///// <returns></returns> + //public ResponsePackNew GetShareDataByMemberAccount(string childAccountId) + //{ + // //Dictionary<string, object> d = new Dictionary<string, object>(); + // //d.Add("DistributedMark", memberId); + // //d.Add("HouseDistributedMark", DB_ResidenceData.residenceData.residecenInfo.RegionID); + // //string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + // //return RequestHttps($"{severAddress}/ZigbeeDataShare/GetShareDataBySubAccount", jsonString, true); + + // var requestJson = HttpUtil.GetSignRequestJson(new HomeShareFindAll() + // { + // homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, + // childAccountId = childAccountId + // }); + // return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Home_Share_FindAll, requestJson); + + //} + + ///// <summary> + ///// 涓嬭浇鍗曚釜鍒嗕韩鏂囦欢 + ///// </summary> + ///// <returns></returns> + //public byte[] GetShareData(ShareData shareData) + //{ + // //Dictionary<string, object> d = new Dictionary<string, object>(); + // //d.Add("DistributedMark", memberId); + // //d.Add("HouseDistributedMark", hId); + // //string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + // //return RequestHttps($"{severAddress}/ZigbeeDataShare/GetOneShareData", jsonString, true); + + // var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(new ShareFileDownObj() + // { + // homeId = shareData.homeId, + // homeShareId = shareData.id + // }); + // var replaceToken = ""; + // if (DB_ResidenceData.residenceData.residecenInfo.IsOthreShare) + // { + // replaceToken = DB_ResidenceData.residenceData.MasterToken; + // } + // return HttpUtil.RequestHttpsDownload(NewAPI.API_POST_Home_Share_DownOne, requestJson, null, DB_ResidenceData.residenceData.residecenInfo.regionUrl, replaceToken); + + //} + + ///// <summary> + ///// 澧炲姞鍏变韩鏁版嵁鍒楄〃 + ///// </summary> + ///// <returns></returns> + //public ResponsePackNew AddShareData(ShareData shareData) + //{ + // //Dictionary<string, object> d = new Dictionary<string, object>(); + // //d.Add("ShareName", shareData.ShareName); + // //d.Add("HouseDistributedMark", shareData.HouseDistributedMark); + // //d.Add("ShareDataBytes", shareData.ShareDataBytes); + // //d.Add("SubAccountDistributedMark", shareData.SubAccountDistributedMark); + // //string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + // //return RequestHttps($"{severAddress}/ZigbeeDataShare/AddShareData", jsonString, true); + + // var queryDic = new Dictionary<string, object>(); + // queryDic.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + // queryDic.Add("childAccountId", shareData.childAccountId); + // queryDic.Add("fileName", shareData.fileName); + // var replaceToken = ""; + // if (DB_ResidenceData.residenceData.residecenInfo.IsOthreShare) + // { + // replaceToken = DB_ResidenceData.residenceData.MasterToken; + // } + // return HttpUtil.RequestHttpsUpload(RestSharp.Method.POST, NewAPI.API_POST_Home_Share_Add, shareData.ShareDataBytes, queryDic, null, DB_ResidenceData.residenceData.residecenInfo.regionUrl, replaceToken); + //} + + ///// <summary> + ///// 澧炲姞鍏变韩鏁版嵁 + ///// </summary> + ///// <returns></returns> + //public ResponsePackNew EditShareData(ShareData shareData) + //{ + // return AddShareData(shareData); + // //Dictionary<string, object> d = new Dictionary<string, object>(); + // //d.Add("DistributedMark", shareData.DistributedMark); + // //d.Add("ShareName", shareData.ShareName); + // //d.Add("HouseDistributedMark", shareData.HouseDistributedMark); + // //d.Add("ShareDataBytes", shareData.ShareDataBytes); + // //d.Add("SubAccountDistributedMark", shareData.SubAccountDistributedMark); + // //string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + // //return RequestHttps($"{severAddress}/ZigbeeDataShare/EditShareData", jsonString, true); + //} + + ///// <summary> + ///// 鍒犻櫎鍏变韩鏁版嵁 + ///// </summary> + ///// <param name="shareData"></param> + ///// <returns></returns> + //public ResponsePackNew DeleteShareData(ShareData shareData) + //{ + // var requestJson = HttpUtil.GetSignRequestJson(new ShareFileDownObj() + // { + // homeId = shareData.homeId, + // homeShareId = shareData.id + // }); + // return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Home_Share_Delete, requestJson); + // //Dictionary<string, string> d = new Dictionary<string, string>(); + // //d.Add("DistributedMark", shareData.DistributedMark); + // //d.Add("HouseDistributedMark", shareData.HouseDistributedMark); + // //string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + // //return RequestHttps($"{severAddress}/ZigbeeDataShare/DeleteShareData", jsonString, true); + //} + ///// <summary> + ///// 鍒犻櫎瀛愯处鍙峰綋鍓嶄綇瀹呯殑鎵�鏈夊叡浜暟鎹� + ///// </summary> + ///// <returns></returns> + //public ResponsePack DeleteCurrentResidenceSharedData(ShareData shareData) + //{ + // Dictionary<string, string> d = new Dictionary<string, string>(); + // d.Add("SubAccountDistributedMark", shareData.SubAccountDistributedMark); + // d.Add("HouseDistributedMark", shareData.HouseDistributedMark); + // string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + // return RequestHttps($"{severAddress}/ZigbeeDataShare/DeleteShareData", jsonString, true); + //} + + /// <summary> + /// 缁戝畾瀛愯处鍙峰埌浣忓畢涓� + /// </summary> + /// <param name="subAccount"></param> + /// <param name="nickName"></param> + /// <returns></returns> + public ResponsePackNew BindResidenceMemberAccount(string subAccount, string nickName) + { + //娣诲姞瀛愯处鍙� + var requestObj = new ChildAddObj() { homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, account = subAccount, nickName = nickName }; + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Add, requestJson); + + } + + ///// <summary> + ///// 鑾峰彇浣忓畢涓嬬殑鎴愬憳璐﹀彿淇℃伅 + ///// </summary> + ///// <returns></returns> + //public ResponsePack GetResidenceMemberAccountInfo(string account) + //{ + // Dictionary<string, object> d = new Dictionary<string, object>(); + // d.Add("Account", account); + // string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); + // return RequestHttps($"{severAddress}/ZigbeeUsers/GetSubAccountInfo", jsonString, true); + //} + + + + + #endregion + /// <summary> + /// 鑾峰彇MQTT杩滅▼杩炴帴淇℃伅鎺ュ彛 + /// </summary> + public MqttInfo GetMqttRemoteInfo(string attachClientId) + { + try + { + var requestJson = HttpUtil.GetSignRequestJson(new GetMqttRemoteInfoObj() + { + attachClientId = attachClientId, + homeType = HomeTypeEnum.BUSPRO.ToString() + }); + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GetMqttRemoteInfo, requestJson, DB_ResidenceData.residenceData.residecenInfo.regionUrl); + if (revertObj.Code == StateCode.SUCCESS) + { + return Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo>(revertObj.Data.ToString()); + } + else + { + Utlis.WriteLine("GetMqttRemoteInfo error"); + return null; + } + } + catch + { + return null; + } + } + + #region 鎺ㄩ�� + /// <summary> + /// 鎻愪氦鎺ㄩ�侀渶瑕佺殑鍏抽敭鏍囪瘑淇℃伅 + /// </summary> + public bool PushSerivceAddPushInfo() + { + try + { + string deviceType = PhoneDeviceType.Android.ToString(); +#if __IOS__ + deviceType = PhoneDeviceType.IOS.ToString(); +#endif + //鏄惁鐢熶骇妯″紡 + bool isProduce = true; +#if DEBUG + isProduce = false; +#endif + + if (string.IsNullOrEmpty(UserInfo.Current.PushDeviceToken)) { + Utlis.WriteLine("PushDeviceToken 涓虹┖"); + return false; + } + + var mAddpushinfoObj = new AddpushinfoObj() + { + pushToken = UserInfo.Current.PushDeviceToken, + deviceName = UserInfo.Current.PhoneName, + deviceType = deviceType, + produce = isProduce, + }; + + //var mAddpushinfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(mAddpushinfoObj); + var mAddpushinfoJson = HttpUtil.GetSignRequestJson(mAddpushinfoObj); + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_PushSerivce_AddToken, mAddpushinfoJson); + if (revertObj.Code == StateCode.SUCCESS) + { + if (revertObj.Data != null) + { + var pushId = revertObj.Data.ToString(); + if (!string.IsNullOrEmpty(pushId)) + { + UserInfo.Current.PushId = pushId; + UserInfo.Current.SaveUserInfo(); + Utlis.WriteLine("PushId: " + pushId); + + return true; + } + } + + } + else + { + //Utlis.WriteLine("AddToken 澶辫触"); + } + return false; + } + catch + { + return false; + } } + /// <summary> + /// 鏌ヨ鎺ㄩ�佷俊鎭垪琛� + /// </summary> + /// <param name="queryType">0鍏ㄩ儴 1鍒嗕韩涓庡姛鑳� 2鎶ヨ绫� 3绯荤粺淇℃伅</param> + /// <returns></returns> + public ResponsePackNew PushSerivceGetPushmessagelist(int queryType = 0) + { + string pushType = null; + + if (queryType == 1) + { + pushType = PushType.Default.ToString(); + } + else if (queryType == 2) + { + pushType = PushType.Alarm.ToString(); + } + else if (queryType == 3) + { + pushType = PushType.Prompt.ToString(); + } + + var requestJson = HttpUtil.GetSignRequestJson(new GetMessageListObj() + { + pushId = UserInfo.Current.PushId, + pushType = pushType + }); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_PushSerivce_Getpushmessagelist, requestJson); + } + + /// <summary> + /// 娓呯┖娑堟伅璁板綍 + /// </summary> + /// <returns></returns> + public bool PushSerivceClearmessagelist() + { + if (string.IsNullOrEmpty(UserInfo.Current.PushId)) return false; + + var requestJson = HttpUtil.GetSignRequestJson(new PushIdObj() + { + pushId = UserInfo.Current.PushId + }); + + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_PushSerivce_Clearmessagelist, requestJson); + if (revertObj.Code == StateCode.SUCCESS) + { + return true; + } + else + { + + } + return false; + } + + /// <summary> + /// 閫�鍑虹櫥褰曪紝娓呯┖鎺ㄩ�佹爣璇� + /// </summary> + /// <returns></returns> + public bool PushSerivceSignOut() + { + if (string.IsNullOrEmpty(UserInfo.Current.PushId)) return false; + try + { + var requestJson = HttpUtil.GetSignRequestJson(new PushIdObj() { + pushId = UserInfo.Current.PushId + }); + + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_PushSerivce_DeleteToken, requestJson); + if (revertObj.Code == StateCode.SUCCESS) + { + return true; + } + else + { + + } + return false; + } + catch + { + return false; + } + } + + /// <summary> + /// 鏍囪娑堟伅鍏ㄩ儴宸茶 + /// </summary> + /// <param name="msgId"></param> + /// <returns></returns> + public bool PushSerivceMarkAllMessageRead() + { + if (string.IsNullOrEmpty(UserInfo.Current.PushId)) return false; + + try + { + var requestJson = HttpUtil.GetSignRequestJson(new PushIdObj() + { + pushId = UserInfo.Current.PushId + }); + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_PushSerivce_ALLMarkread, requestJson); + if (revertObj.Code == StateCode.SUCCESS) + { + return true; + } + else + { + + } + return false; + } + catch + { + return false; + } + } + + /// <summary> + /// 鏍囪鎸囧畾娑堟伅宸茶 + /// </summary> + /// <param name="msgId"></param> + /// <returns></returns> + public bool PushSerivceMarkMessageRead(string msgId) + { + if (string.IsNullOrEmpty(UserInfo.Current.PushId)) return false; + + try + { + var requestJson = HttpUtil.GetSignRequestJson(new PushMsgIdObj() + { + msgId = msgId + }); + + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_PushSerivce_Markread, requestJson); + if (revertObj.Code == StateCode.SUCCESS) + { + return true; + } + else + { + + } + return false; + } + catch + { + return false; + } + } + + /// <summary> + /// 閫氳繃涓婚敭id鍒犻櫎涓�鏉℃帹閫佽褰� + /// </summary> + /// <param name="msgId"></param> + /// <returns></returns> + public bool PushSerivceDeleteMessage(string msgId) + { + if (string.IsNullOrEmpty(UserInfo.Current.PushId)) return false; + + try + { + var requestJson = HttpUtil.GetSignRequestJson(new PushMsgIdObj() + { + msgId = msgId + }); + + var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_PushSerivce_Deletepushinfo, requestJson); + if (revertObj.Code == StateCode.SUCCESS) + { + return true; + } + else + { + IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code); + } + return false; + } + catch + { + return false; + } + } + + /// <summary> + /// 娉ㄥ唽鎺ㄩ�� + /// </summary> + public void RegisteredPush() + { + new System.Threading.Thread(() => + { + var success = PushSerivceAddPushInfo(); + if (success) + { + Utlis.WriteLine("鎺ㄩ�佹敞鍐屾垚鍔�"); + } + else + { + Utlis.WriteLine("鎺ㄩ�佹敞鍐屽け璐�"); + } + }) + { IsBackground = true }.Start(); + } + + /// <summary> + /// 娉ㄩ攢鎺ㄩ�� + /// </summary> + public void SignOutPush() + { + new System.Threading.Thread(() => + { + var success = PushSerivceSignOut(); + if (success) + { + Utlis.WriteLine("鎺ㄩ�佹敞閿�鎴愬姛"); + } + else + { + Utlis.WriteLine("鎺ㄩ�佹敞閿�澶辫触"); + } + }) + { IsBackground = true }.Start(); + } + + #endregion + + #region 妫�娴嬫洿鏂� + /// <summary> + /// + /// </summary> + /// <returns></returns> + public ResponsePackNew CheckAppVersion() + { + var requestObj = new AppVersionCheckObj() + { + + }; + + var requestJson = HttpUtil.GetSignRequestJson(requestObj); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_CheckAppVersion, requestJson); + } + + + + #endregion + + #region 鑾峰彇澶╂皵閮ㄥ垎 + /// <summary> + /// /// <summary> + /// 鑾峰彇鎸囧畾缁忕含搴︾殑鍩庡競淇℃伅 + /// </summary> + /// </summary> + /// <param name="lon">缁忓害</param> + /// <param name="lat">绾害</param> + public void GetCityInfo(string lon, string lat) + { + System.Threading.Tasks.Task.Run(() => + { + while (true) + { + //鑾峰彇澶╂皵 + var webClient = new WebClient(); + string url = $"https://developer.hdlcontrol.com/Weather/Weather/FindCity/?lon={lon}&lat={lat}"; + string responseString = null; + try + { + responseString = Encoding.UTF8.GetString(webClient.DownloadData(url)); + } + catch (Exception ex) + { + MainPage.Log(ex.Message); + } + + if (responseString != null) + { + try + { + var revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(responseString); + JObject jt = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(revertObj.ResponseData.ToString()); + MainPage.cityInfo.city = jt["City"].ToString(); + MainPage.cityInfo.cid = jt["Cid"].ToString(); + MainPage.cityInfo.location = jt.GetValue("Location").ToString(); + MainPage.cityInfo.province = jt.GetValue("Province").ToString(); + MainPage.cityInfo.country = jt.GetValue("Country").ToString(); + MainPage.cityInfo.timeZone = jt.GetValue("TimeZone").ToString(); + url = $"https://developer.hdlcontrol.com/Weather/Weather/GetAirQualityAndWeather/?cid={MainPage.cityInfo.cid}"; + responseString = null; + responseString = Encoding.UTF8.GetString(webClient.DownloadData(url)); + revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(responseString); + jt = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(revertObj.ResponseData.ToString()); + MainPage.cityInfo.temperature = jt.GetValue("Temperature").ToString(); + MainPage.cityInfo.humidity = jt.GetValue("Humidity").ToString(); + MainPage.cityInfo.pm25 = jt.GetValue("Air_Quality").ToString(); + MainPage.cityInfo.windLevel = jt.GetValue("WindLevel").ToString(); + MainPage.cityInfo.weather = jt.GetValue("Weather").ToString(); + break; + } + catch (Exception ex) + { + MainPage.Log($"get weather error : {ex.Message}"); + } + } + System.Threading.Thread.Sleep(1000); + } + Shared.Application.RunOnMainThread(() => + { + try + { + HDL_ON.UI.HomePage.LoadEvent_RefreshAir(); + } + catch { } + }); + }); + } + + #endregion + + + #region 澶囦唤閮ㄥ垎 + ///// <summary> + ///// 鑾峰彇浣忓畢澶囦唤鍒楄〃 + ///// </summary> + //public Dictionary<int, string> GetRegionLastBackupId() + //{ + // //Dialog dialog = new Dialog(); + // //dialog.Show(); + + // Dictionary<int, string> backupList = new Dictionary<int, string>(); + // Dictionary<string, object> d = new Dictionary<string, object>(); + // d.Add("LevelID", DB_ResidenceData.residenceData.residecenInfo.RegionID);// 199200); + // var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d); + // var revertObj = RequestHttps("https://developer.hdlcontrol.com/api/GetUserFolder", requestJson, true); + // if (revertObj == null || revertObj.ResponseData == null) + // { + // return new Dictionary<int, string>(); + // } + // var jt = Newtonsoft.Json.JsonConvert.DeserializeObject<List<JObject>>(revertObj.ResponseData.ToString()); + // foreach (var j in jt) + // { + // var folderId = (int)j.GetValue("FolderID"); + // var folderName = j.GetValue("FolderName").ToString(); + // backupList.Add(folderId, folderName); + // } + // return backupList; + //} + + /* 2020-09-01 寮冪敤 鎭㈠鏃ф暟鎹姛鑳藉湪bus杞欢涓婂疄鐜� + /// <summary> + /// 鑾峰彇澶囦唤鏂囦欢鍒楄〃 + /// </summary> + public void GetBackupFileList(int levelId) + { + Dialog dialog = new Dialog(); + dialog.Show(); + Loading loading = new Loading(); + dialog.AddChidren(loading); + loading.Start(""); + new System.Threading.Thread(() => + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("LevelID", levelId); + var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d); + var revertObj = RequestHttps("https://developer.hdlcontrol.com/api/UserBackupList", requestJson, true); + var jt = Newtonsoft.Json.JsonConvert.DeserializeObject<List<JObject>>(revertObj.ResponseData.ToString()); + #region 鎭㈠鎴块棿鏁版嵁 + + + GetBackupRoom(jt,loading); + #endregion + + Application.RunOnMainThread(() => { + loading.Hide(); + dialog.Close(); + }); + }) + { IsBackground = true }.Start(); + + } + + /// <summary> + /// 涓嬭浇鍥剧墖 + /// </summary> + /// <param name="fileName"></param> + void DownloadImage(string fileName,int fId) + { + if (downImageList.Contains(fileName)) + { + return; + } + else + { + downDeviceList.Add(fileName); + } + + System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(fileName, @"^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$", System.Text.RegularExpressions.RegexOptions.IgnoreCase); + if (match.Success) + { + FileStream fs = null; + try + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("Id", fId); + var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d); + var revertObj = RequestHttps("https://developer.hdlcontrol.com/api/BackupDetail", requestJson, true); + var jsonBytes = Newtonsoft.Json.JsonConvert.SerializeObject(revertObj.ResponseData); + + var bytes = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]>(jsonBytes); + var byteStr = Encoding.UTF8.GetString(bytes); + var ss = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(byteStr); + var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/", fileName+".png"); + fs = new FileStream(filePath, FileMode.Create, FileAccess.Write); + fs.Write(bytes, 0, bytes.Length); + fs.Flush(); + + MainPage.Log($"download image {fileName}"); + } + catch (Exception ex) + { + MainPage.Log("FileUtiles Code 113:" + ex.ToString()); + } + finally + { + try + { + if (fs != null) + { + fs.Close(); + } + } + catch (Exception ex) + { + MainPage.Log("FileUtils Code 121 :" + ex.ToString()); + } + } + } + } + + /// <summary> + /// 鑾峰彇澶囦唤鎴块棿鏁版嵁 + /// </summary> + void GetBackupRoom(List<JObject> jt, Loading loading) + { + var roomList = new Dictionary<JObject, Room>(); + + var roomsObject = jt.FindAll((room) => room.GetValue("FileName").ToString().StartsWith("Room_") && room.GetValue("FileName").ToString().Split('_').Length == 2); + foreach(var pp in jt) + { + if(pp.GetValue("FileName").ToString().StartsWith("Equipment")) + { + MainPage.Log(pp.GetValue("FileName").ToString()); + + + } + + + } + roomsObject = jt.FindAll((room) => room.GetValue("FileName").ToString().StartsWith("Equipment_OnePortBus")); + foreach (var roomJObj in roomsObject) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("Id", (int)roomJObj.GetValue("Id")); + var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d); + var revertObj = RequestHttps("https://developer.hdlcontrol.com/api/BackupDetail", requestJson, true); + var jsonBytes = Newtonsoft.Json.JsonConvert.SerializeObject(revertObj.ResponseData); + var byresss = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]>(jsonBytes); + var byteStr = Encoding.UTF8.GetString(byresss); + var ss = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(byteStr); + //var RootPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/"; + //var filePath = Path.Combine(RootPath, ss.GetValue("BackGroundImage").ToString()) + ".png"; + //var room1 = new Room() + //{ + // sid = Guid.NewGuid().ToString(), + // name = ss.GetValue("Name").ToString(), + // floorIndex = 1, + // backgroundImage = "Classification/Room/Roombg.png", + // //backgroundImage = ss.GetValue("BackGroundImage").ToString() == "Room/r1.png" ? "Classification/Room/Roombg.png" : filePath, + //}; + //DB_ResidenceData.rooms.Add(room1); + //roomList.Add(ss, room1); + + } + var index = 1; + foreach (var j in jt) + { + Application.RunOnMainThread(() => + { + int pro = (int)(index * 1.0 / jt.Count * 100); + loading.Text = pro.ToString() + "%"; + }); + var fileName = j.GetValue("FileName").ToString(); + var fileNameArrary = fileName.Split('_'); + if (fileNameArrary.Length == 5 && fileName.Split('_')[0] == "Equipment") + { + GetBackupFile(fileName, (int)j.GetValue("Id"), roomList); + } + else + { + DownloadImage(fileName, (int)j.GetValue("Id")); + } + index++; + } + DB_ResidenceData.residenceData.SaveResidenceData(); + } + + List<string> downDeviceList = new List<string>(); + List<string> downImageList = new List<string>(); + + /// <summary> + /// 鑾峰彇澶囦唤璁惧鏂囦欢 + /// </summary> + void GetBackupFile(string fileName, int fId, Dictionary<JObject, Room> dir) + { + var type = fileName.Split('_')[1]; + if (downDeviceList.Contains(fileName)) + { + return; + } + else + { + downDeviceList.Add(fileName); + } + if (type == "LightSwitch" || + type == "LightMixSwitch" || + type == "LightDimming" || + type == "LightDALI" || + type == "LightMixDimming" || + type == "LightLogic" || + type == "LightRGB" || + type == "AC" || + type == "HVAC" || + type == "ACPanel" || + type == "ACInfrared" || + type == "CurtainModel" || + type == "CurtainRoller" || + type == "CurtainTrietex") + { + + MainPage.Log($"download file {fileName}"); + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("Id", fId); + var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d); + var revertObj = RequestHttps("https://developer.hdlcontrol.com/api/BackupDetail", requestJson, true); + //var jt = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]>(revertObj.ResponseData.ToString()); + var jsonBytes = Newtonsoft.Json.JsonConvert.SerializeObject(revertObj.ResponseData); + var byresss = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]>(jsonBytes); + var byteStr = System.Text.Encoding.UTF8.GetString(byresss); + var ss = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(byteStr); + + /// <summary> + /// 鍔熻兘ID + /// </summary> + /// "03010112345678901234560101230123AABB"; + var buffer = Guid.NewGuid().ToByteArray(); + string guid = ""; + if (buffer != null) + { + for (int i = 0; i < buffer.Length; i++) + { + if (i > 7) + break; + guid += buffer[i].ToString("X2"); + + } + } + + //var guid = BitConverter.ToUInt32(buffer, 16).ToString(); + List<string> roomIds = new List<string>(); + foreach (var d1 in dir) + { + var key = d1.Key; + var des = key.GetValue("DeviceFilePathList"); + if (Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(des.ToString()).Contains(fileName)) + { + roomIds.Add(d1.Value.sid); + } + } + switch (type) + { + case "LightSwitch": + case "LightMixSwitch": + var light1 = DB_ResidenceData.functionList.lights.Find((obj) => obj.bus_Data.SubnetID == (byte)ss.GetValue("SubnetID") && + obj.bus_Data.DeviceID == (byte)ss.GetValue("DeviceID") && obj.bus_Data.LoopID == (byte)ss.GetValue("LoopID")); + if (light1 != null) + { + //light1.roomIdList.Add(roomSid); + break; + } + DB_ResidenceData.functionList.lights.Add(new Light() + { + sid = "030101" + guid + "0102010001AABB", + name = ss.GetValue("Name").ToString(), + function = new List<Trait>() { + new Trait { name="on_off", max=100,min = 0, value_key= new List<string> { "on","off"} }, + }, + roomIdList = roomIds, + bus_Data = new BusData + { + SubnetID = (byte)ss.GetValue("SubnetID"), + DeviceID = (byte)ss.GetValue("DeviceID"), + LoopID = (byte)ss.GetValue("LoopID"), + }, + }); + break; + case "LightDimming": + case "LightDALI": + case "LightMixDimming": + var light2 = DB_ResidenceData.functionList.lights.Find((obj) => obj.bus_Data.SubnetID == (byte)ss.GetValue("SubnetID") && + obj.bus_Data.DeviceID == (byte)ss.GetValue("DeviceID") && obj.bus_Data.LoopID == (byte)ss.GetValue("LoopID")); + if (light2 != null) + { + //light2.roomIdList.Add(roomSid); + break; + } + DB_ResidenceData.functionList.lights.Add(new Light() + { + sid = "030101" + guid + "0202020001AABB", + name = ss.GetValue("Name").ToString(), + function = new List<Trait>() { + new Trait { name="brightness", max=100,min = 0, value_key= new List<string> { "up","down"} }, + }, + roomIdList = roomIds, + //roomIdList = new List<string>() { "0001" }, + lastState = "20%", + bus_Data = new BusData + { + SubnetID = (byte)ss.GetValue("SubnetID"), + DeviceID = (byte)ss.GetValue("DeviceID"), + LoopID = (byte)ss.GetValue("LoopID"), + }, + }); + break; + case "LightLogic": + case "LightRGB": + var light3 = DB_ResidenceData.functionList.lights.Find((obj) => obj.bus_Data.SubnetID == (byte)ss.GetValue("SubnetID") && + obj.bus_Data.DeviceID == (byte)ss.GetValue("DeviceID") && obj.bus_Data.LoopID == (byte)ss.GetValue("LoopID")); + if (light3 != null) + { + //light3.roomIdList.Add(roomSid); + break; + } + DB_ResidenceData.functionList.lights.Add(new Light() + { + sid = "030101" + guid + "0202040001AABB", + name = ss.GetValue("Name").ToString(), + function = new List<Trait>() { + new Trait { name="brightness", max=100,min = 0, value_key= new List<string> { "on","off"} }, + new Trait { name="color", max=100,min = 0, value_key= new List<string> { "255", "255", "255" } }, + }, + roomIdList = roomIds, + //roomIdList = new List<string>() { roomSid }, + bus_Data = new BusData + { + SubnetID = (byte)ss.GetValue("SubnetID"), + DeviceID = (byte)ss.GetValue("DeviceID"), + LoopID = (byte)ss.GetValue("LoopID"), + }, + }); + break; + case "AC": + case "HVAC": + case "ACPanel": + case "ACInfrared": + var ac = DB_ResidenceData.functionList.aCs.Find((obj) => obj.bus_Data.SubnetID == (byte)ss.GetValue("SubnetID") && + obj.bus_Data.DeviceID == (byte)ss.GetValue("DeviceID") && obj.bus_Data.LoopID == (byte)ss.GetValue("LoopID")); + if (ac != null) + { + //ac.roomIdList.Add(roomSid); + break; + } + DB_ResidenceData.functionList.aCs.Add(new AC() + { + sid = "030101" + guid + "0204010001AABB", + name = ss.GetValue("Name").ToString(), + function = new List<Trait>() { + new Trait { name="on_off", max=1,min = 0, value_key= new List<string> { "on","off"} }, + new Trait { name="mode", max = 2,min =0,value_key = new List<string>{ "auto", "heat", "cool","dry" } }, + new Trait { name = "fan",max = 3,min =0,value_key = new List<string>{ "low", "mid", "high" ,"auto"} }, + new Trait { name = "temperature", max = 32,min=16,value_key = new List<string>{"up","down" } }, + }, + roomIdList = roomIds, + //roomIdList = new List<string>() { roomSid}, + lastState = "鍒跺喎 涓 18掳C", + bus_Data = new BusData + { + SubnetID = (byte)ss.GetValue("SubnetID"), + DeviceID = (byte)ss.GetValue("DeviceID"), + LoopID = (byte)ss.GetValue("LoopID"), + }, + }); + break; + //Entity. + case "CurtainModel": + var curtain1 = DB_ResidenceData.functionList.curtains.Find((obj) => obj.bus_Data.SubnetID == (byte)ss.GetValue("SubnetID") && + obj.bus_Data.DeviceID == (byte)ss.GetValue("DeviceID") && obj.bus_Data.LoopID == (byte)ss.GetValue("LoopID")); + if (curtain1 != null) + { + //curtain1.roomIdList.Add(roomSid); + break; + } + DB_ResidenceData.functionList.curtains.Add(new Curtain() + { + sid = "030101" + guid + "0203010001AABB", + name = ss.GetValue("Name").ToString(), + roomIdList = roomIds, + //roomIdList = new List<string>() { roomSid }, + function = new List<Trait>() { + new Trait { name="on_off", max=2,min = 0, value_key= new List<string> { "on","off","stop"} }, + },// "curtain", + lastState = "寮�", + bus_Data = new BusData + { + SubnetID = (byte)ss.GetValue("SubnetID"), + DeviceID = (byte)ss.GetValue("DeviceID"), + LoopID = (byte)ss.GetValue("LoopID"), + }, + }); + break; + case "CurtainRoller": + var curtain2 = DB_ResidenceData.functionList.curtains.Find((obj) => obj.bus_Data.SubnetID == (byte)ss.GetValue("SubnetID") && + obj.bus_Data.DeviceID == (byte)ss.GetValue("DeviceID") && obj.bus_Data.LoopID == (byte)ss.GetValue("LoopID")); + if (curtain2 != null) + { + //curtain2.roomIdList.Add(roomSid); + break; + } + DB_ResidenceData.functionList.curtains.Add(new Curtain() + { + sid = "030101" + guid + "0203040001AABB", + name = ss.GetValue("Name").ToString(), + roomIdList = roomIds, + //roomIdList = new List<string>() { roomSid }, + function = new List<Trait>() { + new Trait { name="on_off", max=100,min = 0, value_key= new List<string> { "on","off","stop"} }, + },// "rollingshutter", + lastState = "20%", + bus_Data = new BusData + { + SubnetID = (byte)ss.GetValue("SubnetID"), + DeviceID = (byte)ss.GetValue("DeviceID"), + LoopID = (byte)ss.GetValue("LoopID"), + }, + }); + break; + case "CurtainTrietex": + var curtain3 = DB_ResidenceData.functionList.curtains.Find((obj) => obj.bus_Data.SubnetID == (byte)ss.GetValue("SubnetID") && + obj.bus_Data.DeviceID == (byte)ss.GetValue("DeviceID") && obj.bus_Data.LoopID == (byte)ss.GetValue("LoopID")); + if (curtain3 != null) + { + //curtain3.roomIdList.Add(roomSid); + break; + } + DB_ResidenceData.functionList.curtains.Add(new Curtain() + { + sid = "030101" + guid + "0203030001AABB", + name = ss.GetValue("Name").ToString(), + roomIdList = roomIds, + //roomIdList = new List<string>() { roomSid }, + function = new List<Trait>() { + new Trait { name="on_off", max=100,min = 0, value_key= new List<string> { "on","off","stop"} }, + }, + lastState = "20%", + bus_Data = new BusData + { + SubnetID = (byte)ss.GetValue("SubnetID"), + DeviceID = (byte)ss.GetValue("DeviceID"), + LoopID = (byte)ss.GetValue("LoopID"), + }, + }); + break; + //Entity.DB_ResidenceData.functionList.floorHeatings.Add(new FloorHeating() + //{ + // sid = "12341212345678901234560704010004ABCD", + // name = "鍦扮儹", + // roomIdList = new List<string>() { "0001" }, + // trait = new List<Trait>() { + // new Trait { attri="on_off", max=1,min = 0, value= new List<string> { "on","off"} }, + // new Trait { attri="mode", max = 2,min =0,value = new List<string>{ "auto", "heat", "cool","dry" } }, + // new Trait { attri = "temperature", max = 32,min=16,value = new List<string>{"up","down" } }, + // },// + // lastState = "" + //}); + //Entity. + //break; + } + + } + } + */ + + #endregion + + + #region Kaede --璁惧鍔熻兘鈥斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�斺�� + /// <summary> + /// 鑾峰彇璁惧鍒楄〃 + /// </summary> + /// <returns></returns> + public ResponsePackNew GetDeviceList() + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("gatewayId", DB_ResidenceData.residenceData.HomeGateway.gatewayId); + //d.Add("roomId", DB_ResidenceData.residenceData.residecenInfo.RegionID);//鍙帶鍙傛暟锛屽綋闇�瑕佸垎椤佃幏鍙栵紝鎬庝箞鐭ラ亾鍒嗛〉鎬绘暟 + //d.Add("searchType", DB_ResidenceData.residenceData.residecenInfo.RegionID); + //d.Add("pageSize", DB_ResidenceData.residenceData.residecenInfo.RegionID); + //d.Add("pageNo", DB_ResidenceData.residenceData.residecenInfo.RegionID); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetDevcieList, requestJson); + } + /// <summary> + /// 鑾峰彇璁惧璇︽儏鍒楄〃 + /// </summary> + /// <returns></returns> + public ResponsePackNew GetDeviceInfoList(List<string> functionIds) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("deviceIds", functionIds); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetDevcieInfoList, requestJson); + } + /// <summary> + /// 鍒锋柊璁惧鐘舵�� + /// </summary> + /// <returns></returns> + public ResponsePackNew RefreshDeviceStatus(List<string> functionIds) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("deviceIds", functionIds); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_RefreshDeviceStatus, requestJson); + } + + /// <summary> + /// 鎺у埗璁惧 + /// </summary> + /// <returns></returns> + public ResponsePackNew ControlDevice(List<ApiAlinkControlActionObj> actionObjs) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("gatewayId", DB_ResidenceData.residenceData.HomeGateway.gatewayId);//DriverLayer.Control.Ins.GatewayId); + d.Add("actions", actionObjs); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_ControlDevice, requestJson); + } + /// <summary> + /// 缂栬緫璁惧淇℃伅 + /// 缁戝畾鍏崇郴銆佸悕绉般�佹敹钘� + /// </summary> + /// <returns></returns> + public ResponsePackNew UpdataDevcieInfo(Function function) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("deviceId", function.deviceId); + d.Add("name", function.name); + d.Add("collect", function.collect); + d.Add("roomIds", function.roomIds); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditDevice, requestJson); + } + /// <summary> + /// 璁惧缁戝畾鎴块棿 + /// </summary> + public string BindDeviceToRoom(string deviceId,string roomId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("deviceIds", new List<string>() { deviceId}); + d.Add("roomIds", new List<string>() { roomId}); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_BindDeviceToRoom, requestJson).Code; + } + /// <summary> + /// 璁惧瑙g粦鎴块棿 + /// </summary> + public string UnbindDeviceToRoom(string deviceId, string roomId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("deviceIds", new List<string>() { deviceId }); + d.Add("roomIds", new List<string>() { roomId }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_UnbindDeviceToRoom, requestJson).Code; + } + /// <summary> + /// 璁惧鍚嶇О淇敼 + /// </summary> + public string EditDeviceName(string deviceId, string deviceName) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("deviceId", deviceId); + d.Add("name", deviceName); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditDeviceName, requestJson).Code; + } + /// <summary> + /// 鏀惰棌璁惧 + /// </summary> + public ResponsePackNew CollectDevice(string deviceId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("deviceIds",new List<string>() { deviceId }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CollectDevice, requestJson); + } + /// <summary> + /// 鍙栨秷鏀惰棌璁惧 + /// </summary> + public ResponsePackNew CancelCollectDevice(string deviceId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("deviceIds", new List<string>() { deviceId }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CancelCollectDevice, requestJson); + } + + #endregion + + #region Kaede --鍦烘櫙鍔熻兘-------------------------- + /// <summary> + /// 鑾峰彇鍦烘櫙鍒楄〃 + /// 鎴块棿ID鍙┖锛岄粯璁ゆ煡璇綇瀹呬笅鎵�鏈夋埧闂� + /// </summary> + /// <param name="roomId">鎴块棿ID</param> + /// <returns></returns> + public ResponsePackNew GetSceneList(string roomId = null) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + if (roomId != null) + { + d.Add("roomId", roomId); + } + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetSecneList, requestJson); + } + /// <summary> + /// 鑾峰彇鍦烘櫙璇︽儏 + /// </summary> + /// <param name="seceneId">鍦烘櫙ID</param> + /// <returns></returns> + public ResponsePackNew GetSceneInfo(string seceneId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("userSceneIds",new List<string>() { seceneId }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetSecneList, requestJson); + } + /// <summary> + /// 娣诲姞鍦烘櫙 + /// </summary> + /// <returns></returns> + public ResponsePackNew AddScene(Scene scene) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("scenes", new List<Scene>() { scene }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_AddSecne, requestJson); + } + /// <summary> + /// 缂栬緫鍦烘櫙 + /// </summary> + /// <param name="scene"></param> + /// <returns></returns> + public ResponsePackNew EditScene(Scene scene) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("scenes", new List<Scene>() { scene }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditSecne, requestJson); + } + /// <summary> + /// 鍒犻櫎鍦烘櫙 + /// </summary> + /// <returns></returns> + public string DeleteScene(string userSceneId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("userSceneIds", new List<string>() { userSceneId }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_DeleteSecne, requestJson).Code; + } + /// <summary> + /// 鎵ц鍦烘櫙 + /// </summary> + /// <returns></returns> + public string ExecuteScene(string userSceneId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("userSceneIds", new List<string>() { userSceneId }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_ExecuteSecne, requestJson).Code; + } + /// <summary> + /// 鏀惰棌鍦烘櫙 + /// </summary> + /// <param name="userSceneId"></param> + /// <returns></returns> + public string CollectScene(string userSceneId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("userSceneIds", new List<string>() { userSceneId }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CollectScene, requestJson).Code; + } + /// <summary> + /// 鍙栨秷鏀惰棌鍦烘櫙 + /// </summary> + /// <param name="userSceneId"></param> + /// <returns></returns> + public string CancelCollectScene(string userSceneId) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("userSceneIds", new List<string>() { userSceneId }); + + var requestJson = HttpUtil.GetSignRequestJson(d); + return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CancelCollectScene, requestJson).Code; + } + #endregion + + #region Kaede --鎴块棿鍔熻兘-------------------------- + /// <summary> + /// 鑾峰彇鎴块棿鍒楄〃 + /// </summary> + /// <param name="GetType">鑾峰彇绫诲瀷锛歊OOM\FLOOR;涓嶈緭鍏ヨ繑鍥炲叏閮�</param> + /// <returns></returns> + public ResponsePackNew GetRoomList(string GetType = "All") + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + if (GetType != "All") + { + d.Add("roomType", GetType); + } + var requestJson = HttpUtil.GetSignRequestJson(d); + var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetRoomList, requestJson); + + return pack; + } + /// <summary> + /// 娣诲姞鎴块棿\妤煎眰 + /// 妤煎眰涔熷睘浜庢埧闂� + /// </summary> + /// <returns></returns> + public ResponsePackNew AddRoom(List<SpatialInfo> rooms) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("rooms", rooms); + + var requestJson = HttpUtil.GetSignRequestJson(d); + var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_AddRoom, requestJson); + //var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(pack.Data.ToString()); + //if (revData != null) + //{ + // SpatialInfo.CurrentSpatial.UpdateSpatialList(revData, OptionType.Update); + //} + return pack; + } + /// <summary> + /// 淇敼鎴块棿淇℃伅 + /// </summary> + /// <returns></returns> + public ResponsePackNew UpdateRoom(List<SpatialInfo> rooms) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("rooms", rooms); + + var requestJson = HttpUtil.GetSignRequestJson(d); + var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_UpdateRoom, requestJson); + //var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(pack.Data.ToString()); + //if (revData != null) + //{ + // SpatialInfo.CurrentSpatial.UpdateSpatialList(revData,OptionType.Update); + //} + return pack; + } + /// <summary> + /// 鍒犻櫎鎴块棿 + /// </summary> + /// <param name="roomIds"></param> + /// <returns></returns> + public ResponsePackNew DeleteRoom(List<string> roomIds) + { + Dictionary<string, object> d = new Dictionary<string, object>(); + d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); + d.Add("ids", roomIds); + + var requestJson = HttpUtil.GetSignRequestJson(d); + var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_DelRoom, requestJson); + return pack; + } #endregion } -- Gitblit v1.8.0