IEnumerator ConnectToBindPaypal(Action successCallback, Action failCallback, string paypal) { isConnecting = true; List <IMultipartFormSection> iparams = new List <IMultipartFormSection>(); if (!string.IsNullOrEmpty(deviceID)) { iparams.Add(new MultipartFormDataSection("device_id", deviceID)); } iparams.Add(new MultipartFormDataSection("uuid", Save.data.uuid)); iparams.Add(new MultipartFormDataSection("paypal", paypal)); OnConnectingServer(); UnityWebRequest www = UnityWebRequest.Post(getdata_uri_dic[Server_RequestType.BindPaypal], iparams); yield return(www.SendWebRequest()); isConnecting = false; if (www.isNetworkError || www.isHttpError) { OnConnectServerFail(); failCallback?.Invoke(); } else { OnConnectServerSuccess(); string downText = www.downloadHandler.text; if (downText == "-1" || downText == "-2" || downText == "-3" || downText == "-4" || downText == "-5" || downText == "-6") { ShowConnectErrorTip(downText); failCallback?.Invoke(); } else { PlayerBindPaypalReceiveData paypalData = JsonMapper.ToObject <PlayerBindPaypalReceiveData>(www.downloadHandler.text); Save.data.allData.user_panel.user_paypal = paypalData.user_paypal; successCallback?.Invoke(); } } www.Dispose(); }
private IEnumerator ConnectToServerThread(Server_RequestType _RequestType, Action _ServerResponseOkCallback, Action _ServerResponseErrorCallback, Action _NetworkErrorCallback, bool _ShowConnectingWindow, params string[] _Args) { List <IMultipartFormSection> iparams = new List <IMultipartFormSection>(); #region request uuid if (string.IsNullOrEmpty(Save.data.uuid)) { UnityWebRequest requestUUID = UnityWebRequest.Get(getdata_uri_dic[Server_RequestType.GetUUID]); yield return(requestUUID.SendWebRequest()); if (requestUUID.isNetworkError || requestUUID.isHttpError) { OnConnectServerFail(); _NetworkErrorCallback?.Invoke(); } else { string downText = requestUUID.downloadHandler.text; Save.data.uuid = downText; } requestUUID.Dispose(); } #endregion iparams.Add(new MultipartFormDataSection("uuid", Save.data.uuid)); if (!string.IsNullOrEmpty(adID)) { Save.data.adid = adID; iparams.Add(new MultipartFormDataSection("device_id", adID)); } switch (_RequestType) { case Server_RequestType.AllData: #region request country if (string.IsNullOrEmpty(localCountry)) { UnityWebRequest requestCountry = UnityWebRequest.Get(getdata_uri_dic[Server_RequestType.GetLocalCountry]); yield return(requestCountry.SendWebRequest()); if (requestCountry.isNetworkError || requestCountry.isHttpError) { OnConnectServerFail(); _NetworkErrorCallback?.Invoke(); } else { string downText = requestCountry.downloadHandler.text; LocalCountryData countryData = JsonMapper.ToObject <LocalCountryData>(downText); localCountry = countryData.country.ToLower(); } requestCountry.Dispose(); } #endregion iparams.Add(new MultipartFormDataSection("app_name", Bi_name)); iparams.Add(new MultipartFormDataSection("country", localCountry)); iparams.Add(new MultipartFormDataSection("ad_ios", Platform)); break; case Server_RequestType.TaskData: iparams.Add(new MultipartFormDataSection("app_name", Bi_name)); break; case Server_RequestType.ClickSlotsCard: iparams.Add(new MultipartFormDataSection("lucky_id", _Args[0])); break; case Server_RequestType.GetSlotsReward: iparams.Add(new MultipartFormDataSection("reward_type", _Args[0])); //获得奖励类型 iparams.Add(new MultipartFormDataSection("reward_num", _Args[1])); //获得奖励数量 break; case Server_RequestType.FinishTask: iparams.Add(new MultipartFormDataSection("task_id", _Args[0])); iparams.Add(new MultipartFormDataSection("double", _Args[1])); //是否双倍 break; case Server_RequestType.BuyTickets: iparams.Add(new MultipartFormDataSection("reward_type", _Args[0])); //是否是看广告购买 break; case Server_RequestType.WatchRvEvent: break; case Server_RequestType.BindPaypal: iparams.Add(new MultipartFormDataSection("paypal", _Args[0])); break; case Server_RequestType.Cashout: iparams.Add(new MultipartFormDataSection("app_name", Bi_name)); iparams.Add(new MultipartFormDataSection("withdrawal_type", _Args[0])); //提现消耗类型 iparams.Add(new MultipartFormDataSection("withdrawal", _Args[1])); //提现消耗数量 iparams.Add(new MultipartFormDataSection("doller", _Args[2])); //提现现金数量 break; case Server_RequestType.GetLocalCountry: Master.Instance.ShowTip("Error code : can not use this connecting."); isConnecting = false; OnConnectServerSuccess(); yield break; case Server_RequestType.OpenBettingPrize: break; case Server_RequestType.ChangeHead_Name: if (!string.IsNullOrEmpty(_Args[0])) { iparams.Add(new MultipartFormDataSection("title_id", _Args[0])); //新头像id } if (!string.IsNullOrEmpty(_Args[1])) { iparams.Add(new MultipartFormDataSection("user_name", _Args[1])); //新名字 } break; case Server_RequestType.GetLevelUpReward: iparams.Add(new MultipartFormDataSection("double", _Args[0])); //升级奖励倍数 break; case Server_RequestType.GetNewPlayerReward: iparams.Add(new MultipartFormDataSection("double", _Args[0])); //奖励倍数,默认1 break; case Server_RequestType.GetUUID: Master.Instance.ShowTip("Error code : can not use this connecting."); isConnecting = false; OnConnectServerSuccess(); yield break; case Server_RequestType.GetCashoutRecordList: break; default: break; } if (_ShowConnectingWindow) { OnConnectingServer(); } UnityWebRequest www = UnityWebRequest.Post(getdata_uri_dic[_RequestType], iparams); yield return(www.SendWebRequest()); isConnecting = false; if (www.isNetworkError || www.isHttpError) { OnConnectServerFail(); _NetworkErrorCallback?.Invoke(); } else { OnConnectServerSuccess(); string downText = www.downloadHandler.text; www.Dispose(); if (int.TryParse(downText, out int errorcode) && errorcode < 0) { ShowConnectErrorTip(downText); _ServerResponseErrorCallback?.Invoke(); } else { switch (_RequestType) { case Server_RequestType.AllData: AllData allData = JsonMapper.ToObject <AllData>(downText); Save.data.allData = allData; Save.data.uuid = string.IsNullOrEmpty(allData.user_uuid) ? Save.data.uuid : allData.user_uuid; Ads._instance.InitFyber(allData.user_uuid); break; case Server_RequestType.TaskData: AllData_TaskData taskData = JsonMapper.ToObject <AllData_TaskData>(downText); Save.data.allData.lucky_schedule = taskData; break; case Server_RequestType.ClickSlotsCard: AllData_SlotsState slotsStateData = JsonMapper.ToObject <AllData_SlotsState>(downText); Save.data.allData.lucky_status = slotsStateData; break; case Server_RequestType.GetSlotsReward: PlayerGetSlotsRewardReceiveData receiveSlotsRewardData = JsonMapper.ToObject <PlayerGetSlotsRewardReceiveData>(downText); int slotsRewardType = int.Parse(_Args[0]); //int slotsRewardNum = int.Parse(_Args[1]); if (slotsRewardType == 0) { Save.data.allData.user_panel.user_gold = receiveSlotsRewardData.user_gold; Save.data.allData.user_panel.user_gold_live = receiveSlotsRewardData.user_gold_live; } else if (slotsRewardType == 2) { Save.data.allData.user_panel.user_doller = receiveSlotsRewardData.user_doller; Save.data.allData.user_panel.user_doller_live = receiveSlotsRewardData.user_doller_live; } else { Save.data.allData.user_panel.user_tickets = receiveSlotsRewardData.user_tickets; } break; case Server_RequestType.FinishTask: PlayerFinishTaskReceiveData receiveFinishTaskData = JsonMapper.ToObject <PlayerFinishTaskReceiveData>(downText); int length = _Args.Length; for (int i = 2; i < length; i++) //0为任务id,1为是否双倍 { Reward taskChangeTokenType = (Reward)Enum.Parse(typeof(Reward), _Args[i]); switch (taskChangeTokenType) { case Reward.Gold: Save.data.allData.user_panel.user_gold = receiveFinishTaskData.user_gold; Save.data.allData.user_panel.user_gold_live = receiveFinishTaskData.user_gold_live; break; case Reward.Cash: Save.data.allData.user_panel.user_doller = receiveFinishTaskData.user_doller; Save.data.allData.user_panel.user_doller_live = receiveFinishTaskData.user_doller_live; break; case Reward.Ticket: Save.data.allData.user_panel.user_tickets = receiveFinishTaskData.user_tickets; break; default: Debug.LogError("错误的任务完成变动类型"); break; } } break; case Server_RequestType.BuyTickets: PlayerBuyTicketReceiveData receiveBuyTicketsData = JsonMapper.ToObject <PlayerBuyTicketReceiveData>(downText); int isRv = int.Parse(_Args[0]); if (isRv == 1) { Save.data.allData.user_panel.user_tickets = receiveBuyTicketsData.user_tickets; } else { Save.data.allData.user_panel.user_gold = receiveBuyTicketsData.user_gold; Save.data.allData.user_panel.user_gold_live = receiveBuyTicketsData.user_gold_live; Save.data.allData.user_panel.user_tickets = receiveBuyTicketsData.user_tickets; } break; case Server_RequestType.WatchRvEvent: break; case Server_RequestType.BindPaypal: PlayerBindPaypalReceiveData paypalData = JsonMapper.ToObject <PlayerBindPaypalReceiveData>(downText); Save.data.allData.user_panel.user_paypal = paypalData.user_paypal; break; case Server_RequestType.Cashout: PlayerCashoutReceiveData receiveCashoutData = JsonMapper.ToObject <PlayerCashoutReceiveData>(downText); CashoutType cashoutType = (CashoutType)int.Parse(_Args[0]); switch (cashoutType) { case CashoutType.PT: Save.data.allData.fission_info.live_balance = receiveCashoutData.user_coin_live; break; case CashoutType.Cash: Save.data.allData.user_panel.user_doller_live = receiveCashoutData.user_doller_live; break; case CashoutType.Gold: Save.data.allData.user_panel.user_gold_live = receiveCashoutData.user_gold_live; break; } break; case Server_RequestType.GetLocalCountry: throw new ArgumentNullException("can not use this connecting."); case Server_RequestType.OpenBettingPrize: Save.data.allData.day_flag = true; break; case Server_RequestType.ChangeHead_Name: if (!string.IsNullOrEmpty(_Args[0])) { Save.data.allData.user_panel.user_title = int.Parse(_Args[0]); } if (!string.IsNullOrEmpty(_Args[1])) { Save.data.allData.user_panel.user_name = _Args[1]; } break; case Server_RequestType.GetLevelUpReward: GetLevelupRewardReceiveData receiveLevelupData = JsonMapper.ToObject <GetLevelupRewardReceiveData>(downText); Save.data.allData.user_panel.user_tickets = receiveLevelupData.user_tickets; Save.data.allData.user_panel.user_level = receiveLevelupData.user_level; Save.data.allData.user_panel.user_double = receiveLevelupData.user_double; Save.data.allData.user_panel.next_double = receiveLevelupData.next_double; Save.data.allData.user_panel.level_exp = receiveLevelupData.level_exp; Save.data.allData.user_panel.user_exp = receiveLevelupData.user_exp; Save.data.allData.user_panel.title_list = receiveLevelupData.title_list; Save.data.allData.user_panel.next_level = receiveLevelupData.next_level; break; case Server_RequestType.GetNewPlayerReward: GetNewPlayerRewardReceiveData receiveNewPlayerData = JsonMapper.ToObject <GetNewPlayerRewardReceiveData>(downText); Save.data.allData.user_panel.user_doller_live = receiveNewPlayerData.user_doller_live; break; case Server_RequestType.GetUUID: throw new ArgumentNullException("can not use this connecting."); case Server_RequestType.GetCashoutRecordList: AllData_CashoutRecordData casoutRecordData = JsonMapper.ToObject <AllData_CashoutRecordData>(downText); Save.data.allData.lucky_record = casoutRecordData; break; default: break; } _ServerResponseOkCallback?.Invoke(); } } }