_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Login/WebConnact.cs
2024-11-11 19:48:32 +08:00

194 lines
6.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
using UnityEngine;
using UnityEngine.Networking;
using System.Threading.Tasks;
public class WebConnact : MonoBehaviour
{
void Start()
{
//由于除登录注册外的其他方法都需要登录后返回的token
//因此登录不在此发送请求(同时)
//采用监听和事件回调的方法只有监听到登录和token返回时才运行其他方法
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
//Loding();
}
void HandleTokenReceived(string token)
{
// 使用 token
//string loginToken=token;
Debug.Log("HandleTokenReceived:"+token);
Loding(token);
}
public async void Loding(string token)
{
//用来给请求头赋值
string Authorization = token;
Debug.Log("Loding(Authorization)"+Authorization);
//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<string, string> head13 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
// user.nickName = "wulongxiao";
// user.headImg = "https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png";
// user.gender = "男";
// user.birthday = "20010506";
// string UserNewInfoBody = "{\"nickName\":\"wulongxiao\",\"headImg\":\"https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png\",\"gender\":\"男\",\"birthday\":\"20010506\"}";
// string response13 = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", UserNewInfoBody, head13);
// Debug.Log(response13);
//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(mall_virtualponse);
//Mall_List mall = new Mall_List();
//mall.productType = 1;
////mall.pageNo = 1;
////mall.pageSize = 20;//这两个属性是默认值可以省略不写默认是1跟20
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall));
//Debug.Log(response);
//Product_Details product = new Product_Details();
//product.productId = 1;
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(product));
//Debug.Log(response);
// Mall_buy mall_Buy = new Mall_buy();
//string Authorization = "7083e9cb0de74c9dbb3c02f37ec339b8";
// mall_Buy.userId = 106;
// mall_Buy.productId = 1;
// string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mall_Buy),Authorization);
// Debug.Log(response);
//Query_Announcement query_Announcement = new Query_Announcement();
//query_Announcement.userId = 106;
//query_Announcement.pageNo = 1;
//query_Announcement.pageSize = 20;
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/notice/page", "POST", JsonUtility.ToJson(query_Announcement));
//Debug.Log(response);
//string response = await web.SendRequest($"http://121.40.42.41:8080/snail/notice/info?noticeId=${公告id}", "Get");
//Debug.Log(response);
//5.1查询最近一场大屠杀
// Dictionary<string, string> head51 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
// //head.Add("Authorization", token);
// string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51);
// Debug.Log(response51);//查询最近一场大逃亡游戏详情:
//已通过
//===========================================getToken================================================================================
}
void OnDestroy()
{
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
}
// Update is called once per frame
void Update()
{
}
}
[Serializable]
public class Search_room//登录和注册用
{
public int userId;
}
//[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;
}