PoemPhotoSProxy.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Net;
  4. using ET;
  5. using GFGGame;
  6. namespace GFGGame
  7. {
  8. public static class PoemPhotoSProxy
  9. {
  10. //获取玩家所有相册数据协议
  11. public static async ETTask<bool> ReqAllPhotoInfos()
  12. {
  13. S2C_GetAllAlbumInfo response = null;
  14. response = (S2C_GetAllAlbumInfo)await MessageHelper.SendToServer(new C2S_GetAllAlbumInfo());
  15. if (response != null)
  16. {
  17. if (response.Error == ErrorCode.ERR_Success)
  18. {
  19. return true;
  20. }
  21. }
  22. return false;
  23. }
  24. //获取图片的临时上传地址协议
  25. public static async ETTask<string[]> ReqTempPictureUrl(string pictureName)
  26. {
  27. S2C_GetTempPictureUrl response = null;
  28. response = (S2C_GetTempPictureUrl)await MessageHelper.SendToServer(new C2S_GetTempPictureUrl() { PictureName = pictureName });
  29. if (response != null)
  30. {
  31. if (response.Error == ErrorCode.ERR_Success)
  32. {
  33. return new string[] { response.TempPictureUrl, response.PictureObjectPath };
  34. }
  35. }
  36. return null;
  37. }
  38. //将图片上传到华为云
  39. public static string PushToHWCloud(string signUrl, byte[] buffer)
  40. {
  41. // 使用PUT请求上传对象
  42. HttpWebRequest webRequest = WebRequest.Create(signUrl) as HttpWebRequest;
  43. webRequest.Method = "PUT";
  44. webRequest.SendChunked = true;
  45. webRequest.AllowWriteStreamBuffering = false;
  46. using (Stream requestStream = webRequest.GetRequestStream())
  47. {
  48. requestStream.Write(buffer, 0, buffer.Length);
  49. }
  50. HttpWebResponse webResponse = null;
  51. try
  52. {
  53. webResponse = webRequest.GetResponse() as HttpWebResponse;
  54. return webResponse.StatusCode.ToString();
  55. }
  56. catch (WebException ex)
  57. {
  58. webResponse = ex.Response as HttpWebResponse;
  59. return "";
  60. }
  61. }
  62. //保存成功后,添加图片至相册
  63. public static async ETTask<bool> ReqAddTophoto(string pictureObjectPath, int sourceType)
  64. {
  65. S2C_AddPicture response = null;
  66. response = (S2C_AddPicture)await MessageHelper.SendToServer(new C2S_AddPicture() { PictureObjectPath = pictureObjectPath, SourceType = sourceType });
  67. if (response != null)
  68. {
  69. if (response.Error == ErrorCode.ERR_Success)
  70. {
  71. PoemPhotoData photoData = new PoemPhotoData();
  72. photoData.PictureId = response.PictureInfo.PictureId;
  73. photoData.CreationTime = response.PictureInfo.CreationTime;
  74. photoData.ToppingTime = response.PictureInfo.ToppingTime;
  75. photoData.ToppingStatus = response.PictureInfo.ToppingStatus;
  76. photoData.LockingStatus = response.PictureInfo.LockingStatus;
  77. photoData.PictureName = response.PictureInfo.PictureName;
  78. photoData.PictureTempUrl = response.PictureInfo.PictureTempUrl;
  79. PoemPhotoDataManager.Instance.Add(photoData, sourceType);
  80. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. //批量删除玩家相册
  87. public static async ETTask<bool> ReqRemovedPhoto(List<long> pictureIds, int sourceType)
  88. {
  89. S2C_RemovedPictures response = null;
  90. response = (S2C_RemovedPictures)await MessageHelper.SendToServer(new C2S_RemovedPictures() { PictureIds = pictureIds });
  91. if (response != null)
  92. {
  93. if (response.Error == ErrorCode.ERR_Success)
  94. {
  95. PoemPhotoDataManager.Instance.Remove(response.PictureIds, sourceType);
  96. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  97. return true;
  98. }
  99. }
  100. return false;
  101. }
  102. //修改图片锁定状态
  103. public static async ETTask<bool> ReqChangeLockingState(long pictureId, bool state, int sourceType)
  104. {
  105. S2C_UpPictureLockingStatus response = null;
  106. response = (S2C_UpPictureLockingStatus)await MessageHelper.SendToServer(new C2S_UpPictureLockingStatus() { PictureId = pictureId, Status = state });
  107. if (response != null)
  108. {
  109. if (response.Error == ErrorCode.ERR_Success)
  110. {
  111. PoemPhotoDataManager.Instance.ChangeLockingState(pictureId, state, sourceType);
  112. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118. //修改图片置顶状态
  119. public static async ETTask<bool> ReqChangeToppingState(long pictureId, bool state, int sourceType)
  120. {
  121. S2C_UpPictureToppingStatus response = null;
  122. response = (S2C_UpPictureToppingStatus)await MessageHelper.SendToServer(new C2S_UpPictureToppingStatus() { PictureId = pictureId, Status = state });
  123. if (response != null)
  124. {
  125. if (response.Error == ErrorCode.ERR_Success)
  126. {
  127. PoemPhotoDataManager.Instance.ChangeLockingState(pictureId, state, sourceType);
  128. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  129. return true;
  130. }
  131. }
  132. return false;
  133. }
  134. }
  135. }