PoemPhotoSProxy.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. for (int i = 0; i < response.PictureInfosA.Count; i++)
  20. {
  21. PoemPhotoData photoData = new PoemPhotoData();
  22. photoData.PictureId = response.PictureInfosA[i].PictureId;
  23. photoData.CreationTime = response.PictureInfosA[i].CreationTime;
  24. photoData.ToppingTime = response.PictureInfosA[i].ToppingTime;
  25. photoData.ToppingStatus = response.PictureInfosA[i].ToppingStatus;
  26. photoData.LockingStatus = response.PictureInfosA[i].LockingStatus;
  27. photoData.PictureName = response.PictureInfosA[i].PictureName;
  28. photoData.PictureTempUrl = response.PictureInfosA[i].PictureTempUrl;
  29. byte[] bytes = DownloadFile(response.PictureInfosA[i].PictureTempUrl);
  30. photoData.Bytes = bytes;
  31. // photoData.Ntexture = PoemPhotoDataManager.Instance.BytesToTexture2D(bytes); ;
  32. PoemPhotoDataManager.Instance.Add(photoData, (int)PictureSourceType.PersonalAlbum);
  33. }
  34. for (int i = 0; i < response.PictureInfosB.Count; i++)
  35. {
  36. PoemPhotoData photoData = new PoemPhotoData();
  37. photoData.PictureId = response.PictureInfosB[i].PictureId;
  38. photoData.CreationTime = response.PictureInfosB[i].CreationTime;
  39. photoData.ToppingTime = response.PictureInfosB[i].ToppingTime;
  40. photoData.ToppingStatus = response.PictureInfosB[i].ToppingStatus;
  41. photoData.LockingStatus = response.PictureInfosB[i].LockingStatus;
  42. photoData.PictureName = response.PictureInfosB[i].PictureName;
  43. photoData.PictureTempUrl = response.PictureInfosB[i].PictureTempUrl;
  44. byte[] bytes = DownloadFile(response.PictureInfosB[i].PictureTempUrl);
  45. photoData.Bytes = bytes;
  46. // photoData.Ntexture = PoemPhotoDataManager.Instance.BytesToTexture2D(bytes); ;
  47. PoemPhotoDataManager.Instance.Add(photoData, (int)PictureSourceType.WanShuiQianShan);
  48. }
  49. return true;
  50. }
  51. }
  52. return false;
  53. }
  54. //获取图片的临时上传地址协议
  55. public static async ETTask<string[]> ReqTempPictureUrl(int pictureType)
  56. {
  57. ET.Log.Debug("zoya000");
  58. S2C_GetTempPictureUrl response = null;
  59. response = (S2C_GetTempPictureUrl)await MessageHelper.SendToServer(new C2S_GetTempPictureUrl() { PictureType = pictureType });
  60. ET.Log.Debug("zoya111");
  61. if (response != null)
  62. {
  63. if (response.Error == ErrorCode.ERR_Success)
  64. {
  65. ET.Log.Debug("zoya222");
  66. return new string[] { response.TempPictureUrl, response.PictureObjectPath };
  67. }
  68. }
  69. return null;
  70. }
  71. //将图片上传到华为云
  72. public static string PushToHWCloud(string signUrl, byte[] buffer)
  73. {
  74. ET.Log.Debug("zoya333" + buffer);
  75. // 使用PUT请求上传对象
  76. HttpWebRequest webRequest = WebRequest.Create(signUrl) as HttpWebRequest;
  77. webRequest.Method = "PUT";
  78. webRequest.SendChunked = true;
  79. webRequest.AllowWriteStreamBuffering = false;
  80. using (Stream requestStream = webRequest.GetRequestStream())
  81. {
  82. requestStream.Write(buffer, 0, buffer.Length);
  83. }
  84. HttpWebResponse webResponse = null;
  85. try
  86. {
  87. ET.Log.Debug("zoya444");
  88. webResponse = webRequest.GetResponse() as HttpWebResponse;
  89. return webResponse.StatusCode.ToString();
  90. }
  91. catch (WebException ex)
  92. {
  93. ET.Log.Debug("zoya555");
  94. webResponse = ex.Response as HttpWebResponse;
  95. return "";
  96. }
  97. }
  98. //保存成功后,添加图片至相册
  99. public static async ETTask<bool> ReqAddTophoto(string pictureObjectPath, int sourceType)
  100. {
  101. ET.Log.Debug("zoya666");
  102. S2C_AddPicture response = null;
  103. response = (S2C_AddPicture)await MessageHelper.SendToServer(new C2S_AddPicture() { PictureObjectPath = pictureObjectPath, SourceType = sourceType });
  104. ET.Log.Debug("zoya777");
  105. if (response != null)
  106. {
  107. if (response.Error == ErrorCode.ERR_Success)
  108. {
  109. ET.Log.Debug("zoya888");
  110. PoemPhotoData photoData = new PoemPhotoData();
  111. photoData.PictureId = response.PictureInfo.PictureId;
  112. photoData.CreationTime = response.PictureInfo.CreationTime;
  113. photoData.ToppingTime = response.PictureInfo.ToppingTime;
  114. photoData.ToppingStatus = response.PictureInfo.ToppingStatus;
  115. photoData.LockingStatus = response.PictureInfo.LockingStatus;
  116. photoData.PictureName = response.PictureInfo.PictureName;
  117. photoData.PictureTempUrl = response.PictureInfo.PictureTempUrl;
  118. ET.Log.Debug("zoya999");
  119. byte[] bytes = DownloadFile(photoData.PictureTempUrl);
  120. ET.Log.Debug("zoyafff");
  121. photoData.Bytes = bytes;
  122. PoemPhotoDataManager.Instance.Add(photoData, sourceType);
  123. ET.Log.Debug("zoyajjj");
  124. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  125. PromptController.Instance.ShowFloatTextPrompt("已保存至相册");
  126. return true;
  127. }
  128. }
  129. return false;
  130. }
  131. public static byte[] DownloadFile(string URL)
  132. {
  133. try
  134. {
  135. ET.Log.Debug("zoyaaaa");
  136. HttpWebRequest webRequest = HttpWebRequest.Create(URL) as HttpWebRequest;
  137. webRequest.Method = "GET";
  138. HttpWebResponse webResponse = webRequest.GetResponse() as HttpWebResponse;
  139. System.IO.Stream st = webResponse.GetResponseStream();
  140. ET.Log.Debug("zoyabbb");
  141. byte[] bytes;
  142. using (var ms = new MemoryStream())
  143. {
  144. st.CopyTo(ms);
  145. bytes = ms.ToArray();
  146. }
  147. ET.Log.Debug("zoyaccc");
  148. st.Close();
  149. webResponse.Close();
  150. webRequest.Abort();
  151. ET.Log.Debug("zoyaddd");
  152. return bytes;
  153. }
  154. catch (WebException ex)
  155. {
  156. ET.Log.Debug("zoyaeee");
  157. // webResponse = ex.Response as HttpWebResponse;
  158. ET.Log.Debug(ex.Response.ToString());
  159. return null;
  160. }
  161. }
  162. //批量删除玩家相册
  163. public static async ETTask<bool> ReqRemovedPhoto(List<long> pictureIds, int sourceType)
  164. {
  165. S2C_RemovedPictures response = null;
  166. response = (S2C_RemovedPictures)await MessageHelper.SendToServer(new C2S_RemovedPictures() { PictureIds = pictureIds });
  167. if (response != null)
  168. {
  169. if (response.Error == ErrorCode.ERR_Success)
  170. {
  171. PoemPhotoDataManager.Instance.Remove(response.PictureIds, sourceType);
  172. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  173. return true;
  174. }
  175. }
  176. return false;
  177. }
  178. //修改图片锁定状态
  179. public static async ETTask<bool> ReqChangeLockingState(long pictureId, bool state, int sourceType)
  180. {
  181. S2C_UpPictureLockingStatus response = null;
  182. response = (S2C_UpPictureLockingStatus)await MessageHelper.SendToServer(new C2S_UpPictureLockingStatus() { PictureId = pictureId, Status = state });
  183. if (response != null)
  184. {
  185. if (response.Error == ErrorCode.ERR_Success)
  186. {
  187. PoemPhotoDataManager.Instance.ChangeLockingState(response.PictureId, response.Status, sourceType);
  188. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  189. return true;
  190. }
  191. }
  192. return false;
  193. }
  194. //修改图片置顶状态
  195. public static async ETTask<bool> ReqChangeToppingState(long pictureId, bool state, int sourceType)
  196. {
  197. S2C_UpPictureToppingStatus response = null;
  198. response = (S2C_UpPictureToppingStatus)await MessageHelper.SendToServer(new C2S_UpPictureToppingStatus() { PictureId = pictureId, Status = state });
  199. if (response != null)
  200. {
  201. if (response.Error == ErrorCode.ERR_Success)
  202. {
  203. PoemPhotoDataManager.Instance.ChangeToppingState(response.PictureId, response.Status, sourceType);
  204. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  205. return true;
  206. }
  207. }
  208. return false;
  209. }
  210. }
  211. }