| | |
| | | btnTakePicture.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | btnTakePicture.IsSelected = false; |
| | | |
| | | |
| | | //拍照裁剪 |
| | | //var imageName = "headImage"; |
| | | var imageName = Guid.NewGuid().ToString(); |
| | |
| | | var waitPage = new Loading(); |
| | | bodyView.AddChidren(waitPage); |
| | | waitPage.Start(Language.StringByID(StringId.PleaseWait)); |
| | | //开始上传 |
| | | //1.开始上传 |
| | | new Thread(() => |
| | | { |
| | | try |
| | | { |
| | | var uploadImageObj = ImageUtlis.Current.GetHeadImageUploadKeyObj(userId); |
| | | uploadImageObj.content = imageBytes; |
| | | //生成上传头像参数 |
| | | var uploadImageObj = new UploadImageObj() |
| | | { |
| | | prefix = "Icon" + Utlis.GetTimestamp(), |
| | | uid = userId, |
| | | fileName = ImageUtlis.HEADIMAGE, |
| | | content = imageBytes, |
| | | }; |
| | | |
| | | var imageUrl = ImageUtlis.Current.UploadImage(uploadImageObj); |
| | | if (!string.IsNullOrEmpty(imageUrl) && imageUrl.Contains(userId)) |
| | | { |
| | | //上传成功 |
| | | Application.RunOnMainThread(() => |
| | | //2.上传成功 |
| | | //2.1更新最新图片路径到云端 |
| | | var resultObj = UpdateMemberHeadIcon(imageUrl); |
| | | if (resultObj.Code == StateCode.SUCCESS) |
| | | { |
| | | //Utlis.WriteLine("上传成功:" + imageUrl); |
| | | //1.2如果是自定义图片删除之前的 |
| | | if (!string.IsNullOrEmpty(imageView.ImagePath) && !imageView.ImagePath.Contains("LoginIcon/2.png")) |
| | | //3.更新最新图片路径到云端成功 |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | //Utlis.WriteLine("删除: " + imageView.ImagePath); |
| | | System.IO.File.Delete(imageView.ImagePath); |
| | | } |
| | | //重命名保存 |
| | | ImageUtlis.Current.WriteFileByBytes(imageUrl, imageBytes); |
| | | imageView.ImagePath = imageUrl; |
| | | imageView.ImageBytes = imageBytes; |
| | | //上传成功 |
| | | Utlis.ShowTip(Language.StringByID(StringId.UploadSuccessfully)); |
| | | uploadSuccessAction?.Invoke(imageUrl); |
| | | }); |
| | | //Utlis.WriteLine("上传成功:" + imageUrl); |
| | | //1.2如果是自定义图片删除之前的 |
| | | if (!string.IsNullOrEmpty(imageView.ImagePath) && !imageView.ImagePath.Contains("LoginIcon/2.png")) |
| | | { |
| | | //Utlis.WriteLine("删除: " + imageView.ImagePath); |
| | | System.IO.File.Delete(imageView.ImagePath); |
| | | } |
| | | //重命名保存 |
| | | ImageUtlis.Current.WriteFileByBytes(imageUrl, imageBytes); |
| | | imageView.ImagePath = imageUrl; |
| | | imageView.ImageBytes = imageBytes; |
| | | //上传成功 |
| | | Utlis.ShowTip(Language.StringByID(StringId.UploadSuccessfully)); |
| | | uploadSuccessAction?.Invoke(imageUrl); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //更新最新图片路径到云端失败 |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | //保存用户头像失败 |
| | | Utlis.ShowTip(Language.StringByID(StringId.FailedToSaveUserImage)); |
| | | }); |
| | | |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | catch { } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新用户头像 |
| | | /// </summary> |
| | | /// <param name="userName"></param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew UpdateMemberHeadIcon(string memberHeadIcon) |
| | | { |
| | | var requestJson = HttpUtil.GetSignRequestJson(new UpdateMemberHeadIconRes() |
| | | { |
| | | memberHeadIcon = memberHeadIcon |
| | | }); |
| | | return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UpdateMemberInfo, requestJson); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | |
| | | ///// <summary> |
| | | ///// 获取用户信息 |
| | | ///// </summary> |
| | | ///// <returns></returns> |
| | | //public void GetUserInfoNew() |
| | | //{ |
| | | |
| | | // new System.Threading.Thread(() => |
| | | // { |
| | | // try |
| | | // { |
| | | // var requestJson = HttpUtil.GetSignRequestJson(new NullObj()); |
| | | // var resultObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_GetMemberInfo, requestJson); |
| | | // if (resultObj.Code == StateCode.SUCCESS) |
| | | // { |
| | | // var info = Newtonsoft.Json.JsonConvert.DeserializeObject<MemberInfoRes>(resultObj.Data.ToString()); |
| | | // UserInfo.Current.userEmailInfo = info.memberEmail; |
| | | // UserInfo.Current.userMobileInfo = info.memberPhone; |
| | | // UserInfo.Current.userName = info.memberName; |
| | | |
| | | // if (!string.IsNullOrEmpty(info.memberPhonePrefix)) |
| | | // { |
| | | // UserInfo.Current.areaCode = info.memberPhonePrefix; |
| | | // } |
| | | |
| | | // //2020-12-15 修改头像方案 |
| | | // if (!string.IsNullOrEmpty(info.memberHeadIcon)) |
| | | // { |
| | | // var headImageBytes = ImageUtlis.Current.DownHeadImageByImageKey(info.memberHeadIcon); |
| | | |
| | | // if (headImageBytes != null && headImageBytes.Length > 0) |
| | | // { |
| | | // UserInfo.Current.headImagePagePath = info.memberHeadIcon; |
| | | // } |
| | | // } |
| | | |
| | | // Application.RunOnMainThread(() => |
| | | // { |
| | | // btnUserName.Text = str; |
| | | // updataUserName(); |
| | | // }); |
| | | |
| | | // UserInfo.Current.SaveUserInfo(); |
| | | // MainPage.Log("获取用户信息成功。"); |
| | | |
| | | // //userHeadImageView |
| | | // } |
| | | // } |
| | | // catch { } |
| | | // finally |
| | | // { |
| | | |
| | | |
| | | // } |
| | | |
| | | // }) |
| | | // { IsBackground = true }.Start(); |
| | | //} |
| | | } |
| | | } |