//获取服务器资源更新数据
        public void GetUpdateInfo(Action <UpdateInfos> callBack = null, Action <string> errCallBack = null)
        {
            Header header = new Header();

            header.headers = new List <HeaderData>();
            header.headers.Add(new HeaderData()
            {
                key = "Gululu-Agent", value = GululuNetworkHelper.GetAgent()
            });
            header.headers.Add(new HeaderData()
            {
                key = "udid", value = GululuNetworkHelper.GetUdid()
            });
            header.headers.Add(new HeaderData()
            {
                key = "Accept-Language", value = GululuNetworkHelper.GetAcceptLang()
            });
            header.headers.Add(new HeaderData()
            {
                key = "Content-Type", value = "application/json"
            });
            string strHeader = this.JsonUtils.Json2String(header);

            UpdateRecord  updateRecord = this.ReadUpdateRecord();//读取本地更新记录
            UpdateRequest body         = new UpdateRequest()
            {
                partner      = AppInfo.Instance.Channel,
                apk_ver_code = AppInfo.Instance.VersionCode,
                res_ver_code = updateRecord != null ? updateRecord.ResVersionCode : 0//如果本地更新记录为空,资源版本号默认为0
            };
            string strBody = this.JsonUtils.Json2String(body);

            string url = this.UrlProvider.GetUpdateInfo(CupBuild.getCupSn());

            Debug.LogFormat("<><HotUpdateUtils.GetUpdateInfo>Header: {0}, Body: {1}, Url: {2}", strHeader, strBody, url);
            mNativeOkHttpMethodWrapper.post(url, strHeader, strBody, (result) =>
            {
                Debug.LogFormat("<><HotUpdateUtils.GetUpdateInfo>GotResponse: {0}", result);
                UpdateInfos updateInfos = this.JsonUtils.String2Json <UpdateInfos>(result);
                if (updateInfos != null && callBack != null)
                {
                    this.SetNewsestVersion(updateInfos);
                    callBack(updateInfos);
                }
                else if (errCallBack != null)
                {
                    string errorText = "Response data 'updateInfo' is null";
                    Debug.LogErrorFormat("<><HotUpdateUtils.GetUpdateInfo>Invalid data error: {0}", errorText);
                    errCallBack(errorText);
                }
            }, (errorResult) =>
            {
                if (errorResult != null && errCallBack != null)
                {
                    Debug.LogErrorFormat("<><HotUpdateUtils.GetUpdateInfo>Status error: {0}", errorResult.ErrorInfo);
                    errCallBack(errorResult.ErrorInfo);
                }
            });
        }
        public void PingService()
        {
            // Dictionary<string, string> head = new Dictionary<string, string>();

            string url = mUrlProvider.getHealthUrl(CupBuild.getCupSn());

            mNativeOkHttpMethodWrapper.get(url, "", successCallBack, errorCallBack);

            // mGululuNetwork.sendRequest(url, head, successCallBack, errorCallBack, HTTPMethods.Get);
        }
