228 lines
8.3 KiB
C#
228 lines
8.3 KiB
C#
using Assets.Scripts.Apis.Models;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Assets.Scripts.Apis
|
|
{
|
|
public class UserApi : ApiBase
|
|
{
|
|
public async Task<JsonResult<UserResultModel>> Login(string phone, string pwd, string countryCode)
|
|
{
|
|
var param = new
|
|
{
|
|
Phone = phone,
|
|
Pwd = pwd,
|
|
countryCode
|
|
};
|
|
|
|
JsonResult<UserResultModel> ret = null;
|
|
try
|
|
{
|
|
ret = await PostAsync<JsonResult<UserResultModel>>("NoAuth/v1/Login", param);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new JsonResult<UserResultModel> { result = false, errMsg = ex.Message };
|
|
}
|
|
//ApiBase.cookies = response.Cookies;
|
|
//var ret = response.DynamicBody;
|
|
if (ret.result)
|
|
{
|
|
//var str = Newtonsoft.Json.JsonConvert.SerializeObject(ret.data);
|
|
var user = new UserResultModel();
|
|
user.Id = ret.data.Id;
|
|
user.Nickname = ret.data.Nickname;
|
|
user.Phone = ((string)ret.data.Phone).Trim();
|
|
user.Country = ret.data.Country;
|
|
user.Province = ret.data.Province;
|
|
user.City = ret.data.City;
|
|
user.Area = ret.data.Area;
|
|
user.Pass = ret.data.Pass;
|
|
user.Sex = ret.data.Sex;
|
|
user.Unit = ret.data.Unit;
|
|
user.Weight = ret.data.Weight;
|
|
user.FTP = ret.data.FTP;
|
|
user.WheelDiameter = ret.data.WheelDiameter;
|
|
user.Email = user.Email ?? "";
|
|
user.Pass = user.Pass ?? "";
|
|
user.OtherPlatforms = user.OtherPlatforms ?? "";
|
|
user.WxHeadImg = ret.data.WxHeadImg ?? "";
|
|
//user.LoginTime = ret.data.LoginTime;
|
|
user.LastLoginTime = ret.data.LastLoginTime;
|
|
user.AutoPause = ret.data.AutoPause;
|
|
user.MaxHeartRate = ret.data.MaxHeartRate;
|
|
user.CanEditRoom = ret.data.CanEditRoom;
|
|
user.BicycleWeight = ret.data.BicycleWeight;
|
|
user.Contact = ret.data.Contact;
|
|
user.ContactPhone = ret.data.ContactPhone;
|
|
user.ContactAddress = ret.data.ContactAddress;
|
|
user.Sensitivity = ret.data.Sensitivity;
|
|
if (ret.data.ConnectedToStrava != null)
|
|
{
|
|
user.ConnectedToStrava = ret.data.ConnectedToStrava;
|
|
}
|
|
user.Birthday = ret.data.Birthday;
|
|
//todo: check local database, insert new user
|
|
|
|
//PubCommData.CurrentUser = user;
|
|
user.cookie = cookies[0].Value;
|
|
return new JsonResult<UserResultModel>() { result = true, data = user };
|
|
}
|
|
else
|
|
{
|
|
return new JsonResult<UserResultModel>() { result = false, data = null, errMsg = ret.errMsg };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取个人中心的统计信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public JsonResult<SummaryResultModel> GetSummary()
|
|
{
|
|
var result = Get<JsonResult<SummaryResultModel>>("User/GetSummary");
|
|
|
|
return result;
|
|
}
|
|
|
|
public DateTime GetNow()
|
|
{
|
|
var result = Get("NoAuth/GetNow");
|
|
|
|
return DateTime.Parse(result);
|
|
}
|
|
public async Task<JsonResult<UserResultModel>> Register(string Phone, string Pwd, string Captcha)
|
|
{
|
|
var param = new
|
|
{
|
|
Phone,
|
|
Pwd,
|
|
Captcha
|
|
};
|
|
|
|
JsonResult<UserResultModel> ret = null;
|
|
try
|
|
{
|
|
ret = await PostAsync<JsonResult<UserResultModel>>("NoAuth/v1/Register", param);
|
|
ret.data.cookie = cookies[0].Value;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new JsonResult<UserResultModel> { result = false, errMsg = ex.Message };
|
|
}
|
|
return ret;
|
|
}
|
|
public async Task<JsonResult<JObject>> GetCaptcha(string phone)
|
|
{
|
|
return await PostAsync<JsonResult<JObject>>("NoAuth/v1/GetCaptcha",new {phone });
|
|
}
|
|
public async Task<JsonResult<object>> UpdateUserInfo(UserResultModel user)
|
|
{
|
|
return await PostAsync<JsonResult<object>>("User/UpdateUserSetting", user);
|
|
}
|
|
public JsonResult<JObject> GetUserInfo()
|
|
{
|
|
return Get<JsonResult<JObject>>("User/GetCurrentUser");
|
|
}
|
|
public async Task<JsonResult<UserResultModel>> QuickLogin()
|
|
{
|
|
var r = await PostAsync<JsonResult<UserResultModel>>("NoAuth/QuickLogin", null);
|
|
r.data.cookie = cookies[0].Value;
|
|
return r;
|
|
}
|
|
|
|
public async Task<JsonResult<object>> OnWebWxLoginCheckUnionId(string unionId, string openId)
|
|
{
|
|
var r = await PostAsync<JsonResult<object>>("NoAuth/OnWebWxLoginCheckUnionId", new { unionId, openId });
|
|
if (r.result)
|
|
{
|
|
var data = JObject.FromObject(r.data);
|
|
if (data.Value<string>("success") != null && data.Value<string>("success") == "False")
|
|
{
|
|
return r;
|
|
}
|
|
else
|
|
{
|
|
var user = data.ToObject<UserResultModel>();
|
|
user.cookie = cookies[0].Value;
|
|
r.data = user;
|
|
}
|
|
}
|
|
return r;
|
|
}
|
|
public async Task<JsonResult<UserResultModel>> OnWebWxLogin(string Phone, string Captcha
|
|
, string UnionId, string WxWebOpenId, string WxHeadImg, string NickName, int? Sex, string Password)
|
|
{
|
|
var r = await PostAsync<JsonResult<UserResultModel>>("NoAuth/OnWebWxLogin",
|
|
new { Phone, Captcha, UnionId, WxWebOpenId, WxHeadImg, NickName, Sex, Password });
|
|
r.data.cookie = cookies[0].Value;
|
|
return r;
|
|
}
|
|
|
|
|
|
public async Task<JsonResult<JObject>> Update(UserResultModel currUser, string filePath = "")
|
|
{
|
|
//return await PostAsync<JsonResult<dynamic>>("User/UpdateUserSetting", new {
|
|
// UID = currUser.Id,
|
|
// Sex = currUser.Sex,
|
|
// currUser.Unit,
|
|
// currUser.Weight,
|
|
// currUser.FTP,
|
|
// currUser.WheelDiameter,
|
|
// currUser.Nickname,
|
|
// currUser.Country,
|
|
// currUser.Province,
|
|
// currUser.City,
|
|
// currUser.Area,
|
|
// currUser.AutoPause,
|
|
// currUser.MaxHeartRate,
|
|
// currUser.BicycleWeight,
|
|
// currUser.Contact,
|
|
// currUser.ContactPhone,
|
|
// currUser.ContactAddress,
|
|
// currUser.Sensitivity,
|
|
// imgData = imgData
|
|
//});
|
|
var files = new List<string>();
|
|
if (!string.IsNullOrWhiteSpace(filePath))
|
|
{
|
|
files.Add(filePath);
|
|
}
|
|
var res = Upload("v1/User/UpdateUserSetting", new
|
|
{
|
|
UID = currUser.Id,
|
|
Sex = currUser.Sex,
|
|
currUser.Unit,
|
|
currUser.Height,
|
|
currUser.Weight,
|
|
currUser.FTP,
|
|
currUser.WheelDiameter,
|
|
currUser.Nickname,
|
|
currUser.Country,
|
|
currUser.Province,
|
|
currUser.City,
|
|
currUser.Area,
|
|
currUser.AutoPause,
|
|
currUser.MaxHeartRate,
|
|
currUser.BicycleWeight,
|
|
currUser.Contact,
|
|
currUser.ContactPhone,
|
|
currUser.ContactAddress,
|
|
currUser.Sensitivity,
|
|
currUser.Birthday
|
|
//imgData = imgData
|
|
}, files);
|
|
|
|
return Newtonsoft.Json.JsonConvert.DeserializeObject<JsonResult<JObject>>(res);
|
|
}
|
|
public async Task<JsonResult<JObject>> GetNotify()
|
|
{
|
|
return await GetAsync<JsonResult<JObject>>("/Home/GetNotify");
|
|
}
|
|
}
|
|
}
|