123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- 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,// 手机号修改
- }
- /// <summary>
- /// 分辨率
- /// </summary>
- public enum RatioType
- {
- None = 0,
- High = 1,// 高 1290 *960
- Middle =2,//中 640*480
- Low = 3,// 低 320*240
- }
- /// <summary>
- /// fps 帧率
- /// </summary>
- 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<string, string> headers;
- protected WWWForm _wwwForm;
- public virtual WWWForm wwwForm
- {
- get
- {
- return _wwwForm ;
- }
- }
- public virtual string ToBodyString()
- {
- return string.Empty;
- }
- protected WWWForm GetWWWFrom<T>(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<T>(IList<T> 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<T>(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<string, object> 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;
- }
- }
-
- }
|