HDL_ON/DAL/Server/HttpServerRequest.cs
@@ -250,32 +250,15 @@
        /// <summary>
        /// 获取登录验证码
        /// </summary>
        public ResponsePack GetLoginVerCode(string account)
        {
            string jsonString = "{" +
                                "\"Account\":" + "\"" + account + "\"" + "," +
                                "\"AreaCode\":" + "86" +
                                "}";
            return RequestHttps($"{severAddress}/ZigbeeUsers/LoginSendVerCode", jsonString, false);
        }
        ///// <summary>
        ///// 发送验证码
        ///// 获取登录验证码
        ///// </summary>
        //public ResponsePack SendSms(string account)
        //public ResponsePack GetLoginVerCode(string account)
        //{
        //    string jsonString = "{" +
        //                        "\"Account\":" + "\"" + account + "\"" + "," +
        //                        "\"Company\":" + MainPage.Company + "," +
        //                        "\"Language\":" + "\"" + Language.CurrentLanguage + "\"" + "," +
        //                        "\"AreaCode\":" + OnAppConfig.Instance.CountryNumber +
        //                        "\"AreaCode\":" + "86" +
        //                        "}";
        //    return RequestHttps($"{severAddress}/ZigbeeUsers/LoginSendVerCode", jsonString, false);
        //}
@@ -283,18 +266,27 @@
        /// <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($"{severAddress}/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);
        }
@@ -320,57 +312,111 @@
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        public void GetUserInfo()
        public void GetUserInfo(bool bGetHeadImage = true)
        {
            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 requestJson = HttpUtil.GetSignRequestJson(new NullObj());
            var resultObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_GetMemberInfo, requestJson);
            if (resultObj.Code == StateCode.SUCCESS)
            {
                var dataStr = JObject.FromObject(revertObj.ResponseData);
                //"DistributedMark": "96439601-fd26-4768-8440-1d9dfa32c109",  < !--帐号Id-- >
                MainPage.LoginUser.userEmailInfo = dataStr.GetValue("Email").ToString();
                MainPage.LoginUser.userMobileInfo = dataStr.GetValue("Phone").ToString();
                FileStream fs = null;
                try
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<MemberInfoRes>(resultObj.Data.ToString());
                MainPage.LoginUser.userEmailInfo = info.memberEmail;
                MainPage.LoginUser.userMobileInfo = info.memberPhone;
                MainPage.LoginUser.userName = info.memberName;
                MainPage.LoginUser.areaCode = info.memberPhonePrefix;
                //是否需要获取头像
                if (bGetHeadImage)
                {
                    var headImageString = dataStr.GetValue("HeadImage").ToString();
                    if (!string.IsNullOrEmpty(headImageString))
                    var headImageBytes = DownHeadImage();
                    if (headImageBytes != null)
                    {
                        var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(headImageString);
                        var headImageBytes = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]>(jsonString);
                        MainPage.LoginUser.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();
                        MainPage.LoginUser.headImagePagePath = filePath;
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"download headImage error : {ex.Message}");
                }
                finally
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
                // "GesturePwd": null,  < !--手势密码-- >
                // "StringPwd": null , < !--字符串密码-- >
                MainPage.LoginUser.userName = dataStr.GetValue("UserName").ToString();
                        FileStream fs = null;
                        try
                        {
                            MainPage.LoginUser.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();
                            MainPage.LoginUser.headImagePagePath = filePath;
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"download headImage error : {ex.Message}");
                        }
                        finally
                        {
                            if (fs != null)
                            {
                                fs.Close();
                            }
                        }
                Application.RunOnMainThread(() =>
                {
                });
                    }
                }
                MainPage.LoginUser.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-- >
            //    MainPage.LoginUser.userEmailInfo = dataStr.GetValue("Email").ToString();
            //    MainPage.LoginUser.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);
            //            MainPage.LoginUser.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();
            //            MainPage.LoginUser.headImagePagePath = filePath;
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //        MainPage.Log($"download headImage error : {ex.Message}");
            //    }
            //    finally
            //    {
            //        if (fs != null)
            //        {
            //            fs.Close();
            //        }
            //    }
            //    // "GesturePwd": null,  < !--手势密码-- >
            //    // "StringPwd": null , < !--字符串密码-- >
            //    MainPage.LoginUser.userName = dataStr.GetValue("UserName").ToString();
            //    Application.RunOnMainThread(() =>
            //    {
            //    });
            //    MainPage.LoginUser.SaveUserInfo();
            //    MainPage.Log("获取用户信息成功。");
            //}
        }
        /// <summary>
        /// 下载用户头像
        /// </summary>
        public byte[] DownHeadImage()
        {
            return HttpUtil.RequestHttpsDownload(NewAPI.API_POST_Head_Down, null);
        }
        /// <summary>
