using System.Collections.Generic; using System.IO; using System.Net; using ET; using GFGGame; namespace GFGGame { public static class PoemPhotoSProxy { //获取玩家所有相册数据协议 public static async ETTask ReqAllPhotoInfos() { S2C_GetAllAlbumInfo response = null; response = (S2C_GetAllAlbumInfo)await MessageHelper.SendToServer(new C2S_GetAllAlbumInfo()); if (response != null) { if (response.Error == ErrorCode.ERR_Success) { return true; } } return false; } //获取图片的临时上传地址协议 public static async ETTask ReqTempPictureUrl(string pictureName) { S2C_GetTempPictureUrl response = null; response = (S2C_GetTempPictureUrl)await MessageHelper.SendToServer(new C2S_GetTempPictureUrl() { PictureName = pictureName }); if (response != null) { if (response.Error == ErrorCode.ERR_Success) { return new string[] { response.TempPictureUrl, response.PictureObjectPath }; } } return null; } //将图片上传到华为云 public static string PushToHWCloud(string signUrl, byte[] buffer) { // 使用PUT请求上传对象 HttpWebRequest webRequest = WebRequest.Create(signUrl) as HttpWebRequest; webRequest.Method = "PUT"; webRequest.SendChunked = true; webRequest.AllowWriteStreamBuffering = false; using (Stream requestStream = webRequest.GetRequestStream()) { requestStream.Write(buffer, 0, buffer.Length); } HttpWebResponse webResponse = null; try { webResponse = webRequest.GetResponse() as HttpWebResponse; return webResponse.StatusCode.ToString(); } catch (WebException ex) { webResponse = ex.Response as HttpWebResponse; return ""; } } //保存成功后,添加图片至相册 public static async ETTask ReqAddTophoto(string pictureObjectPath, int sourceType) { S2C_AddPicture response = null; response = (S2C_AddPicture)await MessageHelper.SendToServer(new C2S_AddPicture() { PictureObjectPath = pictureObjectPath, SourceType = sourceType }); if (response != null) { if (response.Error == ErrorCode.ERR_Success) { PoemPhotoData photoData = new PoemPhotoData(); photoData.PictureId = response.PictureInfo.PictureId; photoData.CreationTime = response.PictureInfo.CreationTime; photoData.ToppingTime = response.PictureInfo.ToppingTime; photoData.ToppingStatus = response.PictureInfo.ToppingStatus; photoData.LockingStatus = response.PictureInfo.LockingStatus; photoData.PictureName = response.PictureInfo.PictureName; photoData.PictureTempUrl = response.PictureInfo.PictureTempUrl; PoemPhotoDataManager.Instance.Add(photoData, sourceType); EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE); return true; } } return false; } //批量删除玩家相册 public static async ETTask ReqRemovedPhoto(List pictureIds, int sourceType) { S2C_RemovedPictures response = null; response = (S2C_RemovedPictures)await MessageHelper.SendToServer(new C2S_RemovedPictures() { PictureIds = pictureIds }); if (response != null) { if (response.Error == ErrorCode.ERR_Success) { PoemPhotoDataManager.Instance.Remove(response.PictureIds, sourceType); EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE); return true; } } return false; } //修改图片锁定状态 public static async ETTask ReqChangeLockingState(long pictureId, bool state, int sourceType) { S2C_UpPictureLockingStatus response = null; response = (S2C_UpPictureLockingStatus)await MessageHelper.SendToServer(new C2S_UpPictureLockingStatus() { PictureId = pictureId, Status = state }); if (response != null) { if (response.Error == ErrorCode.ERR_Success) { PoemPhotoDataManager.Instance.ChangeLockingState(pictureId, state, sourceType); EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE); return true; } } return false; } //修改图片置顶状态 public static async ETTask ReqChangeToppingState(long pictureId, bool state, int sourceType) { S2C_UpPictureToppingStatus response = null; response = (S2C_UpPictureToppingStatus)await MessageHelper.SendToServer(new C2S_UpPictureToppingStatus() { PictureId = pictureId, Status = state }); if (response != null) { if (response.Error == ErrorCode.ERR_Success) { PoemPhotoDataManager.Instance.ChangeLockingState(pictureId, state, sourceType); EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE); return true; } } return false; } } }