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

111 lines
4.1 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class UpdateUserInfo : 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>
selectGameEscape512.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 UpdateUserInformation();//=====================================================================<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 UpdateUserInformation();//=====================================================================<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;
}
// <20><>ѯ<EFBFBD><D1AF>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD>
await UpdateUserInformation();//==========================================================================================================================================================================
}
//===============================================================================================================================================================================================================================
// <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ
public 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("<22><><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ...");
string response = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", body, headers);
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ<EFBFBD><CFA2>Ӧ: " + 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;
selectGameEscape512.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
}
}