From 4b09a2b7d7aa94ebaf81e04561ad73f7be6e49df Mon Sep 17 00:00:00 2001 From: HuangZiBo <1278481331@qq.com> Date: Wed, 27 Nov 2024 19:07:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=9F=8E=E6=8E=A5=E5=8F=A32.*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Scripts/Login/Global.cs | 83 +++++++++++++++++++ .../Assets/Scripts/MallSystem2.meta | 8 ++ .../Scripts/MallSystem2/BuyProduct23.cs | 40 +++++++++ .../Scripts/MallSystem2/BuyProduct23.cs.meta | 11 +++ .../Scripts/MallSystem2/getMallList21.cs | 48 +++++++++++ .../Scripts/MallSystem2/getMallList21.cs.meta | 11 +++ .../Scripts/MallSystem2/productInfo22.cs | 64 ++++++++++++++ .../Scripts/MallSystem2/productInfo22.cs.meta | 11 +++ TheStrongestSnail/Assets/Scripts/onlyTest.cs | 28 +++++++ .../Assets/Scripts/onlyTest.cs.meta | 11 +++ 10 files changed, 315 insertions(+) create mode 100644 TheStrongestSnail/Assets/Scripts/MallSystem2.meta create mode 100644 TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs create mode 100644 TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs.meta create mode 100644 TheStrongestSnail/Assets/Scripts/MallSystem2/getMallList21.cs create mode 100644 TheStrongestSnail/Assets/Scripts/MallSystem2/getMallList21.cs.meta create mode 100644 TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs create mode 100644 TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs.meta create mode 100644 TheStrongestSnail/Assets/Scripts/onlyTest.cs create mode 100644 TheStrongestSnail/Assets/Scripts/onlyTest.cs.meta diff --git a/TheStrongestSnail/Assets/Scripts/Login/Global.cs b/TheStrongestSnail/Assets/Scripts/Login/Global.cs index e91e36f..1b769b7 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/Global.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/Global.cs @@ -829,4 +829,87 @@ public class AddressInfoData public string address { get; set; } public int status { get; set; } public string createTime { get; set; } +} +//2.1======================================================== +public class getMallListBody +{ + public int productType { get; set; }//商品类型,0实物商品,1虚拟商品 + public int pageNo { get; set; }//默认1 + public int pageSize { get; set; }//默认20 +} + +// 响应的最外层结构 +public class MallResponsePro:Response +{ + public MallDataPro Data { get; set; } +} + +// 内层 Data 结构 +public class MallDataPro +{ + public int PageNo { get; set; } + public int PageSize { get; set; } + public int TotalCount { get; set; } + public List DataList { get; set; } +} + +// 商品结构 +public class ProductPro +{ + public int ProductId { get; set; } + public int ProductType { get; set; } + public string ProductName { get; set; } + public string ProductPic { get; set; } + public string ProductCover { get; set; } + public float Price { get; set; } + public int SellOpen { get; set; } + public string CreateTime { get; set; } // CreateTime可能是 null,表示没有时间信息 +} +//2.1=================================================== +public class getProdectBody +{ + public int productId { get; set; } +} +[System.Serializable] +public class getProductResponse:Response +{ + public MallProduct Data; +} + +[System.Serializable] +public class MallProduct +{ + public int PageNo; + public int PageSize; + public int TotalCount; + public List DataList; +} + +[System.Serializable] +public class ProductInfo +{ + public int ProductId; + public int ProductType; + public string ProductName; + public string ProductPic; + public string ProductCover; + public float Price; + public int SellOpen; + public string CreateTime; // 可以是 null +} +//2.3============================================ +//请求体 +public class BuyProductBody +{ + public int productId;//商品ID + public int userId;//用户ID + public string receiveName;//接收者姓名 + public string receivePhone;//接收者手机 + public string area;//地址 + public string address;//区域 +} +//回 +public class BuyProductResponse : Response +{ + public string data; } \ No newline at end of file diff --git a/TheStrongestSnail/Assets/Scripts/MallSystem2.meta b/TheStrongestSnail/Assets/Scripts/MallSystem2.meta new file mode 100644 index 0000000..89dff22 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/MallSystem2.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 08391c44421d26c4da0f9025c9e570a5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs b/TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs new file mode 100644 index 0000000..925546b --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs @@ -0,0 +1,40 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; + +public class BuyProduct23 : MonoBehaviour +{ + public async Task BuyProduct(int productId, int userId, string receiveName, string receivePhone, string area, string address) + { + // ׼ͷϢȨ + Dictionary head23 = new Dictionary + { + { "Authorization", Global.global.serverResponse.data.token } + }; + + // + BuyProductBody BuyProductBody = new BuyProductBody + { + productId = productId, + userId = userId, + receiveName = receiveName, + receivePhone = receivePhone, + area = area, + address = address + }; + + Debug.Log("========" + JsonConvert.SerializeObject(BuyProductBody)); + // 첽 + string response23 = await web.SendRequest(web.URL + "/snail/product/buy", "POST", JsonConvert.SerializeObject(BuyProductBody), head23); + + // յӦ + Debug.Log("2.3Ʒ:=============== " + response23); + + // Ӧ JSON + BuyProductResponse buyProductResponse = JsonConvert.DeserializeObject(response23); + return buyProductResponse; + } +} diff --git a/TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs.meta b/TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs.meta new file mode 100644 index 0000000..7201a62 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 87a441003adbcf845b9fa739c0d3cc17 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TheStrongestSnail/Assets/Scripts/MallSystem2/getMallList21.cs b/TheStrongestSnail/Assets/Scripts/MallSystem2/getMallList21.cs new file mode 100644 index 0000000..80618b9 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/MallSystem2/getMallList21.cs @@ -0,0 +1,48 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +//2.1ȡ̳б +public class getMallList21 : MonoBehaviour +{ + public async Task getMallList(int productType, int pageNo, int pageSize) + { + // ׼ͷϢȨ + Dictionary head21 = new Dictionary + { + { "Authorization", Global.global.serverResponse.data.token } + }; + + // + getMallListBody getMallListBody = new getMallListBody + { + productType = productType, + pageNo = pageNo, + pageSize = pageSize + }; + + Debug.Log("========" + JsonConvert.SerializeObject(getMallListBody)); + // 첽 + string response21 = await web.SendRequest(web.URL + "/snail/product/page", "POST", JsonConvert.SerializeObject(getMallListBody), head21); + + // յӦ + Debug.Log("2.1̳б:=============== " + response21); + + // Ӧ JSON + MallResponsePro mallResponse = JsonConvert.DeserializeObject(response21); + + // ӦǷɹ + if (mallResponse.code == 200) + { + + } + else + { + // Ϣ + Debug.LogError("ʧ: " + mallResponse.message); + } + return mallResponse; + } +} diff --git a/TheStrongestSnail/Assets/Scripts/MallSystem2/getMallList21.cs.meta b/TheStrongestSnail/Assets/Scripts/MallSystem2/getMallList21.cs.meta new file mode 100644 index 0000000..b23dcd0 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/MallSystem2/getMallList21.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ca9b252d7b28cc24bbc556c52a77376b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs b/TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs new file mode 100644 index 0000000..9ad5ff9 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs @@ -0,0 +1,64 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; + +public class productInfo22 : MonoBehaviour +{ + //public async Task getMallList(int productType, int pageNo, int pageSize) + public async Task productInfo(int productId) + { + // ׼ͷϢȨ + Dictionary head22 = new Dictionary + { + { "Authorization", Global.global.serverResponse.data.token } + }; + + // + getProdectBody getProdectBody = new getProdectBody + { + productId = productId, + }; + + Debug.Log("========" + JsonConvert.SerializeObject(getProdectBody)); + // 첽 + string response22 = await web.SendRequest(web.URL + "/snail/product/page", "POST", JsonConvert.SerializeObject(getProdectBody), head22); + + // յӦ + Debug.Log("2.1̳б:=============== " + response22); + getProductResponse getProductResponse1 = new getProductResponse(); + try + { + // JSON ַлΪ MallResponse + getProductResponse1 = JsonConvert.DeserializeObject(response22); + + // пգȼ getProductResponse getProductResponse.data ǷΪ null + if (getProductResponse1 != null && getProductResponse1.Data != null && getProductResponse1.Data.DataList != null) + { + Debug.Log($"Total Products: {getProductResponse1.Data.DataList.Count}"); + + // Ʒб + foreach (var product in getProductResponse1.Data.DataList) + { + // ÿƷϢ + Debug.Log($"Product ID: {product.ProductId}"); + Debug.Log($"Product Name: {product.ProductName}"); + Debug.Log($"Product Price: {product.Price}"); + Debug.Log($"Product Pic: {product.ProductPic}"); + Debug.Log($"Product Cover: {product.ProductCover}"); + } + } + else + { + Debug.LogWarning("ӦΪջʽ"); + } + } + catch (Exception ex) + { + Debug.LogError("лӦʧ: " + ex.Message); + } + return getProductResponse1; + } +} diff --git a/TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs.meta b/TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs.meta new file mode 100644 index 0000000..304f1a2 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/MallSystem2/productInfo22.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bee78c26d1e96de47a8f948c5b0a1709 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TheStrongestSnail/Assets/Scripts/onlyTest.cs b/TheStrongestSnail/Assets/Scripts/onlyTest.cs new file mode 100644 index 0000000..8f1cb06 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/onlyTest.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class onlyTest : MonoBehaviour +{ + getMallList21 getMallList = new getMallList21(); + MallResponsePro response = new MallResponsePro(); + productInfo22 productInfo22 = new productInfo22(); + getProductResponse Response22 = new getProductResponse(); + BuyProduct23 BuyProduct23 = new BuyProduct23(); + BuyProductResponse buyProductResponse = new BuyProductResponse(); + queryPlayerInfo queryPlayerInfo =new queryPlayerInfo(); + async void Start() + { + Response22 =await productInfo22.productInfo(1); + //Debug.Log("============" + Response22.Data.DataList[1].ProductCover); + buyProductResponse = await BuyProduct23.BuyProduct(1,106,"541236987","","","̷ķԺ"); + Debug.Log(buyProductResponse.data+"+++++++++++++++++++++++++++++++"); + //queryPlayerInfo.QueryPlayerInfoPro(); + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/TheStrongestSnail/Assets/Scripts/onlyTest.cs.meta b/TheStrongestSnail/Assets/Scripts/onlyTest.cs.meta new file mode 100644 index 0000000..5ec9eb9 --- /dev/null +++ b/TheStrongestSnail/Assets/Scripts/onlyTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 28028d7efb1a95a4684cb6cef421f9b7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: