_xiaofang/xiaofang/Assets/Script/loginScripts/LoginPanel.cs
2024-11-25 16:33:54 +08:00

61 lines
1.4 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEditor.PackageManager;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoginPanel : MonoBehaviour
{
public Button loginBtn;
public Button getYzmBtn;
public InputField id;
public InputField pwd;
public InputField sjh;
public InputField yzm;
// Start is called before the first frame update
void Start()
{
loginBtn.onClick.AddListener(OnClickLoginBtn);
getYzmBtn.onClick.AddListener(OnClickGetYzmBtn);
}
public void OnClickGetYzmBtn()
{
}
public void OnClickLoginBtn()
{
Login();
}
//登录逻辑
public async void Login()
{
auth_login loginBody = new auth_login
{
clientId = id.text,
grantType = pwd.text
};
//Debug.Log(JsonUtility.ToJson(loginBody));
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(loginBody));
Debug.Log("登录" + response);
// 解析服务器返回的数据
server serverData = JsonConvert.DeserializeObject<server>(response);
//token = serverData.data.access_token;
Debug.Log(serverData.data.access_token);
//跳转场景写这里
SceneManager.LoadScene("scheduled_exercise");
}
}