| | |
| | | using System;
|
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Net;
|
| | | using System.Net; |
| | | using System.Text; |
| | | using HDL_ON.Entity; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON.DAL.Server |
| | | { |
| | |
| | | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | //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> |
| | |
| | | public ResponsePackNew GetRegionByAccount(string account) |
| | | { |
| | | var requestJson = HttpUtil.GetSignRequestJson(new RegionByAccountObj() { account = account }); |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_GetRegionByAccount, requestJson); |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_GetRegionByAccount, requestJson, HttpUtil.GlobalRequestHttpsHost); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | var requestJson = HttpUtil.GetSignRequestJson(new RefreshTokenObj() |
| | | { |
| | | refreshToken = UserInfo.Current.refreshToken, |
| | | 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.lastTime = DateTime.Now; |
| | | UserInfo.Current.SaveUserInfo(); |
| | | UserInfo.Current.LoginTokenString = revertData.headerPrefix + revertData.accessToken; |
| | | UserInfo.Current.RefreshToken = revertData.refreshToken; |
| | | UserInfo.Current.LastTime = DateTime.Now; |
| | | UserInfo.Current.SaveUserInfo(); |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | |
| | | |
| | | #region 注册、登录部分 |
| | | /// <summary> |
| | | /// 获取请求提交的语言参数 |
| | | /// </summary> |
| | | public string GetPostLanguageType() |
| | | { |
| | | return Language.CurrentLanguage == "Chinese" ? LanguageTypeEnum.CHINESE.ToString() : LanguageTypeEnum.ENGLISH.ToString(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 通用 发送验证码方法 |
| | |
| | | var requestObj = new VerifyCodeSendObj() |
| | | { |
| | | verifyType = (int)verifyType, |
| | | languageType = GetPostLanguageType() |
| | | languageType = Utlis.GetPostLanguageType() |
| | | }; |
| | | // 是否是手机 |
| | | if (isPhone) |
| | |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_ForgetPwd, requestJson); |
| | | } |
| | | |
| | | |
| | | |
| | | ///// <summary> |
| | | ///// 获取登录验证码 |
| | | ///// </summary> |
| | | //public ResponsePack GetLoginVerCode(string account) |
| | | //{ |
| | | |
| | | // string jsonString = "{" +
|
| | | // "\"Account\":" + "\"" + account + "\"" + "," + |
| | | // "\"AreaCode\":" + "86" + |
| | | // "}"; |
| | | // return RequestHttps($"{severAddress}/ZigbeeUsers/LoginSendVerCode", jsonString, false); |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 验证验证码 |
| | | /// </summary> |
| | |
| | | /// <returns></returns> |
| | | public ResponsePackNew ValidatorCode(VerifyType verifyType, string account, string code, bool isPhone, bool verifySuccessFail = true) |
| | | { |
| | | var requestObj = new VerifyCodeCheckObj() { verifyCode = code, verifyType = (int)verifyType , verifySuccessFail = verifySuccessFail }; |
| | | var requestObj = new VerifyCodeCheckObj() { verifyCode = code, verifyType = (int)verifyType, verifySuccessFail = verifySuccessFail }; |
| | | if (isPhone) |
| | | { |
| | | //手机 |
| | |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Verification_Check, requestJson); |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 重设密码 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePack ResetPassword(string account, string password, string rePassword, int countryIndex) |
| | | { |
| | | string jsonString = "{" +
|
| | | "\"Account\":" + "\"" + account + "\"" + "," + |
| | | "\"Password\":" + "\"" + password + "\"" + "," + |
| | | "\"AgainPassword\":" + "\"" + rePassword + "\"" + "," + |
| | | "\"AreaCode\":" + countryIndex + |
| | | "}"; |
| | | return RequestHttps($"{severAddress}/ZigbeeUsers/ResetPassword", jsonString, false); |
| | | } |
| | | #endregion |
| | | |
| | | #region 个人信息部分 |
| | |
| | | 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; |
| | | UserInfo.Current.areaCode = info.memberPhonePrefix; |
| | | 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 headImageBytes = DownHeadImage(); |
| | | if (headImageBytes != null) |
| | | { |
| | | UserInfo.Current.headImagePageBytes = headImageBytes; |
| | | FileStream fs = null; |
| | | try |
| | | { |
| | | 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(); |
| | | } |
| | | } |
| | | 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(); |
| | | UserInfo.Current.SaveUserInfo(); |
| | | MainPage.Log("获取用户信息成功。"); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载用户头像 |
| | | /// 获取用户头像 |
| | | /// </summary> |
| | | public byte[] DownHeadImage() |
| | | /// <param name="userId"></param> |
| | | public void GetUserHeadImage(string userId) |
| | | { |
| | | return HttpUtil.RequestHttpsDownload(NewAPI.API_POST_Head_Down, null); |
| | | 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> |
| | |
| | | /// <returns></returns> |
| | | public ResponsePackNew EditUserName(string userName) |
| | | { |
| | | var requestJson = HttpUtil.GetSignRequestJson(new UpdateMemberNameRes() { |
| | | memberName = userName |
| | | }); |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UpdateMemberInfo, requestJson); |
| | | 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) |
| | | { |
| | | FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); |
| | | byte[] bytes = new byte[fs.Length]; |
| | | fs.Read(bytes, 0, bytes.Length); |
| | | var revertObj = HttpUtil.RequestHttpsUpload(RestSharp.Method.POST, NewAPI.API_POST_Head_Upload, bytes); |
| | | return revertObj.Code; |
| | | } |
| | | ///// <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> |
| | | /// 更改绑定账户的邮箱或者手机号 |
| | |
| | | /// <returns></returns> |
| | | public string BindAccount(string account, string code = "", bool isPhone = false) |
| | | { |
| | | var requestObj = new BindWithAccountObj() { verifyCode = code}; |
| | | var requestObj = new BindWithAccountObj() { verifyCode = code }; |
| | | if (isPhone) |
| | | { |
| | | //手机 |
| | |
| | | /// <returns></returns> |
| | | public string UnBindAccount(bool isPhone) |
| | | { |
| | | var requestObj = new UnBindAccountObj() { unBindLabel = isPhone ? "PHONE": "EMAIL" }; |
| | | var requestObj = new UnBindAccountObj() { unBindLabel = isPhone ? "PHONE" : "EMAIL" }; |
| | | var requestJson = HttpUtil.GetSignRequestJson(requestObj); |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UnbindWithAccount, requestJson).Code; |
| | | } |
| | |
| | | /// </summary> |
| | | public string GetHomePager(HomeTypeEnum homeType = HomeTypeEnum.ALL) |
| | | { |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(new GetHomeListObj() { homeType = homeType.ToString() }); |
| | | var requestJson = HttpUtil.GetSignRequestJson(new GetHomeListObj() { homeType = homeType.ToString() }); |
| | | var resultObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Gethomepager, requestJson); |
| | | if(resultObj.Code == StateCode.SUCCESS) |
| | | if (resultObj.Code == StateCode.SUCCESS) |
| | | { |
| | | var homeList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoResNew>>(resultObj.Data.ToString()); |
| | | if (homeList == null || homeList.Count == 0) { |
| | | if (homeList == null || homeList.Count == 0) |
| | | { |
| | | |
| | | |
| | | } |
| | | else |
| | | { |
| | | UserInfo.Current.regionList = new List<RegionInfoRes>(); |
| | | |
| | | UserInfo.Current.regionList = new List<RegionInfoRes>(); |
| | | |
| | | foreach (var mHome in homeList) |
| | | { |
| | | var home = new RegionInfoRes() |
| | |
| | | { |
| | | continue; |
| | | } |
| | | UserInfo.Current.regionList.Add(home); |
| | | if (string.IsNullOrEmpty(DB_ResidenceData.residenceData.CurReginID)) |
| | | 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; |
| | | DB_ResidenceData.residenceData.CurReginID = UserInfo.Current.regionList[0].RegionID; |
| | | //恢复备份 |
| | | HDLCommon.Current.RestoreHomeBackup(DB_ResidenceData.residenceData.CurReginID); |
| | | } |
| | | } |
| | | |
| | | |
| | | DB_ResidenceData.residenceData.SaveResidenceData(); |
| | | UserInfo.Current.SaveUserInfo(); |
| | | UserInfo.Current.SaveUserInfo(); |
| | | |
| | | //刷新一次住宅网关 |
| | | GetHomeGatewayList(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | return resultObj.Code; |
| | | |
| | | //string jsonString = "{" +
|
| | | //string jsonString = "{" + |
| | | // "\"RequestVersion\":" + "\"" + MainPage.VersionString + "\"" + "," + |
| | | // "\"RequestSource\":" + "\"" + "2" + "\"" + "," + |
| | | // "\"HomeType\":" + "\"" + "1" + "\"" + "," + |
| | |
| | | //} |
| | | //return responsePack.StateCode; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 编辑住宅信息 |
| | | /// </summary> |
| | | /// <param name="editId">0 修改住宅名字、1 修改住宅地址</param> |
| | | /// <param name="editName"></param> |
| | | /// <returns></returns> |
| | | public ResponsePack EditResidenceInfo() |
| | | public ResponsePackNew EditResidenceInfo(int editId, string editName) |
| | | { |
| | | //创建字典 |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | //添加元素 |
| | | d.Add("RequestVersion", MainPage.VersionString); |
| | | d.Add("RequestSource", "2"); |
| | | d.Add("LoginAccessToken", UserInfo.Current.loginTokenString); |
| | | d.Add("HomeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("HomeType", 1); |
| | | d.Add("Name", DB_ResidenceData.residenceData.residecenInfo.Name); |
| | | d.Add("Address", DB_ResidenceData.residenceData.residecenInfo.Address); |
| | | //添加完成以后把字典类中数据格式化为json字符串 |
| | | //将对象转为json字符串 |
| | | var requestObj = new AddOrUpdateHomeObj() |
| | | { |
| | | homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, |
| | | }; |
| | | |
| | | string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); |
| | | return RequestHttps($"{severAddress}/App/EditHome", jsonString, false); |
| | | 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> |
| | |
| | | /// <returns></returns> |
| | | public ResponsePackNew GetResidenceMemberAccount() |
| | | { |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(new HomeIdObj() { homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID }); |
| | | var replaceToken = UserInfo.Current.loginTokenString; |
| | | //如果当前所分享住宅和为管理员,替换为主人token |
| | | //待处理... |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Child_FindAll, requestJson, DB_ResidenceData.residenceData.residecenInfo.regionUrl, replaceToken); |
| | | var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID }); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_FindAll, requestJson); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | childAccountId = subaccount.childAccountId, |
| | | homeId = subaccount.homeId |
| | | }; |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj); |
| | | var replaceToken = UserInfo.Current.loginTokenString; |
| | | //如果当前所分享住宅和为管理员,替换为主人token |
| | | //待处理... |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Child_Delete, requestJson, DB_ResidenceData.residenceData.residecenInfo.regionUrl, replaceToken); |
| | | var requestJson = HttpUtil.GetSignRequestJson(requestObj); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Delete, requestJson); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="nickName"></param> |
| | | /// <param name="subAccountGuid"></param> |
| | | /// <returns></returns> |
| | | public ResponsePack EditSubAccountNickName(string nickName, string subAccountGuid) |
| | | public ResponsePackNew EditSubAccountNickName(string nickName, string childAccountId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("SubAccountGuid", subAccountGuid); |
| | | d.Add("NickName", nickName); |
| | | string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); |
| | | return RequestHttps($"{severAddress}/ZigbeeUsers/EditSubAccountNickName", jsonString, true); |
| | | 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> |
| | | /// 修改子账号创建场景权限 |
| | |
| | | /// <param name="nickName"></param> |
| | | /// <param name="subAccountGuid"></param> |
| | | /// <returns></returns> |
| | | public ResponsePack ChangeCreateSceneState(string homeGuid, string subAccountGuid) |
| | | public ResponsePackNew ChangeCreateSceneState(bool isAllow, string childAccountId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("SubAccountGuid", subAccountGuid); |
| | | d.Add("HomeGuid", homeGuid); |
| | | string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); |
| | | return RequestHttps($"{severAddress}/ZigbeeUsers/ChangeCreateSceneState", jsonString, true); |
| | | 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 ResponsePack GetShareDataByMemberAccount(string memberId) |
| | | public ResponsePackNew DeleteShareData(DeleteShareObj deleteShareObj) |
| | | { |
| | | 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(deleteShareObj); |
| | | |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_Delete, requestJson); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取住宅下子账号的共享数据 |
| | | /// 获取分享 |
| | | /// </summary> |
| | | /// <param name="addShareObj"></param> |
| | | /// <returns></returns> |
| | | public ResponsePack GetShareData(string memberId, string hId) |
| | | public ResponsePackNew GetShareDataByMemberAccount(string childAccountId) |
| | | { |
| | | 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 = HttpUtil.GetSignRequestJson(new GetShareObj() |
| | | { |
| | | homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, |
| | | childAccountId = childAccountId, |
| | | }); |
| | | |
| | | /// <summary> |
| | | /// 增加共享数据列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePack 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); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_GetList, requestJson); |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 增加共享数据 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePack EditShareData(ShareData 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> |
| | | ///// <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); |
| | | |
| | | /// <summary> |
| | | /// 删除共享数据 |
| | | /// </summary> |
| | | /// <param name="shareData"></param> |
| | | /// <returns></returns> |
| | | public ResponsePack DeleteShareData(ShareData shareData) |
| | | { |
| | | 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); |
| | | } |
| | | // 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> |
| | | /// 绑定子账号到住宅下 |
| | |
| | | /// <param name="subAccount"></param> |
| | | /// <param name="nickName"></param> |
| | | /// <returns></returns> |
| | | public ResponsePack BindResidenceMemberAccount(string subAccount, string nickName) |
| | | public ResponsePackNew BindResidenceMemberAccount(string subAccount, string nickName) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("SubAccount", subAccount); |
| | | d.Add("HouseDistributedMark", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("Nickname", nickName); |
| | | d.Add("IsAllowRemoteCtrl", true); |
| | | //添加子账号 |
| | | 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); |
| | | |
| | | string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d); |
| | | return RequestHttps($"{severAddress}/ZigbeeUsers/BindSubAccount", jsonString, true); |
| | | } |
| | | |
| | | ///// <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 ResponsePack GetResidenceMemberAccountInfo(string account) |
| | | public bool PushSerivceClearmessagelist() |
| | | { |
| | | 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); |
| | | 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(() => |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region mqtt远程连接(旧) |
| | | /// <summary> |
| | | /// 请求Mqtt数据 |
| | | /// </summary> |
| | | /// <param name="dataStringJson">请求的参数.</param> |
| | | public ResponsePack RequestMqttInfo(string dataStringJson) |
| | | { |
| | | ResponsePack revertObj = null; |
| | | |
| | | var webClient = new WebClient(); |
| | | #region |
| | | webClient.Headers.Add("CONTENT-TYPE", "application/json"); |
| | | var url = "https://global.hdlcontrol.com/ProposedProductionApi/EmqMqtt/GetConnMqttInfo"; |
| | | |
| | | byte[] bytes = null; |
| | | try |
| | | { |
| | | bytes = webClient.UploadData(url, Encoding.UTF8.GetBytes(dataStringJson)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.Message); |
| | | revertObj = new ResponsePack() { StateCode = "Net_Error" }; |
| | | } |
| | | |
| | | string responseString = null; |
| | | if (bytes != null) |
| | | { |
| | | responseString = Encoding.UTF8.GetString(bytes); |
| | | } |
| | | |
| | | if (responseString != null) |
| | | { |
| | | try |
| | | { |
| | | revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(responseString); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.ToString()); |
| | | } |
| | | } |
| | | return revertObj; |
| | | #endregion |
| | | } |
| | | #endregion |
| | | |
| | | #region 备份部分 |
| | | /// <summary> |
| | | /// 获取住宅备份列表 |
| | | /// </summary> |
| | | public Dictionary<int, string> GetRegionLastBackupId() |
| | | { |
| | | //Dialog dialog = new Dialog(); |
| | | //dialog.Show(); |
| | | ///// <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; |
| | | } |
| | | // 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> |
| | | /// 获取备份文件列表 |
| | |
| | | */ |
| | | |
| | | #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> |
| | | /// 设备解绑房间 |
| | | /// </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">获取类型:ROOM\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 |
| | | } |
| | | } |