zhaoyang %!s(int64=2) %!d(string=hai) anos
pai
achega
26a2e49e58

+ 14 - 64
GameClient/Assets/Game/HotUpdate/ServerProxy/PoemPhotoSProxy.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
@@ -70,41 +71,23 @@ namespace GFGGame
         }
 
         //将图片上传到华为云
-        public static string PushToHWCloud(string signUrl, byte[] buffer)
+        public static IEnumerator PushToHWCloud(string signUrl, byte[] buffer, Action callback)
         {
-            ET.Log.Debug("zoya:000" + signUrl);
-            // 使用PUT请求上传对象
-            HttpWebRequest webRequest = WebRequest.Create(signUrl) as HttpWebRequest;
-            webRequest.Method = "PUT";
-            ET.Log.Debug("zoya:111" + webRequest);
-
-            webRequest.SendChunked = true;
-            webRequest.AllowWriteStreamBuffering = false;
-            ET.Log.Debug("zoya:222" + webRequest);
-
-            using (Stream requestStream = webRequest.GetRequestStream())
+            using (UnityWebRequest www = UnityWebRequest.Put(signUrl, buffer))
             {
-                ET.Log.Debug("zoya:333" + webRequest);
+                yield return www.SendWebRequest();
 
-                requestStream.Write(buffer, 0, buffer.Length);
+                if (www.result != UnityWebRequest.Result.Success)
+                {
+                    Debug.Log(www.error);
+                    callback?.Invoke();
+                }
+                else
+                {
+                    Debug.Log("Upload complete!");
+                }
             }
 
-
-            HttpWebResponse webResponse = null;
-            try
-            {
-                ET.Log.Debug("zoya:444" + webRequest);
-
-                webResponse = webRequest.GetResponse() as HttpWebResponse;
-                ET.Log.Debug("zoya:555" + webRequest);
-
-                return webResponse.StatusCode.ToString();
-            }
-            catch (WebException ex)
-            {
-                webResponse = ex.Response as HttpWebResponse;
-                return "";
-            }
         }
         //保存成功后,添加图片至相册
         public static async ETTask<long> ReqAddTophoto(string pictureObjectPath, int sourceType)
@@ -136,46 +119,13 @@ namespace GFGGame
         }
         public static IEnumerator DownloadFile(PoemPhotoData poemPhotoData)
         {
+
             using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(poemPhotoData.PictureTempUrl))
             {
                 yield return request.SendWebRequest();
                 Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
                 poemPhotoData.Ntexture = new NTexture(texture);
             }
-            // try
-            // {
-
-            //     HttpWebRequest webRequest = HttpWebRequest.Create(poemPhotoData.PictureTempUrl) as HttpWebRequest;
-            //     webRequest.Method = "GET";
-            //     ET.Log.Debug("zoyabbb+Method:" + webRequest.Method);
-
-            //     HttpWebResponse webResponse = webRequest.GetResponse() as HttpWebResponse;
-            //     ET.Log.Debug("zoyabbb" + webResponse);
-
-            //     System.IO.Stream st = webResponse.GetResponseStream();
-            //     ET.Log.Debug("zoyabbb+st:" + st);
-
-            //     byte[] bytes;
-            //     using (var ms = new MemoryStream())
-            //     {
-            //         st.CopyTo(ms);
-            //         bytes = ms.ToArray();
-            //     }
-            //     ET.Log.Debug("zoyaccc");
-
-            //     st.Close();
-            //     webResponse.Close();
-            //     webRequest.Abort();
-            //     ET.Log.Debug("zoyaddd");
-            //     poemPhotoData.Bytes = bytes;
-            // }
-            // catch (WebException ex)
-            // {
-            //     ET.Log.Debug("zoyaeee");
-
-            //     //  webResponse = ex.Response as HttpWebResponse;
-            //     ET.Log.Debug(ex.Response.ToString());
-            // }
 
         }
         //批量删除玩家相册

+ 14 - 12
GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographSaveView.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
+using System.Threading.Tasks;
 using ET;
 using FairyGUI;
 using UI.DressUp;
@@ -79,25 +80,26 @@ namespace GFGGame
             string[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl((int)PictureType.jpg);
             if (rsp == null) return;
 
-            string code = PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes);
-            if (string.IsNullOrEmpty(code)) return;
-
-            long result = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
-
-            if (result > 0)
+            Timers.inst.StartCoroutine(PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes, async () =>
             {
-                List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
+                long result = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
 
-                for (int i = 0; i < list.Count; i++)
+                if (result > 0)
                 {
-                    if (list[i].PictureId == result)
+                    List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
+
+                    for (int i = 0; i < list.Count; i++)
                     {
-                        list[i].Ntexture = new NTexture(tex);
+                        if (list[i].PictureId == result)
+                        {
+                            list[i].Ntexture = new NTexture(tex);
 
-                        break;
+                            break;
+                        }
                     }
                 }
-            }
+            }));
+
         }
     }
 }