Browse Source

Merge branch 'master' into XRSDK_Phone

胡佳骏 1 năm trước cách đây
mục cha
commit
dfcc282487

+ 124 - 0
Samples~/SDK/GatewayHttp.cs

@@ -0,0 +1,124 @@
+using LitJson;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Text;
+using UnityEngine;
+using UnityEngine.Networking;
+
+public class GatewayHttp : MonoBehaviour
+{
+    string baseUrl = "https://api-fat1.ghz-tech.com/";
+    string username = "unity";
+    string password = "unitylisten";
+    Dictionary<string, string> requestHeader = new Dictionary<string, string>();  //  header
+    // Start is called before the first frame update
+    void Start()
+    {
+        
+        Debug.Log("Start Queue SendHttp Start" + Application.version);
+        Dictionary<string,string> data = new Dictionary<string, string>();
+        data.Add("username", username);
+        data.Add("password", password);
+        StartCoroutine(SendHttp("nacos/v1/auth/users/login", data,(string json)=> {
+
+            Debug.Log(json);
+            JsonData jdata = JsonMapper.ToObject(json);
+            Dictionary<string, string> data = new Dictionary<string, string>();
+            data.Add("dataId",Application.version);
+            data.Add("group", Application.productName);
+            data.Add("accessToken", jdata["accessToken"].ToString());
+            StartCoroutine(SendHttp("nacos/v1/cs/configs", data, (string json) =>
+            {
+                JsonData backData = JsonMapper.ToObject(json);
+                HttpSDKAction.Instance.jsonData = json;
+                string pt = "pro";
+#if UNITY_EDITOR
+                pt = "dev";
+#endif
+                HttpSDKAction.Instance.loginUrl = backData["unity"]["url"][pt]["login"].ToString();
+                HttpSDKAction.Instance.managerUrl = backData["unity"]["url"][pt]["manager"].ToString();
+                HttpSDKAction.Instance.officeSocket = backData["unity"]["url"][pt]["officeSocket"].ToString();
+                HttpSDKAction.Instance.pointCloudUrl = backData["unity"]["url"][pt]["pointCloud"].ToString();
+                HttpSDKAction.Instance.roomSocket = backData["unity"]["url"][pt]["roomSocket"].ToString();
+            },false));
+
+
+        }));
+    }
+
+    void test()
+    {
+
+        JsonData data = new JsonData();
+        data["unity"] = new JsonData();
+        data["unity"]["url"] = new JsonData();
+        data["unity"]["devuser"] = new JsonData();
+        data["unity"]["url"]["dev"] = new JsonData();
+        data["unity"]["url"]["fat"] = new JsonData();
+        data["unity"]["url"]["pro"] = new JsonData();
+        data["unity"]["url"]["dev"]["login"] = "";
+        data["unity"]["url"]["dev"]["manager"] = "";
+        data["unity"]["url"]["dev"]["pointCloud"] = "";
+        data["unity"]["url"]["dev"]["roomSocket"] = "";
+        data["unity"]["url"]["dev"]["officeSocket"] = "";
+        data["unity"]["url"]["fat"]["login"] = "";
+        data["unity"]["url"]["fat"]["manager"] = "";
+        data["unity"]["url"]["fat"]["pointCloud"] = "";
+        data["unity"]["url"]["fat"]["roomSocket"] = "";
+        data["unity"]["url"]["fat"]["officeSocket"] = "";
+        data["unity"]["url"]["pro"]["login"] = "";
+        data["unity"]["url"]["pro"]["manager"] = "";
+        data["unity"]["url"]["pro"]["pointCloud"] = "";
+        data["unity"]["url"]["pro"]["roomSocket"] = "";
+        data["unity"]["url"]["pro"]["officeSocket"] = "";
+        data["unity"]["user"]["111@111.com"] = "dev";
+
+        Debug.Log(data.ToJson());
+    }
+    public void initHead()
+    {
+        requestHeader.Clear();
+        requestHeader.Add("Content-Type", "application/x-www-form-urlencoded");
+    }
+
+    public IEnumerator SendHttp(string methodName, Dictionary<string, string> fromDic, Action<string> CallBack,bool isPost=true)
+    {
+        Debug.Log("Start Queue SendHttp " + methodName);
+        string url = baseUrl+ methodName;
+        UnityWebRequest webRequest;
+        if (!isPost)
+        {
+            url += "?";
+            foreach (var item in fromDic)
+            {
+                url+= item.Key +"="+item.Value+ "&";
+            }
+
+            webRequest = UnityWebRequest.Get(url);
+
+        }
+        else
+        {
+            WWWForm form = new WWWForm();
+            foreach (var item in fromDic)
+            {
+                form.AddField(item.Key, item.Value);
+            }
+            webRequest = UnityWebRequest.Post(url, form);
+            webRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+        }
+        yield return webRequest.SendWebRequest();
+        if (webRequest.result == UnityWebRequest.Result.ConnectionError)
+        {
+            Debug.LogError(webRequest.error);
+        }
+        else
+        {
+            string result = webRequest.downloadHandler.text;
+            CallBack(result);
+        }
+
+    }
+
+}

+ 11 - 0
Samples~/SDK/GatewayHttp.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8c732834f608cd64cbdb9615e27dd9a2
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 2
Samples~/SDK/Resources/GatewayHttp.prefab

@@ -42,10 +42,9 @@ MonoBehaviour:
   m_GameObject: {fileID: 6211819728071592439}
   m_Enabled: 1
   m_EditorHideFlags: 0
-  m_Script: {fileID: 11500000, guid: 6f8728bd52a6a4d47a2190fcccd461d1, type: 3}
+  m_Script: {fileID: 11500000, guid: 8c732834f608cd64cbdb9615e27dd9a2, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  AppName: 2
 --- !u!1001 &9165859205490109733
 PrefabInstance:
   m_ObjectHideFlags: 0