diff --git a/TheStrongestSnail/Assets/Scenes/logo.unity b/TheStrongestSnail/Assets/Scenes/logo.unity index 5c9a0fa..2c49d77 100644 --- a/TheStrongestSnail/Assets/Scenes/logo.unity +++ b/TheStrongestSnail/Assets/Scenes/logo.unity @@ -4584,6 +4584,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1789203781} + - component: {fileID: 1789203785} - component: {fileID: 1789203784} - component: {fileID: 1789203783} - component: {fileID: 1789203782} @@ -4618,7 +4619,7 @@ MonoBehaviour: m_GameObject: {fileID: 1789203778} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: db50a6d583762ea45b20d705d0e068cd, type: 3} + m_Script: {fileID: 11500000, guid: 9e50b3d02b729854e87c092afffd2a03, type: 3} m_Name: m_EditorClassIdentifier: --- !u!114 &1789203783 @@ -4640,11 +4641,23 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1789203778} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 8ee1a43c8ad7f8c41bad48013bf5af49, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &1789203785 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1789203778} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: db50a6d583762ea45b20d705d0e068cd, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1850703526 GameObject: m_ObjectHideFlags: 0 diff --git a/TheStrongestSnail/Assets/Scripts/Login/LoginAndGetToken.cs b/TheStrongestSnail/Assets/Scripts/Login/LoginAndGetToken.cs index 5060fd8..441b4a1 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/LoginAndGetToken.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/LoginAndGetToken.cs @@ -15,10 +15,10 @@ public class LoginAndGetToken : MonoBehaviour private void OnEnable() { - //Login(); + Login(); } - public async void Login() + public async void Login() { // ... 登录逻辑 ... loginbody body = new loginbody(); diff --git a/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs b/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs index 1fba2a4..6fbaf5e 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs @@ -1,4 +1,4 @@ -using System; +/*using System; using System.Collections; using System.Collections.Generic; using System.Xml.Linq; @@ -52,7 +52,7 @@ public class WebConnact : MonoBehaviour Debug.Log("使用最新的 escapeId: " + escapeId); // 你剩下的网络请求逻辑 - // 例如:在需要用到 escapeId 的地方直接使用它 + //例如:在需要用到 escapeId 的地方直接使用它 //1.3,完善用户信息//已通过 User_InformationHead user = new User_InformationHead(); @@ -72,7 +72,7 @@ public class WebConnact : MonoBehaviour string response13 = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", UserNewInfoBody, head13); Debug.Log("1.3完善用户信息" + response13); - ////1.4查询用户详情(新增) + //1.4查询用户详情(新增) Dictionary head14 = new Dictionary { { "Authorization", Authorization }, // 设置授权头 @@ -159,7 +159,7 @@ public class WebConnact : MonoBehaviour string response42 = await web.SendRequest("http://121.40.42.41:8080/snail/cutePool/buy", "POST", buyCutePool, head42); Debug.Log("购买欢乐豆" + response42); - //============================================================================================================================ + //// ============================================================================================================================ //5.1查询最近一场大屠杀 Dictionary head51 = new Dictionary @@ -169,7 +169,7 @@ public class WebConnact : MonoBehaviour // 使用最新的 escapeId 在请求体中 string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51); Debug.Log("5.1查询最近一场大屠杀: " + response51); - //==================================================================================================================== + //// ==================================================================================================================== @@ -217,7 +217,7 @@ public class WebConnact : MonoBehaviour string response514 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", selectKill, head514); Debug.Log("5.1.4,查询击杀:" + response514); - //5.1.5,查询结算 + ////5.1.5,查询结算 Dictionary head515 = new Dictionary { { "Authorization", Authorization }, // 设置授权头 @@ -244,248 +244,11 @@ public class WebConnact : MonoBehaviour } } -/*public class WebConnact : MonoBehaviour -{ - - void Start() - { - //由于除登录注册外的其他方法,都需要登录后返回的token - //因此登录不在此发送请求(同时) - //采用监听和事件回调的方法,只有监听到登录和token返回时,才运行其他方法 - LoginAndGetToken.OnTokenReceived += HandleTokenReceived; - //Loding(); - // 订阅事件,当 gameEscapeId 更新时调用 HandleGameEscapeIdUpdated - selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; - } - - void HandleTokenReceived(string token) - { - // 使用 token - //string loginToken=token; - Debug.Log("HandleTokenReceived监听:"+token); - Loding(token); - } - void HandleGameEscapeIdUpdated(int newGameEscapeId) - { - Debug.Log("GameEscapeId 已更新为: " + newGameEscapeId); - // 在这里添加你想要执行的逻辑 - } - - // 传入 token 和更新后的 escapeId - public async void Loding(string token, int newGameEscapeId) - { - // 用来给请求头赋值 - string Authorization = token; - Debug.Log("Loding(Authorization)请求头赋值" + Authorization); - - // 如果 newGameEscapeId 不是初始值(-1),则使用它 - int escapeId = newGameEscapeId != -1 ? newGameEscapeId : 0; - - Debug.Log("使用最新的 escapeId: " + escapeId); - - //loginbody body = new loginbody(); - //body.userName = "15151658596";// + 15151658596; - //body.password = "123456";// + 123456; - //body.verifyCode = 111111; - //string regisestrespose = await web.SendRequest("http://121.40.42.41:8080/snail/user/register", "POST", JsonUtility.ToJson(body)); - //Debug.Log(regisestrespose); - //注册请求 //已通过 - - - //loginbody body = new loginbody(); - //body.userName = "15151658596";// + 15151658596; - //body.password = "123456";// + 123456; - //body.verifyCode = 111111; - //string loginResponse = await web.SendRequest("http://121.40.42.41:8080/snail/user/login", "POST", JsonUtility.ToJson(body)); - //Debug.Log(loginResponse); - //登录请求//已通过 - - - ////1.3,完善用户信息//已通过 - ////User_InformationHead user = new User_InformationHead(); - //Dictionary head13 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //string UserNewInfoBody = @" - // { - // ""nickName"": ""wulongxiao"", - // ""headImg"": ""https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png"", - // ""gender"": 1, - // ""birthday"": ""2023-12-12 12:12:12"" - // }"; - ////打印 JSON 请求体,用于调试 - //Debug.Log("JSON Request Data: " + UserNewInfoBody); - //string response13 = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", UserNewInfoBody, head13); - //Debug.Log("1.3完善用户信息" + response13); - - ////1.4查询用户详情(新增) - //Dictionary head14 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //string response14 = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", head14); - //Debug.Log("1.4查询用户详情" + response14); - - ////2.1商城列表//已通过 - //Mall_List mall_virtual = new Mall_List(); - //mall_virtual.productType = 0; - //mall_virtual.pageNo = 1; - //mall_virtual.pageSize = 20; - //string mall_virtualponse = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall_virtual)); - //Debug.Log("2.1商城列表:" + mall_virtualponse); - - ////2.1,商城列表//已通过 - //Mall_List mall = new Mall_List(); - //mall.productType = 1; - ////mall.pageNo = 1; - ////mall.pageSize = 20;//这两个属性是默认值可以省略不写,默认是1跟20 - //string response21 = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall)); - //Debug.Log("2.1商城列表:" + response21); - - ////2.2,获取商城商品详情//已通过 - //Dictionary head22 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //Product_Details product = new Product_Details(); - //product.productId = 1; - //string response22 = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(product), head22); - //Debug.Log("JSON Request Data: " + JsonUtility.ToJson(product)); - //Debug.Log("2.2,获取商城商品详情" + response22); - - ////2.3,商品购买(无支付)//已通过 - //Mall_buy mall_Buy = new Mall_buy(); - //Dictionary head23 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //mall_Buy.userId = 106; - //mall_Buy.productId = 1; - //string response23 = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mall_Buy), head23); - //Debug.Log("2.3,商品购买(无支付)" + response23); - - ////3.1,查询公告分页://已通过 - //Query_Announcement query_Announcement = new Query_Announcement(); - //query_Announcement.userId = 106; - //query_Announcement.pageNo = 1; - //query_Announcement.pageSize = 20; - //string response31 = await web.SendRequest("http://121.40.42.41:8080/snail/notice/page", "POST", JsonUtility.ToJson(query_Announcement)); - //Debug.Log("3.1,查询公告分页:" + response31); - - ////3.2,查询公告详情://已通过 - //int AnnouncementId = 1; - //string response32 = await web.SendRequest($"http://121.40.42.41:8080/snail/notice/info?noticeId={AnnouncementId}", "GET"); - //Debug.Log("3.2,查询公告详情:" + response32); - - ////4.1查询靓号池分页//已通过 - //Dictionary head41 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //int orderByBeansCoin = 1; - //string response41 = await web.SendRequest("http://121.40.42.41:8080/snail/cutePool/page", "POST", JsonUtility.ToJson(orderByBeansCoin), head41); - //Debug.Log("查询靓号池分页" + response41); - - ////4.2购买欢乐豆//已通过 - //Dictionary head42 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //string buyCutePool = @" - // { - // ""userId"": 106, - // ""cutePoolId"": 2 - // }"; - ////打印 JSON 请求体,用于调试 - //Debug.Log("JSON Request Data: " + buyCutePool); - //string response42 = await web.SendRequest("http://121.40.42.41:8080/snail/cutePool/buy", "POST", buyCutePool, head42); - //Debug.Log("购买欢乐豆" + response42); - - - - ////5.1查询最近一场大屠杀//已通过 - //Dictionary head51 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51); - //Debug.Log("5.1查询最近一场大屠杀" + response51);//查询最近一场大逃亡游戏详情: - - ////5.1.2查询各大逃亡房间最新详情(高性能版) - //Dictionary head512 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //string queryEscapeRoomListBody = @" - // { - // ""userId"": 106, - // ""escapeId"": 24336 - // }"; - //string response512 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", queryEscapeRoomListBody, head512); - //Debug.Log("5.1.2查询各大逃亡房间最新详情(高性能版)" + response512); - - ////5.1.3,用户下注: - //Dictionary head513 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //string userBetBody = @" - // { - // ""userId"": 106, - // ""escapeId"": 24381, - // ""bet"": 100, - // ""roomNo"":1 - // }"; - //string response513 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", userBetBody, head513); - //Debug.Log("5.1.3,用户下注:" + response513); - - //5.1.4,查询击杀 - Dictionary head514 = new Dictionary - { - { "Authorization", Authorization }, // 设置授权头 - }; - string selectKill = @" - { - ""userId"": 106, - ""escapeId"": {escapeId} - }"; - string response514 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", selectKill, head514); - Debug.Log("5.1.4,查询击杀:" + response514); - - //////5.1.5,查询结算 - //Dictionary head515 = new Dictionary - //{ - // { "Authorization", Authorization }, // 设置授权头 - // }; - //string queryUserBetResult = @" - // { - // ""userId"": 106, - // ""escapeId"": 24377 - // }"; - //string response515 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", queryUserBetResult, head515); - //Debug.Log("5.1.5,查询结算:" + response515); - - //=========================================================================================================================== - - } - void OnDestroy() - { - LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; - } - // Update is called once per frame - void Update() - { - - } -}*/ [Serializable] public class Search_room//登录和注册用 { public int userId; - - } @@ -539,5 +302,970 @@ public class Mall_buy public class cutePoolPage { public int orderByBeansCoin; } +*/ + +/*using System; +using System.Collections; +using System.Collections.Generic; +using System.Xml.Linq; +using UnityEngine; +using UnityEngine.Networking; +using System.Threading.Tasks; +using Newtonsoft.Json; + +public class WebConnact : MonoBehaviour +{ + private string token; // 保存 token 以便在整个类中使用 + + void Start() + { + // 注册监听事件,当收到 token 时,触发 HandleTokenReceived + LoginAndGetToken.OnTokenReceived += HandleTokenReceived; + + // 订阅事件,当 gameEscapeId 更新时调用 HandleGameEscapeIdUpdated + selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + } + + // 当接收到 token 时触发此方法 + void HandleTokenReceived(string receivedToken) + { + token = receivedToken; // 保存 token + // 首次调用加载初始数据 + LoadInitialData(token); + } + + // 当游戏逃亡 ID 更新时触发此方法 + void HandleGameEscapeIdUpdated(int newGameEscapeId) + { + Debug.Log("GameEscapeId 已更新为: " + newGameEscapeId); + // 加载游戏逃亡相关数据 + LoadGameEscapeData(token, newGameEscapeId); + } + + // 加载初始数据 + private async void LoadInitialData(string token) + { + // 更新用户信息 + await UpdateUserInformation(token); + // 查询用户详细信息 + await QueryUserDetails(token); + // 加载商城数据 + await LoadMallData(token); + } + + // 加载游戏逃亡数据 + private async void LoadGameEscapeData(string token, int escapeId) + { + // 查询最近的大屠杀 + await QueryLatestMassacre(token); + // 查询逃亡房间详情 + await QueryEscapeRoomDetails(token, escapeId); + // 用户下注 + await UserBet(token, escapeId); + // 查询击杀数据 + await QueryKill(token, escapeId); + // 查询用户结算 + await QueryUserBetResult(token, escapeId); + } + + // 更新用户信息 + private async Task UpdateUserInformation(string token) + { + var headers = CreateHeaders(token); + string body = @" + { + ""nickName"": ""wulongxiao"", + ""headImg"": ""https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png"", + ""gender"": 1, + ""birthday"": ""2023-12-12 12:12:12"" + }"; + Debug.Log("正在更新用户信息..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", body, headers); + Debug.Log("更新用户信息响应: " + response); + } + + // 查询用户详情 + private async Task QueryUserDetails(string token) + { + var headers = CreateHeaders(token); + Debug.Log("正在查询用户详细信息..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", headers); + Debug.Log("查询用户详细信息响应: " + response); + return response; + } + + // 加载商城数据 + private async Task LoadMallData(string token) + { + // 查询商城虚拟商品列表 + await QueryMallList(token, 0); + // 查询商城实体商品列表 + await QueryMallList(token, 1); + // 获取商品详情 + await GetMallProductDetails(token, 1); + // 购买商品 + await BuyMallProduct(token, 106, 1); + } + + // 查询商城列表 + private async Task QueryMallList(string token, int productType) + { + Mall_List mallList = new Mall_List + { + productType = productType + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mallList)); + Debug.Log($"商城列表 (productType: {productType}) 响应: " + response); + } + + // 获取商城商品详情 + private async Task GetMallProductDetails(string token, int productId) + { + var headers = CreateHeaders(token); + Product_Details productDetails = new Product_Details + { + productId = productId + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(productDetails), headers); + Debug.Log("获取商品详情响应: " + response); + } + + // 购买商品 + private async Task BuyMallProduct(string token, int userId, int productId) + { + var headers = CreateHeaders(token); + Mall_buy mallBuy = new Mall_buy + { + userId = userId, + productId = productId + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mallBuy), headers); + Debug.Log("购买商品响应: " + response); + } + + // 查询最近的大屠杀 + private async Task QueryLatestMassacre(string token) + { + var headers = CreateHeaders(token); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", headers); + Debug.Log("查询最近大屠杀响应: " + response); + } + + // 查询逃亡房间详情 + private async Task QueryEscapeRoomDetails(string token, int escapeId) + { + var headers = CreateHeaders(token); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); + Debug.Log("逃亡房间详情响应: " + response); + } + + // 用户下注 + private async Task UserBet(string token, int escapeId) + { + var headers = CreateHeaders(token); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId}, + ""bet"": 100, + ""roomNo"": 1 + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + Debug.Log("用户下注响应: " + response); + } + + // 查询击杀信息 + private async Task QueryKill(string token, int escapeId) + { + var headers = CreateHeaders(token); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); + Debug.Log("查询击杀信息响应: " + response); + } + + // 查询用户下注结果 + private async Task QueryUserBetResult(string token, int escapeId) + { + var headers = CreateHeaders(token); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + Debug.Log("查询用户下注结果响应: " + response); + } + + // 创建请求头 + private Dictionary CreateHeaders(string token) + { + return new Dictionary + { + { "Authorization", token } + }; + } + + void OnDestroy() + { + // 注销监听事件,避免内存泄漏 + LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; + selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + } + + // Update 方法保留,但当前没有需要的功能 + void Update() + { + } +}*/ + +/*using System; +using System.Collections; +using System.Collections.Generic; +using System.Xml.Linq; +using UnityEngine; +using UnityEngine.Networking; +using System.Threading.Tasks; +using Newtonsoft.Json; + +public class WebConnact : MonoBehaviour +{ + private string token; // 保存 token 以便在整个类中使用 + private int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 + + void Start() + { + // 注册监听事件,当收到 token 时,触发 HandleTokenReceived + LoginAndGetToken.OnTokenReceived += HandleTokenReceived; + + // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated + selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + } + + // 当接收到 token 时触发此方法 + void HandleTokenReceived(string receivedToken) + { + token = receivedToken; // 保存 token + // 首次调用加载初始数据 + LoadInitialData(token); + } + + // 当游戏逃亡 ID 更新时触发此方法 + void HandleGameEscapeIdUpdated(int newGameEscapeId) + { + escapeId = newGameEscapeId; // 保存最新的 escapeId + Debug.Log("接收到新的 GameEscapeId: " + escapeId); + + // 调用加载逃亡游戏相关数据的方法 + LoadGameEscapeData(token, escapeId); + } + + // 加载初始数据 + private async void LoadInitialData(string token) + { + // 更新用户信息 + await UpdateUserInformation(token); + // 查询用户详细信息 + await QueryUserDetails(token); + // 加载商城数据 + await LoadMallData(token); + } + + // 加载游戏逃亡数据 + private async void LoadGameEscapeData(string token, int escapeId) + { + if (escapeId == -1) + { + Debug.LogWarning("无法加载游戏逃亡数据,escapeId 未设置。"); + return; + } + + // 查询最近的大屠杀 + await QueryLatestMassacre(token); + // 查询逃亡房间详情 + await QueryEscapeRoomDetails(token, escapeId); + // 用户下注 + await UserBet(token, escapeId); + // 查询击杀数据 + await QueryKill(token, escapeId); + // 查询用户结算 + await QueryUserBetResult(token, escapeId); + } + + // 更新用户信息 + private async Task UpdateUserInformation(string token) + { + var headers = CreateHeaders(token); + string body = @" + { + ""nickName"": ""wulongxiao"", + ""headImg"": ""https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png"", + ""gender"": 1, + ""birthday"": ""2023-12-12 12:12:12"" + }"; + Debug.Log("正在更新用户信息..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", body, headers); + Debug.Log("更新用户信息响应: " + response); + } + + // 查询用户详情 + private async Task QueryUserDetails(string token) + { + var headers = CreateHeaders(token); + Debug.Log("正在查询用户详细信息..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", headers); + Debug.Log("查询用户详细信息响应: " + response); + return response; + } + + // 加载商城数据 + private async Task LoadMallData(string token) + { + // 查询商城虚拟商品列表 + await QueryMallList(token, 0); + // 查询商城实体商品列表 + await QueryMallList(token, 1); + // 获取商品详情 + await GetMallProductDetails(token, 1); + // 购买商品 + await BuyMallProduct(token, 106, 1); + } + + // 查询商城列表 + private async Task QueryMallList(string token, int productType) + { + Mall_List mallList = new Mall_List + { + productType = productType + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mallList)); + Debug.Log($"商城列表 (productType: {productType}) 响应: " + response); + } + + // 获取商城商品详情 + private async Task GetMallProductDetails(string token, int productId) + { + var headers = CreateHeaders(token); + Product_Details productDetails = new Product_Details + { + productId = productId + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(productDetails), headers); + Debug.Log("获取商品详情响应: " + response); + } + + // 购买商品 + private async Task BuyMallProduct(string token, int userId, int productId) + { + var headers = CreateHeaders(token); + Mall_buy mallBuy = new Mall_buy + { + userId = userId, + productId = productId + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mallBuy), headers); + Debug.Log("购买商品响应: " + response); + } + + // 查询最近的大屠杀 + private async Task QueryLatestMassacre(string token) + { + var headers = CreateHeaders(token); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", headers); + Debug.Log("查询最近大屠杀响应: " + response); + } + + // 查询逃亡房间详情 + private async Task QueryEscapeRoomDetails(string token, int escapeId) + { + var headers = CreateHeaders(token); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); + Debug.Log("逃亡房间详情响应: " + response); + } + + // 用户下注 + private async Task UserBet(string token, int escapeId) + { + var headers = CreateHeaders(token); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId}, + ""bet"": 100, + ""roomNo"": 1 + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + Debug.Log("用户下注响应: " + response); + } + + // 查询击杀信息 + private async Task QueryKill(string token, int escapeId) + { + var headers = CreateHeaders(token); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); + Debug.Log("查询击杀信息响应: " + response); + } + + // 查询用户下注结果 + private async Task QueryUserBetResult(string token, int escapeId) + { + var headers = CreateHeaders(token); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + Debug.Log("查询用户下注结果响应: " + response); + } + + // 创建请求头 + private Dictionary CreateHeaders(string token) + { + return new Dictionary + { + { "Authorization", token } + }; + } + + void OnDestroy() + { + // 注销监听事件,避免内存泄漏 + LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; + selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + } +}*/ +/*using System; +using System.Collections; +using System.Collections.Generic; +using System.Xml.Linq; +using UnityEngine; +using UnityEngine.Networking; +using System.Threading.Tasks; +using Newtonsoft.Json; + +public class WebConnact : MonoBehaviour +{ + private string token; // 保存 token 以便在整个类中使用 + private int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 + + void Start() + { + // 注册监听事件,当收到 token 时,触发 HandleTokenReceived + LoginAndGetToken.OnTokenReceived += HandleTokenReceived; + + // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 + selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + } + + // 当接收到 token 时触发此方法 + void HandleTokenReceived(string receivedToken) + { + token = receivedToken; // 保存 token + // 首次调用加载初始数据 + LoadInitialData(); + } + + // 当游戏逃亡 ID 更新时触发此方法,仅保存最新的 escapeId + void HandleGameEscapeIdUpdated(int newGameEscapeId) + { + escapeId = newGameEscapeId; // 保存最新的 escapeId + Debug.Log("接收到新的 GameEscapeId: " + escapeId); + } + + // 加载初始数据 + private async void LoadInitialData() + { + // 更新用户信息 + await UpdateUserInformation(); + // 查询用户详细信息 + await QueryUserDetails(); + // 加载商城数据 + await LoadMallData(); + } + + // 加载游戏逃亡数据,使用最新的 escapeId + public async void LoadGameEscapeData() + { + if (escapeId == -1) + { + Debug.LogWarning("无法加载游戏逃亡数据,escapeId 未设置。"); + return; + } + + // 查询最近的大屠杀 + //await QueryLatestMassacre(); + // 查询逃亡房间详情 + await QueryEscapeRoomDetails(); + // 用户下注 + await UserBet(); + // 查询击杀数据 + await QueryKill(); + // 查询用户结算 + await QueryUserBetResult(); + } + + // 更新用户信息 + private async Task UpdateUserInformation() + { + var headers = CreateHeaders(); + string body = @" + { + ""nickName"": ""wulongxiao"", + ""headImg"": ""https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png"", + ""gender"": 1, + ""birthday"": ""2023-12-12 12:12:12"" + }"; + Debug.Log("正在更新用户信息..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", body, headers); + Debug.Log("更新用户信息响应: " + response); + } + + // 查询用户详情 + private async Task QueryUserDetails() + { + var headers = CreateHeaders(); + Debug.Log("正在查询用户详细信息..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", headers); + Debug.Log("查询用户详细信息响应: " + response); + return response; + } + + // 加载商城数据 + private async Task LoadMallData() + { + // 查询商城虚拟商品列表 + await QueryMallList(0); + // 查询商城实体商品列表 + await QueryMallList(1); + // 获取商品详情 + await GetMallProductDetails(1); + // 购买商品 + await BuyMallProduct(106, 1); + } + + // 查询商城列表 + private async Task QueryMallList(int productType) + { + Mall_List mallList = new Mall_List + { + productType = productType + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mallList)); + Debug.Log($"商城列表 (productType: {productType}) 响应: " + response); + } + + // 获取商城商品详情 + private async Task GetMallProductDetails(int productId) + { + var headers = CreateHeaders(); + Product_Details productDetails = new Product_Details + { + productId = productId + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(productDetails), headers); + Debug.Log("获取商品详情响应: " + response); + } + + // 购买商品 + private async Task BuyMallProduct(int userId, int productId) + { + var headers = CreateHeaders(); + Mall_buy mallBuy = new Mall_buy + { + userId = userId, + productId = productId + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mallBuy), headers); + Debug.Log("购买商品响应: " + response); + } + + //// 查询最近的大屠杀 + //private async Task QueryLatestMassacre() + //{ + // var headers = CreateHeaders(); + // string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", headers); + // Debug.Log("查询最近大屠杀响应: " + response); + //} + + // 查询逃亡房间详情 + private async Task QueryEscapeRoomDetails() + { + var headers = CreateHeaders(); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); + Debug.Log("逃亡房间详情响应: " + response); + } + + // 用户下注 + private async Task UserBet() + { + var headers = CreateHeaders(); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId}, + ""bet"": 100, + ""roomNo"": 1 + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + Debug.Log("用户下注响应: " + response); + } + + // 查询击杀信息 + private async Task QueryKill() + { + var headers = CreateHeaders(); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); + Debug.Log("查询击杀信息响应: " + response); + } + + // 查询用户下注结果 + private async Task QueryUserBetResult() + { + var headers = CreateHeaders(); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + Debug.Log("查询用户下注结果响应: " + response); + } + + // 创建请求头 + private Dictionary CreateHeaders() + { + return new Dictionary + { + { "Authorization", token } + }; + } + + void OnDestroy() + { + // 注销监听事件,避免内存泄漏 + LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; + selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + } +}*/ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.Threading.Tasks; +using Newtonsoft.Json; + +public class WebConnact : MonoBehaviour +{ + private string token = null; // 保存最新的 token,初始为 null + private int escapeId = -1; // 保存最新的 escapeId,初始为 -1 表示未设置 + + void Start() + { + // 注册监听事件,当收到 token 时,触发 HandleTokenReceived + LoginAndGetToken.OnTokenReceived += HandleTokenReceived; + + // 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated,但不执行其他方法 + selectGameEscape512.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated; + } + + // 当接收到 token 时触发此方法,仅保存 token + void HandleTokenReceived(string receivedToken) + { + token = receivedToken; // 保存最新的 token + Debug.Log("接收到新的 token: " + token); + } + + // 当游戏逃亡 ID 更新时触发此方法,仅保存最新的 escapeId + void HandleGameEscapeIdUpdated(int newGameEscapeId) + { + escapeId = newGameEscapeId; // 保存最新的 escapeId + Debug.Log("接收到新的 GameEscapeId: " + escapeId); + } + + // 加载初始数据,使用最新的 token + public async void LoadInitialData() + { + if (string.IsNullOrEmpty(token)) + { + Debug.LogWarning("无法加载初始数据,token 未设置。"); + return; + } + + // 更新用户信息 + await UpdateUserInformation(); + // 查询用户详细信息 + await QueryUserDetails(); + // 加载商城数据 + await LoadMallData(); + } + + // 加载游戏逃亡数据,使用最新的 escapeId 和 token + public async void LoadGameEscapeData() + { + if (string.IsNullOrEmpty(token)) + { + Debug.LogWarning("无法加载游戏逃亡数据,token 未设置。"); + return; + } + + if (escapeId == -1) + { + Debug.LogWarning("无法加载游戏逃亡数据,escapeId 未设置。"); + return; + } + + // 查询最近的大屠杀 + await QueryLatestMassacre(); + // 查询逃亡房间详情 + await QueryEscapeRoomDetails(); + // 用户下注 + await UserBet(); + // 查询击杀数据 + await QueryKill(); + // 查询用户结算 + await QueryUserBetResult(); + } + + // 更新用户信息 + private async Task UpdateUserInformation() + { + var headers = CreateHeaders(); + string body = @" + { + ""nickName"": ""wulongxiao"", + ""headImg"": ""https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png"", + ""gender"": 1, + ""birthday"": ""2023-12-12 12:12:12"" + }"; + Debug.Log("正在更新用户信息..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", body, headers); + Debug.Log("更新用户信息响应: " + response); + } + + // 查询用户详情 + private async Task QueryUserDetails() + { + var headers = CreateHeaders(); + Debug.Log("正在查询用户详细信息..."); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", headers); + Debug.Log("查询用户详细信息响应: " + response); + return response; + } + + // 加载商城数据 + private async Task LoadMallData() + { + // 查询商城虚拟商品列表 + await QueryMallList(0); + // 查询商城实体商品列表 + await QueryMallList(1); + // 获取商品详情 + await GetMallProductDetails(1); + // 购买商品 + await BuyMallProduct(106, 1); + } + + // 查询商城列表 + private async Task QueryMallList(int productType) + { + var headers = CreateHeaders(); + Mall_List mallList = new Mall_List + { + productType = productType + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mallList), headers); + Debug.Log($"商城列表 (productType: {productType}) 响应: " + response); + } + + // 获取商城商品详情 + private async Task GetMallProductDetails(int productId) + { + var headers = CreateHeaders(); + Product_Details productDetails = new Product_Details + { + productId = productId + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(productDetails), headers); + Debug.Log("获取商品详情响应: " + response); + } + + // 购买商品 + private async Task BuyMallProduct(int userId, int productId) + { + var headers = CreateHeaders(); + Mall_buy mallBuy = new Mall_buy + { + userId = userId, + productId = productId + }; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mallBuy), headers); + Debug.Log("购买商品响应: " + response); + } + + // 查询最近的大屠杀 + private async Task QueryLatestMassacre() + { + var headers = CreateHeaders(); + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", headers); + Debug.Log("查询最近大屠杀响应: " + response); + } + + // 查询逃亡房间详情 + private async Task QueryEscapeRoomDetails() + { + var headers = CreateHeaders(); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryEscapeRoomList", "POST", body, headers); + Debug.Log("逃亡房间详情响应: " + response); + } + + // 用户下注 + private async Task UserBet() + { + var headers = CreateHeaders(); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId}, + ""bet"": 100, + ""roomNo"": 1 + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers); + Debug.Log("用户下注响应: " + response); + } + + // 查询击杀信息 + private async Task QueryKill() + { + var headers = CreateHeaders(); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryKill", "POST", body, headers); + Debug.Log("查询击杀信息响应: " + response); + } + + // 查询用户下注结果 + private async Task QueryUserBetResult() + { + var headers = CreateHeaders(); + string body = $@" + {{ + ""userId"": 106, + ""escapeId"": {escapeId} + }}"; + string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryUserBetResult", "POST", body, headers); + Debug.Log("查询用户下注结果响应: " + response); + } + + // 创建请求头,使用最新的 token + private Dictionary CreateHeaders() + { + if (string.IsNullOrEmpty(token)) + { + Debug.LogWarning("尝试创建请求头时,token 未设置。"); + return new Dictionary(); + } + + return new Dictionary + { + { "Authorization", token } + }; + } + + void OnDestroy() + { + // 注销监听事件,避免内存泄漏 + LoginAndGetToken.OnTokenReceived -= HandleTokenReceived; + selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated; + } +} +//[Serializable] +//public class loginbody//登录和注册用 +//{ +// public string userName; +// public string password; +// public int verifyCode; + +//} + +[System.Serializable] +public class User_InformationHead //完善用户信息 +{ + public string nickName; + public string headImg; + public string gender; + public string birthday; +} +[Serializable] +public class Query_Announcement //查询公告分页 +{ + public int userId; + public int pageNo; + public int pageSize; +} + +[Serializable] +public class Mall_List //获取商城列表 +{ + public int productType; + public int pageNo; + public int pageSize; +} + +[Serializable] +public class Product_Details//商品详情,有问题 +{ + public int productId; +} + +[Serializable] +public class Mall_buy +{ + public int productId; + public int userId; +} + + +[Serializable] +public class cutePoolPage +{ + public int orderByBeansCoin; +} \ No newline at end of file diff --git a/TheStrongestSnail/Assets/Scripts/Login/web.cs b/TheStrongestSnail/Assets/Scripts/Login/web.cs index fc850ca..3c397c5 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/web.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/web.cs @@ -154,7 +154,7 @@ public class web : MonoBehaviour // Promptmgr.Instance.PromptBubble(request.error, Color.black,Color.red); return null; } - else + else { // 处理返回的Cookie string setCookieHeader;