@@ -378,14 +424,12 @@
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public ResponsePack EditUserName(string userName)
        public ResponsePackNew EditUserName(string userName)
        {
            Dictionary<string, string> d = new Dictionary<string, string>();
            d.Add("UserName", userName);
            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d);
            var revertObj = RequestHttps($"{severAddress}/ZigbeeUsers/UpdateUserName", requestJson, true);
            return revertObj;
           var requestJson = HttpUtil.GetSignRequestJson(new UpdateMemberNameRes() {
               memberName = userName
           });
           return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UpdateMemberInfo, requestJson);
        }
        /// <summary>
@@ -398,26 +442,47 @@
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            byte[] bytes = new byte[fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            Dictionary<string, byte[]> d = new Dictionary<string, byte[]>();
            d.Add("HeadImage", bytes);
            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(d);
            var revertObj = RequestHttps($"{severAddress}/ZigbeeUsers/UpdateHeadImage", requestJson, true);
            return revertObj.StateCode;
            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)
        public string BindAccount(string account, string code = "", bool isPhone = false)
        {
            string jsonString = "{" + "\"Account\":" + "\"" + account + "\"" + "}";
            var responsePack = RequestHttps($"{severAddress}/ZigbeeUsers/BindAccount", jsonString, true);
            return responsePack.StateCode;
            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>
        /// 解绑手机或者邮箱
        /// </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 住宅部分
@@ -575,25 +640,31 @@
        /// 获取住宅下的成员账号
        /// </summary>
        /// <returns></returns>
        public ResponsePack GetResidenceMemberAccount()
        public ResponsePackNew GetResidenceMemberAccount()
        {
            Dictionary<string, object> d = new Dictionary<string, object>();
            d.Add("DistributedMark", DB_ResidenceData.residenceData.residecenInfo.RegionID);
            string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d);
            return RequestHttps($"{severAddress}/ZigbeeUsers/GetSubAccountByDistributedMark", jsonString, true);
            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(new HomeIdObj() { homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID });
            var replaceToken = MainPage.LoginUser.loginTokenString;
            //如果当前所分享住宅和为管理员,替换为主人token
            //待处理...
            return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Child_FindAll, requestJson, DB_ResidenceData.residenceData.residecenInfo.regionUrl, replaceToken);
        }
        /// <summary>
        /// 删除住宅下的成员账号
        /// </summary>
        /// <returns></returns>
        public ResponsePack DeleteResidenceMemberAccount(string memberAccount)
        public ResponsePackNew DeleteResidenceMemberAccount(ResidenceMemberInfo subaccount)
        {
            Dictionary<string, object> d = new Dictionary<string, object>();
            d.Add("SubAccount", memberAccount);
            d.Add("HouseDistributedMark", DB_ResidenceData.residenceData.residecenInfo.RegionID);
            string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d);
            return RequestHttps($"{severAddress}/ZigbeeUsers/DeletedSubAccount", jsonString, true);
            var requestObj = new ChildDeleteObj()
            {
                childAccountId = subaccount.childAccountId,
                homeId = subaccount.homeId
            };
            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
            var replaceToken = MainPage.LoginUser.loginTokenString;
            //如果当前所分享住宅和为管理员,替换为主人token
            //待处理...
            return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Child_Delete, requestJson, DB_ResidenceData.residenceData.residecenInfo.regionUrl, replaceToken);
        }
        /// <summary>