Esempio n. 3
0
        public string getToken()
        {
            string cupSn = CupBuild.getCupSn();

            string cupToken = mLocalCupAgent.getCupToken(CupBuild.getCupSn());

            Debug.Log("<><>cupSn<><>" + cupSn + "<><><><>" + cupToken);

            return(mLocalCupAgent.getCupToken(CupBuild.getCupSn()));
        }
        //         [Inject]
        //         public HeartBeatBody body { set; get; }

        public override void Execute()
        {
            GuLog.Info("<><HeartBeatCommand> Execute!");
            if (mLocalChildInfoAgent.getChildSN() == null || mLocalChildInfoAgent.getChildSN() == string.Empty)
            {
                GuLog.Info("<><HeartBeatCommand> child sn null!");
                FinishAndDispatchResult(ResponseErroInfo.GetErrorInfo(100, "child sn null!"));
                return;
            }
            getHeartBeatService.serviceHeartBeatBackSignal.AddListener(HeartBeatResult);
            getHeartBeatService.serviceHeartBeatErrBackSignal.AddListener(HeartBeatResultErr);

            SChild child = SChild.getBuilder().setFriend_count(10)
                           .setX_child_sn(mLocalChildInfoAgent.getChildSN()).setLanguage(languageUtils.getLanguageToAgentKey()).build();

            CupBuild.getCupHwMac((mac) => {
                Debug.Log("HeartBeatCommand mac:" + mac);
                SCup cup = SCup.getBuilder().setCup_hw_mac(mac)
#if UNITY_EDITOR
                           .setBattery(50)
                           .setCharge(false)
                           .setCapability(0)
                           .build();
#else
                           .setBattery(BatteryUtils.getBatteryCapacity(AndroidContextHolder.GetAndroidContext()))
                           .setCharge(BatteryUtils.isCharging(AndroidContextHolder.GetAndroidContext()))
                           .setCapability(0)
                           .build();
#endif
                SGame game = SGame.getBuilder()
                             .setGame_name(AppData.GetAppName())
#if UNITY_EDITOR
                             .setGame_version("1.0.31")
#else
                             .setGame_version(CupBuild.getAppVersionName())
#endif
                             .setPet_model(mLocalPetInfoAgent.getCurrentPet()).build();

                SExtra extra = SExtra.getBuilder().setTimestamp(DateUtil.GetTimeStamp()).setTimezone(8).build();

                HeartBeatBody body = HeartBeatBody.getBuilder().setChild(child).setCup(cup).setGame(game).setExtra(extra).build();


                getHeartBeatService.HeartBeat(body);
            });
        public void reNewToken(Action <Result> callBack, Action <Result> errCallBack)
        {
            Dictionary <string, string> body = new Dictionary <string, string>();

            body.Add("access_cup", CupBuild.getCupSn());

            HTTPRequest hTTPRequest = new HTTPRequest(new Uri(mUrlProvider.getCupTokenUrl(CupBuild.getCupSn())), HTTPMethods.Post, (request, response) =>
            {
                Debug.LogFormat("--------AuthenticationUtils.reNewToken.GotResponse--------");
                Debug.LogFormat("response.IsSuccess: {0}", response.IsSuccess);
                Debug.LogFormat("response.DataAsText: {0}", response.DataAsText);
                Debug.LogFormat("response.Message: {0}", response.Message);
                Debug.LogFormat("request.State: {0}", request.State);

                if (response.IsSuccess)
                {
                    TokenResponseData mTokenResponseData = mJsonUtils.String2Json <TokenResponseData>(response.DataAsText);
                    string token = mTokenResponseData.token;
                    mLocalCupAgent.saveCupToken(CupBuild.getCupSn(), token);
                    if (callBack != null)
                    {
                        callBack(Result.Success(token));
                    }
                }
                else
                {
                    if (errCallBack != null)
                    {
                        errCallBack(Result.Error());
                    }
                }
            });

            string strBody = mJsonUtils.DicToJsonStr(body);

            hTTPRequest.RawData = Encoding.UTF8.GetBytes(strBody);

            hTTPRequest.AddHeader("Gululu-Agent", mGululuNetworkHelper.GetAgent());
            hTTPRequest.AddHeader("udid", mGululuNetworkHelper.GetUdid());
            hTTPRequest.AddHeader("Accept-Language", mGululuNetworkHelper.GetAcceptLang());
            hTTPRequest.SetHeader("Content-Type", "application/json");
            hTTPRequest.Send();
        }
        public void HeartBeat(HeartBeatBody body)
        {
            // Dictionary<string, string> head = new Dictionary<string, string>();

            string prod_name = AppData.GetAppName();

            string x_cup_sn = CupBuild.getCupSn();

            string strbody = mJsonUtils.Json2String(body);

            GuLog.Info("<><HeartBeatService> x_cup_sn:" + x_cup_sn + "  strbody:" + strbody);


            // mGululuNetwork.sendRequest(mUrlProvider.HeartBeatUrl(prod_name, x_cup_sn), head, strbody, (r) => {

            //     GuLog.Debug("<><HeartBeatService> Succeed:" + r);
            //     HeartBeatResponse info = mJsonUtils.String2Json<HeartBeatResponse>(r);

            //     modelHeartBeat.responseHeartBeat = info;

            //     serviceHeartBeatBackSignal.Dispatch(modelHeartBeat.responseHeartBeat);

            // }, (e) => {
            //     GuLog.Debug("<><HeartBeatService> Error:" + e.ErrorCode + e.ErrorInfo);
            //     serviceHeartBeatErrBackSignal.Dispatch(e);
            // }, HTTPMethods.Post);


            mNativeOkHttpMethodWrapper.post(mUrlProvider.HeartBeatUrl(prod_name, x_cup_sn), "", strbody, (r) => {
                GuLog.Info("<><HeartBeatService> Succeed:" + r);
                HeartBeatResponse info = mJsonUtils.String2Json <HeartBeatResponse>(r);

                modelHeartBeat.responseHeartBeat = info;

                serviceHeartBeatBackSignal.Dispatch(modelHeartBeat.responseHeartBeat);
            }, (e) => {
                GuLog.Info("<><HeartBeatService> Error:" + e.ErrorCode + e.ErrorInfo);
                serviceHeartBeatErrBackSignal.Dispatch(e);
            });
        }
        //读取本地资源更新记录
        public UpdateRecord ReadUpdateRecord()
        {
            UpdateRecord updateRecord = null;

            if (!File.Exists(this.fileName))
            {
                updateRecord = new UpdateRecord()
                {
                    CupSN          = CupBuild.getCupSn(),
                    CupType        = "Go2",
                    TimeStamp      = "",
                    ApkVersion     = AppInfo.Instance.Version,
                    ApkVersionCode = AppInfo.Instance.VersionCode,
                    ResVersionCode = 0,
                    FileList       = new List <LocalFileInfo>()
                };
            }
            else
            {
                try
                {
                    string content = "";
                    using (FileStream fs = new FileStream(this.fileName, FileMode.Open, FileAccess.Read))
                    {
                        using (StreamReader sr = new StreamReader(fs))
                        {
                            content = sr.ReadToEnd();
                            sr.Close();
                        }
                        fs.Close();
                    }
                    updateRecord = this.JsonUtils.String2Json <UpdateRecord>(content);
                }
                catch (Exception ex)
                {
                    Debug.LogErrorFormat("<><HotUpdateUtils.ReadUpdateRecord>Error: {0}", ex.Message);
                }
            }
            return(updateRecord);
        }
        private void saveData(RegisterResponseData info)
        {
            if (!string.IsNullOrEmpty(info.x_child_sn))
            {
                //Debug.LogFormat("--------SaveSN--------RegisterCupService.saveData: {0}", info.x_child_sn);
                mLocalChildInfoAgent.saveChildSN(info.x_child_sn);
                FlurryUtil.LogEvent("Pair_Get_Childsn_Sunccess_Event");
            }
            else
            {
                FlurryUtil.LogEvent("Pair_Get_Childsn_Fail_Event");
                GuLog.Warning("pair data childsn is null");
            }

            //删除本地数据
            this.LocalPetInfoAgent.Clear();
            GuLog.Debug("<><RegisterCupService>Clear currentPet");
            this.LocalUnlockedPetsAgent.Clear();
            GuLog.Debug("<><RegisterCupService>Clear unlockedPets");

            //保存网络数据
            //mLocalCupAgent.saveCupToken(CupBuild.getCupSn(), info.token);
            mNativeDataManager.saveToken(info.token);
            mLocalCupAgent.saveCupID(CupBuild.getCupSn(), info.x_cup_sn);
            LocalPetInfoAgent.saveCurrentPet(info.pet_model);
            //重新保存语言数据
            this.PlayerDataManager.SaveLanguage(this.PlayerDataManager.Language);

            if (info.timestamp > 0)
            {
                mTimeManager.setServerTime(info.timestamp * (1000L));
            }

            if (!string.IsNullOrEmpty(info.timezone))
            {
                mTimeManager.setTimeZone(info.timezone);
            }
        }
        void Awake()
        {
            BatteryUtils.init();
            FlurryUtil.Init();
            AsyncActionHelper.Instance.init();
            FlurryUtil.SetUserId(CupBuild.getCupSn());
            FlurryUtil.LogEvent("Hank_Splashscreen_View");
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
            GameObject objGlobalContextView = null; /*= GameObject.Find("GlobalContextView");
                                                     * if (objGlobalContextView == null)*/

            {
                objGlobalContextView      = new GameObject();
                objGlobalContextView.name = "GlobalContextView";
                GlobalContextView globalContextView = objGlobalContextView.AddComponent <GlobalContextView>();
                GameObject.DontDestroyOnLoad(globalContextView);
            }
#if (UNITY_IOS || UNITY_ANDROID) && (!UNITY_EDITOR)
#if WETEST_SDK
            objGlobalContextView.AddComponent <WeTest.U3DAutomation.U3DAutomationBehaviour>();
            BuglyAgent.RegisterLogCallback(WeTest.U3DAutomation.CrashMonitor._OnLogCallbackHandler);
#endif
#endif
        }
        public void PostGameData(string paras)
        {
            string prod_name = AppData.GetAppName();

            string x_child_sn = mLocalChildInfoAgent.getChildSN();

            if (x_child_sn == string.Empty)
            {
                return;
            }

            string x_cup_sn = CupBuild.getCupSn();

            GuLog.Info("PostGameData:" + paras);
            mNativeOkHttpMethodWrapper.post(mUrlProvider.GameDataUrl(x_child_sn, prod_name, x_cup_sn), "", paras, (r) => {
                PostGameDataResponse info = mJsonUtils.String2Json <PostGameDataResponse>(r);

                modelPostGameData.responsePostGameData = info;

                servicePostGameDataBackSignal.Dispatch(modelPostGameData.responsePostGameData);
            }, (e) => {
                servicePostGameDataErrBackSignal.Dispatch(e);
            });
        }
Esempio n. 11
0
        public void GetSameStarFriendsInfo(Action <SameStarFriendsInfo> callBack = null, Action <string> errCallBack = null)
        {
            string url = UrlProvider.GetSameStarFriendsInfo(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn());

            NativeOkHttpMethodWrapper.get(url, "", (result) =>
            {
                SameStarFriendsInfo sameStarFriendsInfo = this.JsonUtils.String2Json <SameStarFriendsInfo>(result);
                if (callBack != null)
                {
                    callBack(sameStarFriendsInfo);
                }
            },
                                          (errorInfo) =>
            {
                if (errCallBack != null)
                {
                    errCallBack(errorInfo.ErrorInfo);
                }
                Debug.LogErrorFormat("<><WorldMapUtils.GetSameStarFriendsInfo>Error: {0}", errorInfo.ErrorInfo);
            });
        }
Esempio n. 12
0
        public void GetAllMissionInfo(Action <AllMissionInfo> callBack = null, Action <string> errCallBack = null)
        {
            string url = UrlProvider.GetAllMissionInfo(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn());

            Debug.LogFormat("<><WorldMapUtils.GetAllMissionInfo>ChildSN: {0}, CupSN: {1}, Url: {2}", this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn(), url);

            NativeOkHttpMethodWrapper.get(url, "", (result) =>
            {
                Debug.LogFormat("<><WorldMapUtils.GetAllMissionInfo>Result: {0}", result);
                GetAllMissionInfoResponse response = this.JsonUtils.String2Json <GetAllMissionInfoResponse>(result);
                if (response != null && response.highest_mission_data != null)
                {
                    AllMissionInfo allMissionInfo = new AllMissionInfo();
                    string starID    = "";
                    string missionID = "";
                    for (int i = 0; i < response.highest_mission_data.Count; i++)
                    {
                        starID    = response.highest_mission_data[i].star_id;
                        missionID = response.highest_mission_data[i].mission_id;
                        if (string.IsNullOrEmpty(starID) || string.IsNullOrEmpty(missionID) && int.Parse(starID) != PlayerData.defaultStar)
                        {
                            Debug.LogAssertionFormat("<><WorldMapUtils.GetAllMissionInfo>Response is invalid, starID: {0}, missionID: {1}", starID, missionID);
                            continue;
                        }
                        else if (string.IsNullOrEmpty(missionID) && int.Parse(starID) == PlayerData.defaultStar)
                        {
                            missionID = PlayerData.startMission.ToString();
                        }

                        allMissionInfo.Items.Add(new MissionInfo()
                        {
                            StarID = starID, MissionID = missionID
                        });
                    }
                    Debug.LogFormat("<><WorldMapUtils.GetAllMissionInfo>Response data is valid: {0}", result);
                    if (callBack != null)
                    {
                        callBack(allMissionInfo);
                    }
                }
            },
                                          (errorInfo) =>
            {
                Debug.LogErrorFormat("<><WorldMapUtils.GetAllMissionInfo>Error: {0}", errorInfo.ErrorInfo);
                if (errCallBack != null)
                {
                    errCallBack(errorInfo.ErrorInfo);
                }
            });
        }
Esempio n. 13
0
 //数据同步
 private void SyncUnlockedPets()
 {
     if (this.actionDatas.Count > 0)
     {
         ActionData actionData = this.actionDatas[0];
         Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets--------Header: {0}, Body: {1}, SendTimes: {2}", actionData.Header, actionData.Body, actionData.SendTimes);
         mNativeOkHttpMethodWrapper.post(this.UrlProvider.GetUnlockedPets(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn()), actionData.Header, actionData.Body, (result) =>
         {
             Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.GotResponse--------{0}", result);
             RemotePetsInfo remotePetsInfo = this.JsonUtils.String2Json <RemotePetsInfo>(result);
             this.LocalUnlockedPetsAgent.SaveUnlockedPets(remotePetsInfo.pets);
             if (actionData.OnSuccess != null)
             {
                 Loom.QueueOnMainThread(() => actionData.OnSuccess(Result.Success(result)));
             }
             Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.Success--------\n{0}", result);
             //检查数据
             if (this.actionDatas.Count > 0)
             {
                 this.actionDatas.RemoveAt(0);   //移除已经执行成功的数据
                 if (this.actionDatas.Count > 0) //执行下一条数据
                 {
                     this.SyncUnlockedPets();
                 }
             }
         }, (errorResult) =>
         {
             Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.Error--------{0}", Result.Error(errorResult.ErrorInfo));
             if (actionData.OnFailed != null)
             {
                 Loom.QueueOnMainThread(() => actionData.OnFailed(Result.Error(errorResult.ErrorInfo)));
             }
             //检查数据
             if (this.actionDatas.Count > 0)
             {
                 if (this.actionDatas[0].SendTimes > 0)
                 {//重复上传(最多3次)
                     this.actionDatas[0].SendTimes -= 1;
                     Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.Repeat--------SendTimes: {0}, Body: {1}", actionData.SendTimes, actionData.Body);
                     this.SyncUnlockedPets();
                 }
                 else
                 {//3次重传失败放弃
                     this.actionDatas.RemoveAt(0);
                     Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.Abandon--------SendTimes: {0}, Body: {1}", actionData.SendTimes, actionData.Body);
                 }
             }
         });
     }
 }
Esempio n. 14
0
        public void uploadIntakeLogs(IntakeLogs mIntakeLogs, string current_child_sn, Action <UpLoadIntakeLogsResponseData> callBack, Action <ResponseErroInfo> errCallBack)
        {
            GuLog.Info("UploadChildIntakeLogsService uploadIntakeLogs");
            Dictionary <string, string> head = new Dictionary <string, string>();

            string body = mJsonUtils.Json2String(mIntakeLogs);

            // mGululuNetwork.sendRequest(mUrlProvider.getChildIntakeLogUrl(current_child_sn,CupBuild.getCupSn()), head, body, (result) =>
            // {

            // UpLoadIntakeLogsResponseData info = mJsonUtils.String2Json<UpLoadIntakeLogsResponseData>(result);
            //  mUploadChildIntakeLogsModel.mUpLoadIntakeLogsResponseData = info;
            // callBack(info);

            // }, (ecb) =>
            // {
            //     errCallBack(ecb);
            // }, HTTPMethods.Post);

            mNativeOkHttpMethodWrapper.post(mUrlProvider.getChildIntakeLogUrl(current_child_sn, CupBuild.getCupSn()), "", body, (result) => {
                GuLog.Info("UploadChildIntakeLogsService onresponse");
                UpLoadIntakeLogsResponseData info = mJsonUtils.String2Json <UpLoadIntakeLogsResponseData>(result);
                mUploadChildIntakeLogsModel.mUpLoadIntakeLogsResponseData = info;
                callBack(info);
            }, (errorResult) => {
                GuLog.Info("UploadChildIntakeLogsService faliure");
                errCallBack(errorResult);
            });
        }
Esempio n. 15
0
        private AndroidJavaObject getOkHttpMethodWrapper()
        {
            AndroidJavaClass okHttpMethodWrapperBuilder = new AndroidJavaClass("com.bowhead.hank.network.OKHttpMethodWrapperBuilder");

            return(okHttpMethodWrapperBuilder.CallStatic <AndroidJavaObject>("getOkHttpMethodWrapper", urlProvider.getCupTokenUrl(CupBuild.getCupSn())));
        }
Esempio n. 16
0
 public string GetAgent()
 {
     return("GululuCupHank/" + CupBuild.getAppVersionName() + ";" + "Unity/" + SystemInfo.operatingSystem + ";" + SystemInfo.deviceName + "/" + SystemInfo.deviceModel);
 }
Esempio n. 17
0
        //获取所有已购买的配饰列表
        public void GetPaidItems(Action <GetPaidItemsResponse> callBack = null, Action <string> errCallBack = null)
        {
            string url = this.UrlProvider.GetPaidItems(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn());

            //Debug.LogFormat("<><PetAccessoryUtils.GetPaidItems>ChildSN: {0}, CupSN: {1}, Url: {2}", this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn(), url);

            this.NativeOkHttpMethodWrapper.get(url, "", (result) =>
            {
                //Debug.LogFormat("<><PetAccessoryUtils.GetPaidItems>Result: {0}", result);
                GetPaidItemsResponse response = this.JsonUtils.String2Json <GetPaidItemsResponse>(result);
                if (response != null && !string.IsNullOrEmpty(response.status) && response.status.ToUpper() == "OK")
                {
                    Debug.LogFormat("<><PetAccessoryUtils.GetPaidItems>Response data is valid: {0}", result);
                    if (callBack != null)
                    {
                        callBack(response);
                    }
                }
            },
                                               (errorInfo) =>
            {
                Debug.LogErrorFormat("<><PetAccessoryUtils.GetPaidItems>Error: {0}", errorInfo.ErrorInfo);
                if (errCallBack != null)
                {
                    errCallBack(errorInfo.ErrorInfo);
                }
            });
        }
        public void sendRegisterCupRequest(Dictionary <string, string> head, string strbody)
        {
            Header headerentity = new Header();

            headerentity.headers = new List <HeaderData>();

            if (head != null)
            {
                foreach (KeyValuePair <string, string> headr in head)
                {
                    HeaderData data = new HeaderData();
                    data.key   = headr.Key;
                    data.value = headr.Value;
                    headerentity.headers.Add(data);
                }
            }

            string strHeader = mJsonUtils.Json2String(headerentity);


            mNativeOkHttpMethodWrapper.post(mUrlProvider.getRegisterUrl(AppData.GetAppName(), CupBuild.getCupSn()), strHeader, strbody, (result) =>
            {
                try
                {
                    GuLog.Info("Register response data :" + result);
                    RegisterResponseData info            = mJsonUtils.String2Json <RegisterResponseData>(result);
                    modelRegisterCup.responseRegisterCup = info;

                    Loom.QueueOnMainThread(() =>
                    {
                        if (mValidateResponseData.isValidRegisterResponseData(info))
                        {
                            //Debug.LogFormat("--------SaveSN--------RegisterCupService.sendRegisterCupRequest: {0}", info.x_child_sn);
                            saveData(info);
                            serviceRegisterCupBackSignal.Dispatch(info);
                        }
                        else
                        {
                            Debug.LogError("response data is invalid:" + result);
                            serviceRegisterCupErrBackSignal.Dispatch(ResponseErroInfo.GetErrorInfo(GululuErrorCode.RESPONSE_DATA_ERROR, "response data is invalid"));
                        }
                    });
                }
                catch
                {
                    Loom.QueueOnMainThread(() =>
                    {
                        Debug.LogError("response data is error:" + result);
                        serviceRegisterCupErrBackSignal.Dispatch(ResponseErroInfo.GetErrorInfo(GululuErrorCode.RESPONSE_DATA_ERROR, "response data is error"));
                    });
                }
            }, (errorResult) =>
            {
                Loom.QueueOnMainThread(() =>
                {
                    serviceRegisterCupErrBackSignal.Dispatch(errorResult);
                });
            });
        }
        public void uploadChildFriendsinfo(FriendInfo mFriendInfo, string current_child_sn, Action <UploadFriendsInfoData> successCallback, Action <ResponseErroInfo> errorCallBack)
        {
            Dictionary <string, string> head = new Dictionary <string, string>();
            string body = mJsonUtils.Json2String(mFriendInfo);

            // mGululuNetwork.sendRequest(mUrlProvider.getUploadChildFriendsUrl(current_child_sn,CupBuild.getCupSn()),head,body,(result)=>{
            // UploadFriendsInfoData info = mJsonUtils.String2Json<UploadFriendsInfoData>(result);
            // mUploadChildFriendsModel.mUploadFriendsInfoData = info;
            // successCallback(info);

            // },(ecb)=>{
            //     errorCallBack(ecb);
            // },HTTPMethods.Post);

            mNativeOkHttpMethodWrapper.post(mUrlProvider.getUploadChildFriendsUrl(current_child_sn, CupBuild.getCupSn()), "", body, (result) => {
                UploadFriendsInfoData info = mJsonUtils.String2Json <UploadFriendsInfoData>(result);
                mUploadChildFriendsModel.mUploadFriendsInfoData = info;
                successCallback(info);
            }, (errorResult) => {
                errorCallBack(errorResult);
            });
        }
Esempio n. 20
0
        protected void BuildBackAckBody(HeartBeatAck ack, string msg, string status, string todoid, List <ActionPostBodyValue> values = null)
        {
            _ackAdress             = GetAckAddress(ack);
            _backAckBody           = ActionPostBody.getBuilder().build();
            _backAckBody.cup_hw_sn = CupBuild.getCupSn();
            _backAckBody.msg       = msg;
            _backAckBody.status    = status;
            _backAckBody.todoid    = todoid;
            if (values == null)
            {
                _backAckBody.values = new List <ActionPostBodyValue>();
            }
            else
            {
                _backAckBody.values = values;
            }
            // body.values.Add(new ActionPostBody.Value
            // {
            //     key = "timestamp",
            //     value = DateUtil.GetTimeStamp().ToString()
            // });

//             backAckBody.values.Add(ActionPostBodyValue.getBuilder().setKey("timestamp").setValue( DateUtil.GetTimeStamp().ToString()).build());
            // body.values.Add(new ActionPostBody.Value
            // {
            //     key = "timezone",
            //     value = "8"
            // });

//             backAckBody.values.Add(ActionPostBodyValue.getBuilder().setKey("timezone").setValue("8").build());
            // string param = new NetUtils().Json2String<ActionPostBody>(body);

            // IUrlProvider mUrlProvider = new UrlProvider();
            // INetUtils mNetUtils = new NetUtils();
            // IAuthenticationUtils mAuthenticationUtils = new AuthenticationUtils();
            // mAuthenticationUtils.mNetUtils = mNetUtils;
            // mAuthenticationUtils.mUrlProvider = mUrlProvider;
            // GululuNetwork mGululuNetwork = new GululuNetwork();
            // mGululuNetwork.mAuthenticationUtils = mAuthenticationUtils;
            // mGululuNetwork.mNetUtils = mNetUtils;

            // mGululuNetwork.sendRequest(GetAckAddress(ack), null, param, (r) =>
            // {

            //     GuLog.Log("ackRet:" + r);

            // }, (e) =>
            // {
            //     GuLog.Log("ackRet Error:" + e.ErrorInfo);
            // }, HTTPMethods.Post);

//             sendAckService.serviceSendAckBackSignal.AddListener((result)=>{
//                 GuLog.Log("ackRet:" + result);
//             });
//
//             sendAckService.serviceSendAckErrBackSignal.AddListener((errorResult)=>{
//                 GuLog.Log("ackRet Error:" + errorResult.ErrorInfo);
//             });
//
//             sendAckService.sendAck(GetAckAddress(ack),backAckBody);
        }
Esempio n. 21
0
 //发送购买配饰数据
 private void SendPetAccessoryOrder()
 {
     if (this.actionDatas.Count > 0)
     {
         ActionData actionData = this.actionDatas[0];
         Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Header: {0}, Body: {1}, SendTimes: {2}", actionData.Header, actionData.Body, actionData.SendTimes);
         Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Url: {0}", this.UrlProvider.BuyPetAccessories(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn()));
         this.NativeOkHttpMethodWrapper.post(this.UrlProvider.BuyPetAccessories(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn()), actionData.Header, actionData.Body, (result) =>
         {
             Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>GotResponse: {0}", result);
             OrderReceipt orderReceipt = this.JsonUtils.String2Json <OrderReceipt>(result);
             this.OrderReceiptSignal.Dispatch(orderReceipt);
             if (actionData.OnSuccess != null)
             {
                 Loom.QueueOnMainThread(() => actionData.OnSuccess(Result.Success(result)));
             }
             Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Success:\n{0}", result);
             //检查数据
             if (this.actionDatas.Count > 0)
             {
                 this.lastActionData = null;
                 this.actionDatas.RemoveAt(0);   //移除已经执行成功的数据
                 if (this.actionDatas.Count > 0) //执行下一条数据
                 {
                     this.SendPetAccessoryOrder();
                 }
             }
         }, (errorResult) =>
         {
             Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Error: {0}", errorResult.ErrorInfo);
             if (actionData.OnFailed != null)
             {
                 Loom.QueueOnMainThread(() => actionData.OnFailed(Result.Error(errorResult.ErrorInfo)));
             }
             //检查数据
             if (this.actionDatas.Count > 0)
             {
                 this.lastActionData = null;
                 if (this.actionDatas[0].SendTimes > 0)
                 {//重复上传(最多3次)
                     this.actionDatas[0].SendTimes -= 1;
                     Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Repeat, SendTimes: {0}, Body: {1}", actionData.SendTimes, actionData.Body);
                     this.SendPetAccessoryOrder();
                 }
                 else
                 {//3次重传失败放弃
                     this.actionDatas.RemoveAt(0);
                     Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Abandon, SendTimes: {0}, Body: {1}", actionData.SendTimes, actionData.Body);
                 }
             }
         });
     }
 }
        //点击确认
        public void Confirm()
        {
            if (this.accessoryTypes.BackButtonSelected)
            {//退出换装页
                this.CloseViewSignal.Dispatch(true);
            }
            else if (!this.accessories.HasItems)
            {//如果当前商店中无配饰
                return;
            }
            else if (!this.accessories.CurrentButton.Accessory.Suitable(this.PlayerDataManager.CurrentPet) && !this.suitLockView.IsOpen)
            {//显示配饰不适用提示页面
                this.audioPlayer.Stop();
                this.suitLockView.Open(this.accessories.CurrentButton.Accessory);
                FlurryUtil.LogEventWithParam("mall_scene_lock_suitable", "accessory_name", this.accessories.CurrentButton.Accessory.Name);
            }
            else if (this.suitLockView.IsOpen)
            {//关闭配饰不适用提示页面
                this.suitLockView.Close();
            }
            else if (this.accessories.CurrentButton.Paid && !this.accessories.CurrentButton.Worn)
            {//已拥有:穿上当前配饰
                this.PutOn(this.accessories.CurrentButton.Accessory);
                this.PlaySound("mall_put_on_accessory");
                FlurryUtil.LogEventWithParam("mall_scene_change", "accessory_name", this.accessories.CurrentButton.Accessory.Name);
            }
            else if (this.accessories.CurrentButton.Paid && this.accessories.CurrentButton.Worn)
            {//已拥有:脱掉当前配饰
                this.TakeOff(this.accessories.CurrentButton.Accessory);
                this.PlaySound(this.accessories.CurrentButton.Accessory.CanWear ? "mall_take_off_accessory" : "mall_spirit_out");
            }
            else if (this.accessories.CurrentButton.Accessory.Level > this.PlayerDataManager.playerLevel && !this.levelLockView.IsOpen)
            {//显示等级不够提示页面
                this.audioPlayer.Stop();
                this.levelLockView.Open(this.accessories.CurrentButton.Accessory);
                FlurryUtil.LogEventWithParam("mall_scene_lock_level", "accessory_name", this.accessories.CurrentButton.Accessory.Name);
            }
            else if (this.levelLockView.IsOpen)
            {//关闭等级不够提示页面
                this.levelLockView.Close();
            }
            else if (!this.accessories.CurrentButton.Accessory.Opened && !this.openLockView.IsOpen)
            {//显示未开放提示页面
                this.audioPlayer.Stop();
                this.openLockView.Open(this.accessories.CurrentButton.Accessory);
            }
            else if (this.openLockView.IsOpen)
            {//关闭未开放提示页面
                this.openLockView.Close();
            }
            else if (this.goalLockView.IsOpen)
            {//关闭饮水目标未达标提示页面
                this.goalLockView.Close();
            }
            else if (this.coinLockView.IsOpen)
            {//关闭金币不足提示页面
                this.coinLockView.Close();
            }
            else if (this.wifiLockView.IsOpen)
            {//关闭无网络连接提示页面
                this.wifiLockView.Close();
            }
            else if (this.qrCodeView.IsOpen)
            {//关闭二维码页面
                this.qrCodeView.Close();
            }
            else if (!this.accessories.CurrentButton.Paid && this.accessories.CurrentButton.Accessory.Coin)
            {//金币购买的配饰:钱够→扣钱→配饰进包裹→记录穿戴数据→配饰图标状态更新
                if (this.FundDataManager.GetItemCount(this.FundDataManager.GetCoinId()) >= this.accessories.CurrentButton.Accessory.Price)
                {
                    this.accessories.CurrentButton.Paid = true;
                    this.AccessoryDataManager.AddItem(this.accessories.CurrentButton.Accessory.ID);                                         //配饰添加到包裹
                    this.FundDataManager.ExpendCoin(this.FundDataManager.GetCoinId(), (int)this.accessories.CurrentButton.Accessory.Price); //扣钱
                    SoundPlayer.GetInstance().StopAllSoundExceptMusic();
                    SoundPlayer.GetInstance().PlaySoundInChannal("mall_purchase_qr_complete", this.audioPlayer, 0.2f);
                    this.PutOn(this.accessories.CurrentButton.Accessory);
                    ExpUI.Instance.Show(this.accessories.CurrentButton.Accessory.Exp, 0, -25, 25, GameObject.FindGameObjectWithTag("ExpUILayer").transform);
                    this.PlayerDataManager.exp += this.accessories.CurrentButton.Accessory.Exp;
                    this.UIState.PushNewState(UIStateEnum.eExpIncrease, this.PlayerDataManager.GetExpPercent());
                    this.UpdateExpAndCoinSignal.Dispatch();
                    FlurryUtil.LogEventWithParam("mall_scene_purchase", "accessory_name", this.accessories.CurrentButton.Accessory.Name);
                }
                else if (!this.coinLockView.IsOpen)
                {//显示金币不足提示页面
                    this.audioPlayer.Stop();
                    this.coinLockView.Open();
                }
            }
            else if (!this.accessories.CurrentButton.Paid && this.accessories.CurrentButton.Accessory.Cash && !this.qrCodeView.IsOpen)
            {     //货币购买的配饰:向服务器发送请求,获取二维码并打开页面显示
                if (this.PlayerDataManager.currIntake < this.PlayerDataManager.GetDailyGoal() && !this.goalLockView.IsOpen)
                { //显示饮水目标未达标提示页面
                    this.audioPlayer.Stop();
                    this.goalLockView.Open(this.accessories.CurrentButton.Accessory);
                    FlurryUtil.LogEventWithParam("mall_scene_lock_goal", "accessory_name", this.accessories.CurrentButton.Accessory.Name);
                }
#if !UNITY_EDITOR && UNITY_ANDROID
                else if (!NativeWifiManager.Instance.IsConnected() && !this.wifiLockView.IsOpen)
                {//显示无网络连接提示页面
                    this.audioPlayer.Stop();
                    this.wifiLockView.Open();
                }
#else
                else if (!this.wifiLockView.IsOpen)
                {//显示无网络连接提示页面
                    this.audioPlayer.Stop();
                    this.wifiLockView.Open();
                }
#endif
                else
                {
#if !UNITY_EDITOR && UNITY_ANDROID
                    this.IsBuying = true;
                    PetAccessoryOrder order = new PetAccessoryOrder()
                    {
                        items = new List <PetAccessory>()
                        {
                            new PetAccessory()
                            {
                                sn = this.accessories.CurrentButton.Accessory.ID.ToString(), count = 1
                            }
                        },
                        remark = string.Format("CupSn:{0}, ChildSn:{1}", CupBuild.getCupSn(), this.LocalChildInfoAgent.getChildSN())
                    };

                    this.PetAccessoryUtils.BuyPetAccessories(order, (result) =>
                    {
                        this.IsBuying             = false;
                        OrderReceipt orderReceipt = this.JsonUtils.String2Json <OrderReceipt>(result.info);
                        if (orderReceipt != null && !string.IsNullOrEmpty(orderReceipt.status) && orderReceipt.status.ToUpper() == "OK")
                        {
                            this.audioPlayer.Stop();
                            this.qrCodeView.Open(orderReceipt);
                            FlurryUtil.LogEventWithParam("mall_scene_qr", "accessory_name", this.accessories.CurrentButton.Accessory.Name);
                        }
                        else
                        {
                            Debug.LogError("<><PetPageView.Confirm>orderReceipt is null");
                        }
                    },
                                                             (error) =>
                    {
                        this.IsBuying = false;
                        Debug.LogErrorFormat("<><PetPageView.Confirm>BuyPetAccessories, error: {0}", error.info);
                    });
#else
                    this.audioPlayer.Stop();
                    this.qrCodeView.Open(null);
#endif
                }
            }
        }