Cute_demon_attacks/meng_yao/Assets/script/serveTestScript/UserModule/updatePlayerInfo.cs

47 lines
1.9 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.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
using UnityEngine;
//用户信息更新
public class updatePlayerInfo : MonoBehaviour
{
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(MyGlobal.global.loginResponse.Data.access_token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization","Bearer "+MyGlobal.global.loginResponse.Data.access_token },
{ "client-info", "{\"platform\":\"ios\",\"phone_product\":\"apple\",\"phone_model\":\"iPhone_8\",\"system_version\":\"12.0\",\"screen_size\":\"750*1334\",\"device_no\":\"e3e277810fff9d955ebdd7037eff51a8\",\"version\":\"1.0.0\"}" }
};
}
//=========用户信息更新=============================================================================
public async Task<UpdatePlayerInfoResponse> UpdatePlayerInfo(string field, string value)//呢称需要包含中文可以跟字母组合,且必须大于两个//只能更新名字头像
{
string body = $"{{\"{field}\":\"{value}\"}}";
//Debug.Log("=====" + body);
string response = await myWeb.SendRequest(myWeb.URL + "/api/user/update_info", "POST", body, CreateHeaders());
Debug.Log("用户信息更新" + response);
UpdatePlayerInfoResponse updatePlayerInfoResponse = JsonConvert.DeserializeObject<UpdatePlayerInfoResponse>(response);
return updatePlayerInfoResponse;
}
}
//=================================================================================
public class UpdatePlayerInfoResponse
{
public int code;
public string message;
public UpdatePlayerInfoData data;
}
public class UpdatePlayerInfoData
{
public string nickname;
public string avatar;
}