| 
					
				 | 
			
			
				@@ -5,6 +5,7 @@ using UnityEngine.Networking; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using System.Text; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using GFGGame.Launcher; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using System.Reflection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+using System.Collections.Generic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -13,6 +14,10 @@ namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public class HttpTool : SingletonMonoBase<HttpTool> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //最大尝试次数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        const int TryTimes = 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //存储尝试次数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        public Dictionary<string, int> TryTimesDic = new Dictionary<string, int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public void Get(string url, Action<string> callback, bool showWrong = true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -27,15 +32,34 @@ namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public IEnumerator GetRequest(string url, Action<string> callback, bool showWrong) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ET.Log.Debug("get url : " + url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var key = url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ET.Log.Debug("get url : " + key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             using (UnityWebRequest webRequest = UnityWebRequest.Get(url)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 webRequest.timeout = LauncherConfig.HTTP_GET_TIME_OUT; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                TryTimesDic.TryGetValue(key, out var times); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                times++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                TryTimesDic[key] = times; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 yield return webRequest.SendWebRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ResultHandler(webRequest, callback, url, () => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ResultHandler(webRequest, callback, url, () =>  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    Get(url, callback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }, showWrong); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if(times < HttpTool.TryTimes) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        Get(url, callback, showWrong); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (showWrong) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            TryTimesDic.Remove(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Alert.Show("连接服务器失败:\n请检查网络和服务器状态") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .SetRightButton(true, "重试", (object data) => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Get(url, callback, showWrong); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -52,8 +76,8 @@ namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private IEnumerator PostRequest(string url, string body, Action<string> callback, string contentType, bool showWrong) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-             
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-             ET.Log.Debug(string.Format("post url:{0} postData:{1}", url, body)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var key = url + ":" + body; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ET.Log.Debug(string.Format($"post {key}", url, body)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             using (UnityWebRequest webRequest = new UnityWebRequest(url, "POST")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 byte[] bodyRaw = Encoding.UTF8.GetBytes(body); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -62,29 +86,39 @@ namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 webRequest.timeout = LauncherConfig.HTTP_POST_TIME_OUT; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //http header 的内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 webRequest.SetRequestHeader("Content-Type", contentType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                // webRequest.timeout; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                TryTimesDic.TryGetValue(key, out var times); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                times++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                TryTimesDic[key] = times; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 yield return webRequest.SendWebRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ResultHandler(webRequest, callback, body, () => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ResultHandler(webRequest, callback, key, () => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    Post(url, body, callback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }, showWrong); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (times < HttpTool.TryTimes) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        Post(url, body, callback,contentType, showWrong); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (showWrong) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            TryTimesDic.Remove(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Alert.Show("连接服务器失败:\n请检查网络和服务器状态") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .SetRightButton(true, "重试", (object data) => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Post(url, body, callback, contentType, showWrong); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        public void ResultHandler(UnityWebRequest webRequest, Action<string> callback, string tag, Action retryCall, bool showWrong) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        public void ResultHandler(UnityWebRequest webRequest, Action<string> callback, string tag, Action retryFunc) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             string paramCallback = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (webRequest.result == UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ET.Log.Error(webRequest.error + "\n" + webRequest.downloadHandler.text); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if(showWrong) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    Alert.Show("连接服务器失败:\n请检查网络和服务器状态") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .SetRightButton(true, "重试", (object data) => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        retryCall(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ET.Log.Error(webRequest.error + "\n" + webRequest.downloadHandler.text + "\nby " + tag); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                retryFunc?.Invoke(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 |