_xiaofang/xiaofang/Assets/Script/loginScripts/LoginPanel.cs

71 lines
1.7 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting.Antlr3.Runtime;
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()
{
// 创建登录请求的 body
auth_login loginBody = new auth_login
{
grantType = "password",
clientId = "e5cd7e4891bf95d1d19206ce24a7b32e",
userType = "company_user",
username = "13006065371",
password = "YYL5371!",
phonenumber = "",
smsCode = ""
};
// 发送请求
Debug.Log("登陆入参"+ JsonUtility.ToJson(loginBody));
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(loginBody));
Debug.Log("登录" + response);
// 解析服务器返回的数据
loginResponse serverData = JsonConvert.DeserializeObject<loginResponse>(response);
// 将登录响应数据保存到静态变量中
GlobalData.ServerData = serverData;
// 打印 access_token
Debug.Log(serverData.data.access_token);
// 跳转场景
SceneManager.LoadScene(1);
}
}