123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using ET;
- using GFGGame;
- namespace GFGGame
- {
- public static class PoemPhotoSProxy
- {
- //获取玩家所有相册数据协议
- public static async ETTask<bool> 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<string[]> 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<bool> 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<bool> ReqRemovedPhoto(List<long> 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<bool> 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<bool> 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;
- }
- }
- }
|