Compare commits
2 Commits
a94daba6fa
...
8a9efc2dfe
Author | SHA1 | Date | |
---|---|---|---|
8a9efc2dfe | |||
4b09a2b7d7 |
@ -829,4 +829,87 @@ public class AddressInfoData
|
|||||||
public string address { get; set; }
|
public string address { get; set; }
|
||||||
public int status { get; set; }
|
public int status { get; set; }
|
||||||
public string createTime { 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<ProductPro> 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<ProductInfo> 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;
|
||||||
}
|
}
|
8
TheStrongestSnail/Assets/Scripts/MallSystem2.meta
Normal file
8
TheStrongestSnail/Assets/Scripts/MallSystem2.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 08391c44421d26c4da0f9025c9e570a5
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
40
TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs
Normal file
40
TheStrongestSnail/Assets/Scripts/MallSystem2/BuyProduct23.cs
Normal file
@ -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<BuyProductResponse> BuyProduct(int productId, int userId, string receiveName, string receivePhone, string area, string address)
|
||||||
|
{
|
||||||
|
// 准备请求的头部信息,包含授权令牌
|
||||||
|
Dictionary<string, string> head23 = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "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<BuyProductResponse>(response23);
|
||||||
|
return buyProductResponse;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 87a441003adbcf845b9fa739c0d3cc17
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -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<MallResponsePro> getMallList(int productType, int pageNo, int pageSize)
|
||||||
|
{
|
||||||
|
// 准备请求的头部信息,包含授权令牌
|
||||||
|
Dictionary<string, string> head21 = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "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<MallResponsePro>(response21);
|
||||||
|
|
||||||
|
// 检查响应是否成功
|
||||||
|
if (mallResponse.code == 200)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 处理错误信息
|
||||||
|
Debug.LogError("请求失败: " + mallResponse.message);
|
||||||
|
}
|
||||||
|
return mallResponse;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ca9b252d7b28cc24bbc556c52a77376b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -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<MallResponsePro> getMallList(int productType, int pageNo, int pageSize)
|
||||||
|
public async Task<getProductResponse> productInfo(int productId)
|
||||||
|
{
|
||||||
|
// 准备请求的头部信息,包含授权令牌
|
||||||
|
Dictionary<string, string> head22 = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "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<getProductResponse>(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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bee78c26d1e96de47a8f948c5b0a1709
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
28
TheStrongestSnail/Assets/Scripts/onlyTest.cs
Normal file
28
TheStrongestSnail/Assets/Scripts/onlyTest.cs
Normal file
@ -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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
TheStrongestSnail/Assets/Scripts/onlyTest.cs.meta
Normal file
11
TheStrongestSnail/Assets/Scripts/onlyTest.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 28028d7efb1a95a4684cb6cef421f9b7
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user