private void LikeMyworkEvent(EditedImg img, bool islike) //点赞自己的作品 { if (ApplicationModel.userInfo != null) { OffLineController.Instance.OffLine(); return; } if(img.workId == null || img.workId == "") //这个作品还没有自己的作品id,需要先上传 { UploadUserEditedFileCo(img , image => { LikeMyworkEvent(image, islike);}); } else { NetLoadcontroller.Instance.RequestUrlWidthMethodGet( ApplicationModel.HOST + "/image/like?uid=" + ApplicationModel.userInfo.Uid + "&authorUid=" + ApplicationModel.userInfo.Uid + "&workId=" + img.workId + "&action=" + GetActionStrByBool(islike) + "&sessionId=" + ApplicationModel.userInfo.SessionId, (json, isSuccess) => { LikeRequestCallback(json, isSuccess); } ); } }
public IEnumerator UploadUserEditedFileCo(EditedImg img, Action<EditedImg> calback) { yield return new WaitForSeconds(2f); //TODO:daiwancheng WWWForm postForm = GetPostFormByEditedImg(img); WWW upload = new WWW(ApplicationModel.HOST + "/image/saveWork", postForm); yield return upload; NetLoadcontroller.Instance.RequestUrlWidthMethodPost( ApplicationModel.HOST + "/image/saveWork", postForm, (json, isSuccess) => { UploadUserEditedFileCallback(json, isSuccess, img, calback); } ); }
private WWWForm GetPostFormByEditedImg(EditedImg img) { WWWForm postForm = new WWWForm(); postForm.AddField("imageId", img.imageId); postForm.AddBinaryData("clickPos", GetClickPosFromImg(img.imageId).EncodeToPNG(), img.imageId + "_pos"); postForm.AddBinaryData("palette", GetPaletteFromImg(img.imageId).EncodeToPNG(), img.imageId + "_ed"); postForm.AddField("deviceId", ApplicationModel.device_id); postForm.AddField("uid", ApplicationModel.userInfo.Uid); postForm.AddBinaryData("finalImg", GetTex2dFromImg(img.imageId).EncodeToPNG(), img.imageId); postForm.AddField("sessionId", ApplicationModel.userInfo.SessionId); return postForm; }
private void UploadUserEditedFileCallback(string json, bool isSuccess, EditedImg img, Action<EditedImg> calback) { if (isSuccess) { UploadEditedFileReturnJson uploadEditedFileReturnJson = JsonConvert.DeserializeObject<UploadEditedFileReturnJson>(json); if (uploadEditedFileReturnJson.status == 0) { img.workId = uploadEditedFileReturnJson.data.workId; calback(img); } } else { //:上传失败 } }