using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; namespace Studio.Scripts.HttpMessage { public enum HttpMethodType { None = 0, Post = 1, Get = 2, } public enum MessageModuleType { None = 0, Common = 1, Login = 2, Room = 3, Set = 4, } public enum MessageType { None = 0, SNLoginType = 1,// sn 登录 PhoneLoginType = 2,// 手机登录 AccountLoginType = 3,// 账号登录 AdvanceAccountLoginType = 4,// 预登录 LogoutType = 5,// 退出 GetAvatarType =6,// 获取头像 ModifyRoleType =7,// 修改信息 CaptchaCodeType = 10,// 图形验证码 SmsCodeType = 11,//手机验证码 GetFileAddressType = 12,//文件存储地址 CreaterRoomType = 20,// 创建房间 DeleteRoomType = 21,// 删除房间 GetMySetType = 22,// 获取我的设置 UpdateSetType = 23,//修改我的设置 GetAllArtType = 30,//获取资源列表 GetDetailArtType = 31,//获取资源详情 SearchArtList = 32,//搜索资源列表 } public enum PhoneSMSCodeType { None = 0, Register = 1,// 注册 Login = 2,// 登录 RetrievePassword = 3,// 找回密码 ChangePassword = 4,// 修改密码 Reserve = 5,// 预留 ChangePhone = 6,// 手机号修改 } /// /// 分辨率 /// public enum RatioType { None = 0, High = 1,// 高 1290 *960 Middle =2,//中 640*480 Low = 3,// 低 320*240 } /// /// fps 帧率 /// public enum FpsType { None = 0, Low = 1,// 低 15 Middle = 2,//中 30 High = 3,// 高 60 } public enum IsActivateType { Unactivated = 0,// 未激活 Activated = 1,// 激活 } public struct ScenesData { public int scenesID; public int roomID; } public class BaseHttpMessage { public MessageModuleType messageModuleType = MessageModuleType.None; public HttpMethodType methodType = HttpMethodType.None; protected string _path; public virtual string path { get { return _path; } } public Dictionary headers; protected WWWForm _wwwForm; public virtual WWWForm wwwForm { get { return _wwwForm ; } } public virtual string ToBodyString() { return string.Empty; } protected WWWForm GetWWWFrom(T body) where T: struct { WWWForm wf = new WWWForm(); System.Reflection.FieldInfo[] fields = body.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); foreach (System.Reflection.FieldInfo item in fields) { if (item.FieldType == typeof(string)) { wf.AddField(item.Name, (item.GetValue(body)??"").ToString()); } else if (item.FieldType == typeof(int)) { wf.AddField(item.Name, (int)item.GetValue(body)); } } return wf; } protected WWWForm GetWWWFrom(IList body) where T : struct { WWWForm wf = new WWWForm(); foreach (var bodyItem in body) { System.Reflection.FieldInfo[] fields = bodyItem.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); foreach (System.Reflection.FieldInfo item in fields) { Debug.LogWarning(item.Name + ":" + item.GetValue(bodyItem)); if (item.FieldType == typeof(string)) { wf.AddField(item.Name, item.GetValue(bodyItem).ToString()); } else if (item.FieldType == typeof(int)) { wf.AddField(item.Name, (int)item.GetValue(bodyItem)); } } } return wf; } protected string GetHttpGetForm(string url, T body) where T : struct { string parameters = ""; System.Reflection.FieldInfo[] fields = body.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); foreach (System.Reflection.FieldInfo item in fields) { parameters += item.Name + "="; parameters += item.GetValue(body).ToString() + "&"; } if (url.IndexOf("?") == -1) url += "?"; else url += "&"; url += parameters.TrimEnd(new char[] { '&' }); return url; } protected string CreateGetData(string url, Dictionary form) { string data = ""; if (form != null && form.Count > 0) { foreach (var item in form) { data += item.Key + "="; data += item.Value.ToString() + "&"; } } if (url.IndexOf("?") == -1) url += "?"; else url += "&"; url += data.TrimEnd(new char[] { '&' }); return url; } } }