From 1209d93632b447823caf371dea5ccf030ab20434 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期五, 13 十一月 2020 17:11:55 +0800 Subject: [PATCH] 2020-11-13 1.更新 --- HDL_ON/DAL/Server/HttpServerRequest.cs | 376 +++++++++++++++++++++++++++++++++++------------------ 1 files changed, 247 insertions(+), 129 deletions(-) diff --git a/HDL_ON/DAL/Server/HttpServerRequest.cs b/HDL_ON/DAL/Server/HttpServerRequest.cs index 15b98dc..b8f4f5c 100644 --- a/HDL_ON/DAL/Server/HttpServerRequest.cs +++ b/HDL_ON/DAL/Server/HttpServerRequest.cs @@ -31,14 +31,11 @@ */ - public string relaseaSever = "https://global.hdlcontrol.com/HangZhouHdlCloudApi"; - public string debugSever = "https://global.hdlcontrol.com/ProposedProductionApi"; - string severAddress; + string severAddress = "https://global.hdlcontrol.com/ProposedProductionApi"; public HttpServerRequest() { - severAddress = relaseaSever; } /// <summary> @@ -53,7 +50,7 @@ /// <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) + 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); @@ -66,7 +63,7 @@ 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); + return RequestHttps("https://developer.hdlcontrol.com/api/GetSensorPushHistory", jsonString, true); } @@ -94,99 +91,166 @@ 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); + } + + /// <summary> + /// 鍒锋柊Token + /// </summary> + /// <returns></returns> + public bool RefreshToken() + { + var requestJson = HttpUtil.GetSignRequestJson(new RefreshTokenObj() + { + refreshToken = MainPage.LoginUser.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()); + MainPage.LoginUser.loginTokenString = revertData.headerPrefix + revertData.accessToken; + MainPage.LoginUser.lastTime = DateTime.Now; + MainPage.LoginUser.SaveUserInfo(); + return true; + } + return false; + } + + #endregion + #region 娉ㄥ唽銆佺櫥褰曢儴鍒� /// <summary> + /// 鑾峰彇璇锋眰鎻愪氦鐨勮瑷�鍙傛暟 + /// </summary> + public string GetPostLanguageType() + { + return Language.CurrentLanguage == "Chinese" ? LanguageTypeEnum.CHINESE.ToString() : LanguageTypeEnum.ENGLISH.ToString(); + } + + /// <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 = 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($"{severAddress}/ZigbeeUsers/Login", jsonString, false); + var requestJson = HttpUtil.GetSignRequestJson(new LoginObj() + { + account = account, + loginPwd = password + }); + return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Login, requestJson); } /// <summary> /// 楠岃瘉鐮佺櫥褰� /// </summary> - public ResponsePack LoginValidCode(string account,string vCode) + /// <param name="account">璐﹀彿</param> + /// <param name="vCode">楠岃瘉鐮�</param> + /// <returns></returns> + public ResponsePackNew LoginValidCode(string account, string vCode) { - Dictionary<string, object> d = new Dictionary<string, object>(); - d.Add("Account", account); - d.Add("Code", vCode); - d.Add("Language", Language.CurrentLanguage); - d.Add("AreaCode", "86"); - var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); - return RequestHttps($"{severAddress}/ZigbeeUsers/LoginValidCode", jsonString, false); - } - - /// <summary> - /// 鎵嬫満鍙风爜娉ㄥ唽 - /// </summary> - /// <param name="mobileNumber"></param> - /// <param name="password"></param> - /// <param name="language"></param> - public ResponsePack RegisterPhone(string mobileNumber, string password, string language) - { - string jsonString = "{" + - "\"Account\":" + "\"" + mobileNumber + "\"" + "," + - "\"Password\":" + "\"" + password + "\"" + "," + - "\"Language\":" + "\"" + language + "\"" + - "\"AreaCode\":" + "\"" + "86" + "\"" + - "}"; - return RequestHttps($"{severAddress}/SignIn", jsonString, false); - } - - public ResponsePack GetAreaCode() - { - string requestJson = "{}"; - return RequestHttps($"{severAddress}/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.ToLower() + "\"" + "," + - "\"Code\":" + "\"" + code + "\"" + "," + - "\"RegisterSoruce\":" + 0 + "," + - "\"AreaCode\":" + areaCode + - "}"; - return RequestHttps($"{severAddress}/ZigbeeUsers/ValidataCodeAndRegisterAccount", requestJson, 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 GetRegisterVerCode(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.ToLower() + "\"" + "," + - "\"AreaCode\":" + MainPage.LoginUser.areaCode + - "}"; - return RequestHttps($"{severAddress}/ZigbeeUsers/RegisterSendVerCode", 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> @@ -197,7 +261,7 @@ string jsonString = "{" + "\"Account\":" + "\"" + account + "\"" + "," + - "\"AreaCode\":" + "86" + + "\"AreaCode\":" + "86" + "}"; return RequestHttps($"{severAddress}/ZigbeeUsers/LoginSendVerCode", jsonString, false); } @@ -233,6 +297,8 @@ return RequestHttps($"{severAddress}/ZigbeeUsers/ValidatorCode", jsonString, false); } + + /// <summary> /// 閲嶈瀵嗙爜 /// </summary> @@ -260,7 +326,7 @@ var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d); var revertObj = RequestHttps($"{severAddress}/ZigbeeUsers/GetAccountInfo", requestJson, true); - if (revertObj.StateCode.ToUpper() == "SUCCESS") + if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) { var dataStr = JObject.FromObject(revertObj.ResponseData); //"DistributedMark": "96439601-fd26-4768-8440-1d9dfa32c109", < !--甯愬彿Id-- > @@ -281,7 +347,8 @@ fs.Flush(); MainPage.LoginUser.headImagePagePath = filePath; } - } catch (Exception ex) + } + catch (Exception ex) { MainPage.Log($"download headImage error : {ex.Message}"); } @@ -357,63 +424,39 @@ /// <summary> /// 鑾峰彇浣忓畢鍒楄〃 /// </summary> - public string GetHomePager() + public string GetHomePager(HomeTypeEnum homeType = HomeTypeEnum.ALL) { - string jsonString = "{" + - "\"RequestVersion\":" + "\"" + MainPage.VersionString + "\"" + "," + - "\"RequestSource\":" + "\"" + "2" + "\"" + "," + - "\"HomeType\":" + "\"" + "1" + "\"" + "," + - "\"LoginAccessToken\":" + "\"" + MainPage.LoginUser.loginTokenString + "\"" + - "}"; - var responsePack = RequestHttps($"{severAddress}/App/GetHomePager", jsonString,false); - - if (responsePack.StateCode.ToUpper() == "SUCCESS") + var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(new GetHomeListObj() { homeType = homeType.ToString() }); + var resultObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Gethomepager, requestJson); + if(resultObj.Code == StateCode.SUCCESS) { - var dataStr = JObject.FromObject(responsePack.ResponseData); - //娌℃湁浣忓畢 - if (dataStr.GetValue("PageData").ToString() == "[]") - { + var homeList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoResNew>>(resultObj.Data.ToString()); + if (homeList == null || homeList.Count == 0) { + } 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" - // } - // ] - //}} MainPage.LoginUser.regionList = new List<RegionInfoRes>(); - foreach (var jsonData in dataStr.GetValue("PageData")) + + foreach (var mHome in homeList) { - 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()), + 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) { @@ -428,8 +471,82 @@ DB_ResidenceData.residenceData.SaveResidenceData(); MainPage.LoginUser.SaveUserInfo(); } + } - return responsePack.StateCode; + + return resultObj.Code; + + //string jsonString = "{" + + // "\"RequestVersion\":" + "\"" + MainPage.VersionString + "\"" + "," + + // "\"RequestSource\":" + "\"" + "2" + "\"" + "," + + // "\"HomeType\":" + "\"" + "1" + "\"" + "," + + // "\"LoginAccessToken\":" + "\"" + MainPage.LoginUser.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" + // // } + // // ] + // //}} + // MainPage.LoginUser.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; + // } + // MainPage.LoginUser.regionList.Add(home); + // if (string.IsNullOrEmpty(DB_ResidenceData.residenceData.CurReginID)) + // { + // DB_ResidenceData.residenceData.CurReginID = MainPage.LoginUser.regionList[0].RegionID; + // } + // } + // DB_ResidenceData.residenceData.SaveResidenceData(); + // MainPage.LoginUser.SaveUserInfo(); + // } + //} + //return responsePack.StateCode; } /// <summary> /// 缂栬緫浣忓畢淇℃伅 @@ -485,7 +602,7 @@ /// <param name="nickName"></param> /// <param name="subAccountGuid"></param> /// <returns></returns> - public ResponsePack EditSubAccountNickName(string nickName,string subAccountGuid) + public ResponsePack EditSubAccountNickName(string nickName, string subAccountGuid) { Dictionary<string, object> d = new Dictionary<string, object>(); d.Add("SubAccountGuid", subAccountGuid); @@ -525,7 +642,7 @@ /// 鑾峰彇浣忓畢涓嬪瓙璐﹀彿鐨勫叡浜暟鎹� /// </summary> /// <returns></returns> - public ResponsePack GetShareData(string memberId,string hId) + public ResponsePack GetShareData(string memberId, string hId) { Dictionary<string, object> d = new Dictionary<string, object>(); d.Add("DistributedMark", memberId); @@ -597,7 +714,7 @@ /// <param name="subAccount"></param> /// <param name="nickName"></param> /// <returns></returns> - public ResponsePack BindResidenceMemberAccount(string subAccount,string nickName) + public ResponsePack BindResidenceMemberAccount(string subAccount, string nickName) { Dictionary<string, object> d = new Dictionary<string, object>(); d.Add("SubAccount", subAccount); @@ -677,7 +794,8 @@ } System.Threading.Thread.Sleep(1000); } - Shared.Application.RunOnMainThread(() => { + Shared.Application.RunOnMainThread(() => + { try { HDL_ON.UI.HomePage.LoadEvent_RefreshAir(); @@ -694,7 +812,7 @@ /// 璇锋眰Mqtt鏁版嵁 /// </summary> /// <param name="dataStringJson">璇锋眰鐨勫弬鏁�.</param> - public ResponsePack RequestMqttInfo( string dataStringJson) + public ResponsePack RequestMqttInfo(string dataStringJson) { ResponsePack revertObj = null; @@ -740,7 +858,7 @@ /// <summary> /// 鑾峰彇浣忓畢澶囦唤鍒楄〃 /// </summary> - public Dictionary<int,string> GetRegionLastBackupId() + public Dictionary<int, string> GetRegionLastBackupId() { //Dialog dialog = new Dialog(); //dialog.Show(); @@ -750,7 +868,7 @@ 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) + if (revertObj == null || revertObj.ResponseData == null) { return new Dictionary<int, string>(); } -- Gitblit v1.8.0