/// <summary> /// 回调的第一个参数:连续登陆的天数 /// 回调的第一个参数:签到成功 /// </summary> /// <param name="callback"></param> public void Signin(Action <int, bool> callback) { Body body = new SigninBody(URLConfig.Signin); HttpRequestTool.SendMessage( body, (x) => { Debug.Log("dailySign Success:" + x); JSONNode res = JSONNode.Parse(x); int code = res["code"]; if (code == 0) { int days = res["days"]; int signStatus = res["status"]; signLog[DateTime.UtcNow.Day] = signStatus == (int)SignResult.Sucess; if (callback != null) { callback.Invoke(days, signStatus == (int)SignResult.Sucess); } } else { Debug.Log("dailySign Fail:" + x); } }, (y) => { Debug.Log("dailySign Fail" + y); } ); }
/// <summary> /// 获取服务端的邮件 /// </summary> /// <param name="callback"></param> public void RequestMail(List <int> existMailids, Action callback = null) { MailListBody <int> body = new MailListBody <int>(existMailids, URLConfig.MailList); HttpRequestTool.SendMessage( body, (x) => { Debug.Log("get mail Sucess :" + x); JSONNode node = JSONNode.Parse(x); if (node["code"] == 0) { } else { if (callback != null) { callback(); } } }, (x) => { if (callback != null) { callback(); } Debug.LogError("get mail Fail :" + x); }, null, true ); }
public void HeartBeat() { return; if (!string.IsNullOrEmpty(LoginManager.Inst.Session)) { HeartBeatBody body = new HeartBeatBody(URLConfig.HeartBeat); HttpRequestTool.SendMessage( body, (respons) => { Debug.Log("HeartBeat Sucess :" + respons); JSONNode jsonNode = JSONNode.Parse(respons); int code = jsonNode["code"]; if (code == 0) { serverTime = (int)(jsonNode["serverTime"].AsDouble / 1000L); //signStatus = jsonNode["signin_status"]; //signDays = jsonNode["signin_days"]; EventDispatcher.TriggerEvent(EventKey.HeartBeat); } }, (respons) => { Debug.LogError("HeartBeat Fail :" + respons); }); } }
public void Login(Action <bool> callback = null) { loginStatus = LoginStatus.LOGINING; Dictionary <string, string> headerDic = new Dictionary <string, string>(); string timeStr = ((int)SystemClock.Now).ToString(); LoginBody body = GetLoginBody(); Header header = Header.GetHeader(headerDic); HttpRequestTool.SendMessage( body, (x) => { Debug.Log("Login Sucess :" + x); JSONNode respons = JSONNode.Parse(x); ParseLoginResponse(respons, callback); }, (x) => { Debug.LogError("Login Fail :" + x); if (callback != null) { callback.Invoke(false); } loginStatus = LoginStatus.LOGINFAIL; }, header, false); }
/// <summary> /// 获取关卡好友排行数据 /// </summary> /// <param name="level">关卡等级</param> /// <param name="successCallback">获取成功回调</param> public void GetFriendsLevelRankData(int level, int score, Action successCallback = null) { SelfRank = -1; GetFriendsLevelRankBody body = new GetFriendsLevelRankBody(URLConfig.GetFriendsLevelRank); body.level = level; body.score = score; HttpRequestTool.SendMessage( body , (x) => { Debug.Log("GetFriendsLevelRankData Sucess :" + x); UserLevelRankList = ParseLevelRankInfo(x); if (successCallback != null) { successCallback(); } } , (x) => { Debug.LogError("GetFriendsLevelRankData Fail :" + x); } ); }
private void ReSendNeedSessionHttpPacket() { while (needSessionHttpPackets != null && needSessionHttpPackets.Count > 0) { HttpRequestTool.SendMessage(needSessionHttpPackets.Dequeue()); } }
public void BindFBActual(string _fbtoken, string _fbid, Action bindSucessCallback = null) { BindBody body = new BindBody(URLConfig.BindUser); body.type = "facebook"; body.id = _fbid; body.thirdtoken = _fbtoken; body.gameUid = StorageManager.Inst.GetStorage <StorageAccountInfo>().Uid; HttpRequestTool.SendMessage( body, (x) => { JSONNode respons = JSONNode.Parse(x); int code = respons["code"]; if (code == 0) { fbid = _fbid; Debug.Log("Bind Success 1:" + x); if (bindSucessCallback != null) { bindSucessCallback(); } EventUtil.EventDispatcher.TriggerEvent(EventKey.FB_Bind_Sucess); UIManager.Inst.ShowMessage(LanguageTool.Get("bind_fb_success")); //弹出绑定成功面板 //UIManager.Inst.ShowUI(UIModuleEnum.UIFacebookTips, FacebookTipType.Login_Suc); } else if (code == -10008) { Debug.Log("Bind Success 2 :" + "该fb之前已经绑定过当前游戏账号了,无需再次操作"); UIManager.Inst.ShowMessage(LanguageTool.Get("bind_fb_success")); fbid = _fbid; //弹出绑定失败面板 //UIManager.Inst.ShowUI(UIModuleEnum.UIFacebookTips, FacebookTipType.Login_Fail); } else if (code == -10010) { Debug.Log("Bind Success 3 :" + "找到fb之前绑定过的游戏进度,即将切换到该游戏进度"); UIManager.Inst.ShowMessage(LanguageTool.Get("fb_bind_account_reloading")); // 清除fb数据 fbid = _fbid; // 清除本地缓存数据 PlayerPrefs.DeleteAll(); //重启游戏 // GameController.Inst.Restart(); SceneLoadManager.Inst.LoadScene(SceneName.StartScene); } }, (x) => { Debug.LogError("Bind Fail :" + x); }, null, true ); }
private static void PushBatchLog() { // 如果(前一次)正在上传,则本次直接退出(此时log已经加入到本地缓存中了) if (isPushingLog) { return; } // 是否还有本地log if (cacheLogArray.Count == 0) { return; } // 标记开始上传 isPushingLog = true; // 准备上传的log JSONArray pushingLogArray = new JSONArray(); foreach (var log in cacheLogArray) { pushingLogArray.Add(log); } Body logBody = new BatchLogBody(pushingLogArray, URLConfig.PushBatchLog); HttpRequestTool.SendMessage(logBody, (successData) => { DebugUtil.Log("push batch log success:" + successData); // 删除已经上传成功的log foreach (var log in pushingLogArray) { cacheLogArray.Remove(log); } // 如果本地log数量为0,则清除缓存;如果本地log还有,则重新写入缓存。 if (cacheLogArray.Count == 0) { PlayerPrefs.DeleteKey(BatchLogCacheKey); } else { PlayerPrefs.SetString(BatchLogCacheKey, cacheLogArray.ToString()); } isPushingLog = false; }, (failData) => { DebugUtil.LogError("push batch log fail:" + failData); isPushingLog = false; }); }
private static void Main(string[] args) { /* string URL = "http://175.98.160.67/vuewstest/WeatherForecast"; * WebRequest request = WebRequest.Create(URL); * request.ContentType = "application/json; charset=utf-8"; * WebResponse response = request.GetResponse() as WebResponse; * Stream responseStream = response.GetResponseStream(); * StreamReader reader = new StreamReader(responseStream, Encoding.UTF8); * Console.WriteLine(reader.ReadToEnd()); */ HttpRequestTool tool = new HttpRequestTool(); string v = tool.Post("http://175.98.160.67/vuewstest/chat/GetUserInfo", new { userId = "Player001" }); GetUserInfo user = JsonConvert.DeserializeObject <GetUserInfo>(v); }
public ActionResult Step3() { try { LogHelper.WriteInfo("Step3"); string imgUrl = string.Empty; string authCode = string.Empty; string phone = Session["Phone"].ToString(); if (Session["AuthCode"] != null) { authCode = Session["AuthCode"].ToString(); } else if (HttpContext.Request.Form["txtAuthCode"] != null && HttpContext.Request.Form["txtAuthCode"] != "") { authCode = HttpContext.Request.Form["txtAuthCode"]; } else { Step2(); } DefaultParametes def = HttpRequestTool.GetDefaultParametes(1, 4); EntryParametes entry = new EntryParametes() { authCode = authCode, phone = phone }; OutputParametes inp = HttpRequestTool.GetInputParametes(def, entry); HttpRequestResult httpResult = HttpRequestTool.CheckInputParametes(inp, 3); if (httpResult.state == 0) //成功 { return(View("Success")); } else if (httpResult.state == 1) //下一步 { Session.Add("AuthCode", authCode); return(View("Step4")); } else //异常 { ViewBag.Message = httpResult.context; return(View("Step3")); } } catch (Exception e) { LogHelper.WriteError(e.Message, e); return(View("Step3")); } }
public ActionResult Step4() { try { LogHelper.WriteInfo("Step4"); string imgUrl = string.Empty; string smsCode = HttpContext.Request.Form["txtSMSCode"]; object authCodeObj = Session["AuthCode"]; string authCode = authCodeObj != null?authCodeObj.ToString() : ""; if (smsCode == null || smsCode == "") { Step3(); return(View("Step4")); } string phone = Session["Phone"].ToString(); DefaultParametes def = HttpRequestTool.GetDefaultParametes(1, 5); EntryParametes entry = new EntryParametes() { smsCode = smsCode, authCode = authCode, phone = phone }; OutputParametes inp = HttpRequestTool.GetInputParametes(def, entry); HttpRequestResult httpResult = HttpRequestTool.CheckInputParametes(inp, 4); if (httpResult.state == 0) //成功 { return(View("Success")); } else //异常 { ViewBag.Message = httpResult.context; return(View("Step4")); } } catch (Exception e) { LogHelper.WriteError(e.Message, e); return(View("Step4")); } }
/// <summary> /// 存储至网络 /// </summary> public void SaveToRemote(ulong dataVersion) { //return; //if (LoginManager.Instance.loginStatus != LoginManager.LoginStatus.LOGINSUCESS // || Application.internetReachability == NetworkReachability.NotReachable) //{ // return; //} //if (!string.IsNullOrEmpty(SROptions.Current.GetUId)) //{ // DebugUtil.Log("setuid data not syndata"); // return; //} string jsonData = getJson(); if (!string.IsNullOrEmpty(jsonData)) { SyncPlayDataBody body = new SyncPlayDataBody(jsonData, URLConfig.SyncPlayData); //body.playdata = jsonData; syncLock = true; HttpRequestTool.SendMessage( body, (x) => { lastSavedRemoteVersion = dataVersion; Debug.Log("SaveToRemote Sucess :" + x); syncLock = false; }, (x) => { Debug.LogError("SaveToRemote Fail :" + x); syncLock = false; }, null, true ); } else { DebugUtil.LogError("StorageManager.SaveToRemote , Storage Local data do not exist"); } }
public ActionResult Step1() { try { LogHelper.WriteInfo("Step1"); string phone = HttpContext.Request["txtPhone"]; if (phone == null) //第二步返回 { phone = Session["Phone"].ToString(); } string imgUrl = string.Empty; DefaultParametes def = HttpRequestTool.GetDefaultParametes(1, 1); EntryParametes entry = new EntryParametes() { index = "1", phone = phone }; OutputParametes inp = HttpRequestTool.GetInputParametes(def, entry); HttpRequestResult httpResult = HttpRequestTool.CheckInputParametes(inp); if (httpResult.state == 0) //成功 { return(View("Success")); } else if (httpResult.state == 1) //失败 { imgUrl = HttpRequestTool.CreateHttpRequest(httpResult.context, 2); Session.Add("Phone", phone); return(View("Step2", (object)imgUrl)); } else //异常 { ViewBag.Message = httpResult.context; return(View("Index")); } } catch (Exception e) { LogHelper.WriteError(e.Message, e); return(View("Index")); } }
/// <summary> /// 获取手机账单信息 /// </summary> /// <param name="phone">手机号</param> /// <returns></returns> public string GetMobileBill(string phone) { try { LogHelper.WriteInfo("GetMobileBill"); DefaultParametes def = HttpRequestTool.GetDefaultParametes(1, 6); EntryParametes entry = new EntryParametes(); entry.loginName = phone; string url = HttpRequestTool.GetUrl(def, entry); string responsStr = HttpRequestTool.CreateHttpRequest(url); OutputParametes inp = HttpRequestTool.GetOutputParametes(responsStr); if (inp != null && inp.phoneList != null && inp.phoneList.Count > 0) { _baseDAL.SavePhoneList(inp.phoneList[0]); } return(responsStr); } catch (Exception e) { LogHelper.WriteError(e.Message, e); return(""); } }
/// <summary> /// 获取所有活动的时间 /// </summary> /// <param name="callback"></param> public void GetAllActivity(Action <List <ActivityItem> > callback = null) { //if (activities != null && activities.Count > 0) //{ // if (callback != null) // callback(activities); // return; //} Body body = new Body(URLConfig.GetActivityInfo); HttpRequestTool.SendMessage( body, (x) => { Debug.Log("get all activity Sucess :" + x); var acs = ParseActivityInfo(x); if (acs.Count > 0) { PlayerPrefs.SetString(AcitivityInfoCacheKey, x); activities = acs; EventDispatcher.TriggerEvent(EventKey.OnActivityItemsUpdate); if (callback != null) { callback(activities); } } }, (x) => { if (callback != null) { callback(null); } Debug.LogError("get all activity Fail :" + x); }, null, true ); }
/// <summary> /// 删除服务端的邮件 /// </summary> /// <param name="callback"></param> public void DeleteMail(List <int> deleteMailIds, Action <List <int> > callback = null) { MailListBody <int> body = new MailListBody <int>(deleteMailIds, URLConfig.DeleteMails); HttpRequestTool.SendMessage( body, (x) => { Debug.Log("delete mail Sucess :" + x); JSONNode node = JSONNode.Parse(x); if (node["code"] == 0) { if (callback != null) { callback(deleteMailIds); } } }, (x) => { Debug.LogError("delete mail Fail :" + x); }, null, true ); }
public override void OnInspectorGUI() { DrawDefaultInspector(); HttpRequestTool self = (HttpRequestTool)target; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.Toggle("Requesting", self._isRequesting); EditorGUI.EndDisabledGroup(); if (self._cacheMessageList == null) { return; } EditorGUILayout.Space(); GUILayout.Label("Cache Message List : " + self._cacheMessageList.Count); foreach (var item in self._cacheMessageList) { EditorGUILayout.BeginHorizontal(); GUILayout.Label(item.body.method); EditorGUILayout.EndHorizontal(); } }
/// <summary> /// 获取最新的版本信息 /// </summary> /// <param name="upgradeInfo"></param> /// <returns></returns> public IEnumerator Upgrade(GameController.UpgradeInfo upgradeInfo) { //yield break; if (!AssetBundleConfig.Inst.UseAssetBundle) { yield break; } //请求服务器版本信息 bool finishCheckVersion = false; DataContainer dataContainer = new DataContainer(); VersionInfoBody vb = new VersionInfoBody(URLConfig.AppVersion); vb.assetVersion = this._versionInfo.Version; HttpRequestTool.SendMessage(vb, (sucessData) => { DebugUtil.Log("appversion sucess:" + sucessData); JSONNode jsonNode = JSONNode.Parse(sucessData); latestAssetUrl = jsonNode["assetUrl"]; if (string.IsNullOrEmpty(assetUrl)) { assetUrl = latestAssetUrl; } if (upgradeInfo != null) { upgradeInfo.appUrl = jsonNode["appUrl"]; upgradeInfo.assetUrl = latestAssetUrl; upgradeInfo.assetUpdateType = jsonNode["assetUpdateType"]; upgradeInfo.appUpdateType = jsonNode["appUpdateType"]; upgradeInfo.appVersion = jsonNode["appVersion"]; upgradeInfo.assetVersion = jsonNode["assetVersion"]; if (upgradeInfo.appUpdateType == 1 || upgradeInfo.appUpdateType == 2) { upgradeInfo.noticeTitle = jsonNode["appNotice"]["noticeTitle"]; upgradeInfo.noticeContent = jsonNode["appNotice"]["noticeContent"]; TableBI.Version_Updating(vb.appVersion, upgradeInfo.appVersion, vb.assetVersion, upgradeInfo.assetVersion); } else if (upgradeInfo.assetUpdateType == 1) { upgradeInfo.noticeTitle = jsonNode["assetNotice"]["noticeTitle"]; upgradeInfo.noticeContent = jsonNode["assetNotice"]["noticeContent"]; TableBI.Version_Updating(vb.appVersion, upgradeInfo.appVersion, vb.assetVersion, upgradeInfo.assetVersion); } } finishCheckVersion = true; }, (failData) => { DebugUtil.LogError("appversion fail:" + failData); finishCheckVersion = true; }, null, false); //等待版本信息 while (!finishCheckVersion) { yield return(null); } }
public ActionResult Step2() { try { LogHelper.WriteInfo("Step2"); string imgUrl = string.Empty; string password = string.Empty; string phone = Session["Phone"].ToString(); string authCode = HttpContext.Request.Form["txtAuthCode"]; if (Session["Password"] != null) //如Session不为空 则为第三步返回 { password = Session["Password"].ToString(); } else if (HttpContext.Request.Form["txtPassword"] != null && HttpContext.Request.Form["txtPassword"] != "") //第二步正常点击下一步 { password = HttpContext.Request.Form["txtPassword"]; } else //第二步重新获取验证码 { Step1(); return(View("Step2")); } DefaultParametes def = HttpRequestTool.GetDefaultParametes(1, 2); EntryParametes entry = new EntryParametes() { password = password, authCode = authCode, phone = phone }; OutputParametes inp = HttpRequestTool.GetInputParametes(def, entry); HttpRequestResult httpResult = HttpRequestTool.CheckInputParametes(inp, 2); if (httpResult.state == 0) //成功 { return(View("Success")); } else if (httpResult.state == 2) //需图片验证码 { def = HttpRequestTool.GetDefaultParametes(1, 3); entry = new EntryParametes() { index = "3", phone = phone }; inp = HttpRequestTool.GetInputParametes(def, entry); httpResult = HttpRequestTool.CheckInputParametes(inp); if (httpResult.state == 1) //下一步 { Session.Add("Password", password); Session.Add("AuthCode", authCode); imgUrl = HttpRequestTool.CreateHttpRequest(httpResult.context, 2); return(View("Step3", (object)imgUrl)); } else //异常 { ViewBag.Message = httpResult.context; return(View("Step2")); } } else if (httpResult.state == 3) //需短信验证码 { Session.Add("AuthCode", authCode); return(View("Step4")); } else //异常 { ViewBag.Message = httpResult.context; return(View("Step2")); } } catch (Exception e) { LogHelper.WriteError(e.Message, e); return(View("Step2")); } }