_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Login/11/selectUserInfo.cs

422 lines
14 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using Newtonsoft.Json;
2024-11-13 21:52:56 +08:00
using UnityEngine.UI;
using Newtonsoft.Json.Linq;
/*public class selsecUserInfo : MonoBehaviour
{
public string token = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token<65><6E><EFBFBD><EFBFBD>ʼΪ null
public int escapeId = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId<49><64><EFBFBD><EFBFBD>ʼΪ -1 <20><>ʾδ<CABE><CEB4><EFBFBD><EFBFBD>
void Start()
{
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HandleTokenReceived
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> HandleGameEscapeIdUpdated<65><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-14 18:09:37 +08:00
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> token
public void HandleTokenReceived(string receivedToken)
{
token = receivedToken; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
// <20>״ε<D7B4><CEB5>ü<EFBFBD><C3BC>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
LoadInitialData();
//LoadGameEscapeData();
//Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> token: " + token);
}
// <20><><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD> ID <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
public async void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
escapeId = newGameEscapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
await selectUser();//=====================================================================<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>κεط<CEB5><D8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>input.GetKeyDown.....<2E><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD>
//Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> GameEscapeId: " + escapeId);
}
// <20><><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
public async void LoadInitialData()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return;
}
await selectUser();//=====================================================================<3D><><EFBFBD>ڴ˴<DAB4>ֻΪ<D6BB><CEAA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD>Ҫ
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId <20><> token
public async void selectQueryKill1()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return;
}
if (escapeId == -1)
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>escapeId δ<><CEB4><EFBFBD>á<EFBFBD>");
return;
}
await selectUser();//==========================================================================================================================================================================
}
//===============================================================================================================================================================================================================================
// <20><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
public async Task<string> selectUser()
{
var headers = CreateHeaders();
Debug.Log("<22><><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ...");
string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", headers);
Debug.Log("<22><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2>Ӧ: " + response);
return response;
}
//===============================================================================================================================================================================================================================
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷʱ<CDB7><CAB1>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization", token }
};
}
void OnDestroy()
{
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
2024-11-14 18:09:37 +08:00
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
}
2024-11-13 21:52:56 +08:00
}*/
/*public class SelectUserInfo : MonoBehaviour
{
public string token = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token<65><6E><EFBFBD><EFBFBD>ʼΪ null
public int escapeId = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId<49><64><EFBFBD><EFBFBD>ʼΪ -1 <20><>ʾδ<CABE><CEB4><EFBFBD><EFBFBD>
private string lastSelectUserInfoResponse = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF>Ӧ
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>ť
public Button selectUserInfoButton;
void Start()
{
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HandleTokenReceived
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> HandleGameEscapeIdUpdated
2024-11-14 18:09:37 +08:00
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
2024-11-13 21:52:56 +08:00
// <20><><EFBFBD>谴ť<E8B0B4><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> OnSelectUserInfoButtonClicked
if (selectUserInfoButton != null)
{
selectUserInfoButton.onClick.AddListener(OnSelectUserInfoButtonClicked);
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> token
public void HandleTokenReceived(string receivedToken)
{
token = receivedToken; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> token: " + token);
// <20>״ε<D7B4><CEB5>ü<EFBFBD><C3BC>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
LoadInitialData();
}
// <20><><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD> ID <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
public async void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
escapeId = newGameEscapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> GameEscapeId: " + escapeId);
// <20>ڽ<EFBFBD><DABD>յ<EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ò<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
lastSelectUserInfoResponse = await SelectUser();
Debug.Log("HandleGameEscapeIdUpdated <20><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + lastSelectUserInfoResponse);
}
// <20><><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
public async void LoadInitialData()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return;
}
// <20><><EFBFBD>ò<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><E9B7BD>
lastSelectUserInfoResponse = await SelectUser();
Debug.Log("<22><>ʼ<EFBFBD><CABC><EFBFBD>صIJ<D8B5>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + lastSelectUserInfoResponse);
}
// <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>󴥷<EFBFBD><F3B4A5B7>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
public async void OnSelectUserInfoButtonClicked()
{
// <20><><EFBFBD><EFBFBD> token <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>飬token δ<><CEB4><EFBFBD>á<EFBFBD>");
return;
}
// <20><><EFBFBD>ò<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><E9B7BD>
lastSelectUserInfoResponse = await SelectUser();
Debug.Log("<22>û<EFBFBD><C3BB><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + lastSelectUserInfoResponse);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
HandleSelectUserResponse(lastSelectUserInfoResponse);
}
// <20><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
public async Task<string> SelectUser()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>飬token δ<><CEB4><EFBFBD>á<EFBFBD>");
return null;
}
var headers = CreateHeaders();
Debug.Log("<22><><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ...");
string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", headers);
Debug.Log("<22><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2>Ӧ: " + response);
return response; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷʱ<CDB7><CAB1>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization", token }
};
}
// <20><><EFBFBD><EFBFBD> SelectUser <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
private void HandleSelectUserResponse(string response)
{
if (response.Contains("success"))
{
Debug.Log("<22><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
}
else
{
Debug.LogWarning("<22><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + response);
}
}
void OnDestroy()
{
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
2024-11-14 18:09:37 +08:00
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
2024-11-13 21:52:56 +08:00
// ȡ<><C8A1><EFBFBD><EFBFBD>ť<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (selectUserInfoButton != null)
{
selectUserInfoButton.onClick.RemoveListener(OnSelectUserInfoButtonClicked);
}
}
}*/
public class SelectUserInfo : MonoBehaviour
{
public string token = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token<65><6E><EFBFBD><EFBFBD>ʼΪ null
public int escapeId = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId<49><64><EFBFBD><EFBFBD>ʼΪ -1 <20><>ʾδ<CABE><CEB4><EFBFBD><EFBFBD>
private string lastSelectUserInfoResponse = null; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF>Ӧ
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>ť=======================================================================================
public Button selectUserInfoButton;
void Start()
{
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HandleTokenReceived
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> HandleGameEscapeIdUpdated
2024-11-14 18:09:37 +08:00
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
2024-11-13 21:52:56 +08:00
// <20><><EFBFBD>谴ť<E8B0B4><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> OnSelectUserInfoButtonClicked===================================================================
if (selectUserInfoButton != null)
{
selectUserInfoButton.onClick.AddListener(OnSelectUserInfoButtonClicked);
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> token
public void HandleTokenReceived(string receivedToken)
{
token = receivedToken; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> token: " + token);
// <20>״ε<D7B4><CEB5>ü<EFBFBD><C3BC>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
LoadInitialData();
}
// <20><><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD> ID <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
public async void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
escapeId = newGameEscapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> escapeId
Debug.Log("<22><><EFBFBD>յ<EFBFBD><D5B5>µ<EFBFBD> GameEscapeId: " + escapeId);
// <20>ڽ<EFBFBD><DABD>յ<EFBFBD> escapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ò<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
lastSelectUserInfoResponse = await SelectUser();
Debug.Log("HandleGameEscapeIdUpdated <20><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + lastSelectUserInfoResponse);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
HandleSelectUserResponse(lastSelectUserInfoResponse);
}
// <20><><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
public async void LoadInitialData()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>س<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݣ<EFBFBD>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return;
}
// <20><><EFBFBD>ò<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><E9B7BD>
lastSelectUserInfoResponse = await SelectUser();
Debug.Log("<22><>ʼ<EFBFBD><CABC><EFBFBD>صIJ<D8B5>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + lastSelectUserInfoResponse);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
HandleSelectUserResponse(lastSelectUserInfoResponse);
}
// <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>󴥷<EFBFBD><F3B4A5B7>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
public async void OnSelectUserInfoButtonClicked()
{
// <20><><EFBFBD><EFBFBD> token <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>飬token δ<><CEB4><EFBFBD>á<EFBFBD>");
return;
}
// <20><><EFBFBD>ò<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><E9B7BD>
lastSelectUserInfoResponse = await SelectUser();
Debug.Log("<22>û<EFBFBD><C3BB><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + lastSelectUserInfoResponse);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
HandleSelectUserResponse(lastSelectUserInfoResponse);
}
// <20><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
public async Task<string> SelectUser()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22>޷<EFBFBD><DEB7><EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>飬token δ<><CEB4><EFBFBD>á<EFBFBD>");
return null;
}
var headers = CreateHeaders();
Debug.Log("<22><><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ...");
string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/queryUserInfo", "POST", "{}", headers);
Debug.Log("<22><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2>Ӧ: " + response);
return response; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> token
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("<22><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷʱ<CDB7><CAB1>token δ<><CEB4><EFBFBD>á<EFBFBD>");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization", token }
};
}
// <20><><EFBFBD><EFBFBD> SelectUser <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ֱ<EFBFBD>Ӵ<EFBFBD><D3B4>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>л<EFBFBD>ȡ<EFBFBD>ֶ<EFBFBD>
private void HandleSelectUserResponse(string response)
{
try
{
// ʹ<><CAB9> JObject <20><><EFBFBD><EFBFBD> JSON <20>ַ<EFBFBD><D6B7><EFBFBD>
JObject jsonObject = JObject.Parse(response);
// <20><>ȡ code <20><> message
int code = jsonObject.Value<int>("code");
string message = jsonObject.Value<string>("message");
if (code == 200)
{
JObject data = jsonObject.Value<JObject>("data");
if (data != null)//<2F>û<EFBFBD><C3BB><EFBFBD>Ϣ
{
int userId = data.Value<int>("userId");//<2F>û<EFBFBD>ID
string userName = data.Value<string>("userName");//<2F>û<EFBFBD><C3BB><EFBFBD>
string nickName = data.Value<string>("nickName");//<2F>س<EFBFBD>
string headImg = data.Value<string>("headImg");//ͷ<><CDB7>
int gender = data.Value<int>("gender");//<2F>Ա<EFBFBD>
string birthday = data.Value<string>("birthday");//<2F><><EFBFBD><EFBFBD>
int voluteCoin = data.Value<int>("voluteCoin");//<2F>Ͽ<EFBFBD>
int beansCoin = data.Value<int>("beansCoin");//<2F><>ţ<EFBFBD><C5A3>
int ichorCoin = data.Value<int>("ichorCoin");//<2F><>Һ
int cuteNo = data.Value<int>("cuteNo");//<2F><><EFBFBD><EFBFBD>
// <20><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ֶ<EFBFBD>
Debug.Log($"<22><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>û<EFBFBD> ID: {userId}, <20>û<EFBFBD><C3BB><EFBFBD>: {userName}, <20>dz<EFBFBD>: {nickName}, <20>Ա<EFBFBD>: {(gender == 1 ? "<EFBFBD><EFBFBD>" : "Ů")}, <20>Ͽ<EFBFBD>: {voluteCoin}, <20>ϵ<EFBFBD>: {beansCoin}, <20><>Һ: {ichorCoin}, <20><><EFBFBD><EFBFBD>: {cuteNo}");
}
else
{
Debug.LogWarning("<22><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><D5A3>޷<EFBFBD><DEB7><EFBFBD>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ");
}
}
else
{
Debug.LogWarning($"<22><>ѯ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣʧ<CFA2>ܣ<EFBFBD><DCA3><EFBFBD>Ϣ: {message}");
}
}
catch (Exception ex)
{
Debug.LogError($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧʱ<D3A6><CAB1><EFBFBD><EFBFBD><EFBFBD>쳣: {ex.Message}");
}
}
void OnDestroy()
{
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
2024-11-14 18:09:37 +08:00
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
2024-11-13 21:52:56 +08:00
// ȡ<><C8A1><EFBFBD><EFBFBD>ť<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-==============================================================================================
if (selectUserInfoButton != null)
{
selectUserInfoButton.onClick.RemoveListener(OnSelectUserInfoButtonClicked);
}
}
}