Exemplo n.º 1
0
        void StartResquestForDoLogin(string phone, string pwd)
        {
            Dictionary <string, object> paramDict = new Dictionary <string, object>();

            paramDict.Add("mobile", phone);
            paramDict.Add("passwd", pwd);
            HttpUtil.PostWithSign <UserInfoModel>(UrlConst.Login, paramDict)
            .Subscribe(response =>
            {
                PlayerPrefsUtil.UserInfo = response;
                if (response.babyInfoVo.IsNull())
                {
                    // BabyInfoActivity
                    UIMgr.OpenPanel <LoginPanel>(new LoginPanelData());
                }
                else if (response.babyRelation.IsNullOrEmpty())
                {
                    // BabyRelationShipActivity
                    UIMgr.OpenPanel <LoginPanel>(new LoginPanelData());
                }
                else
                {
                    UIMgr.OpenPanel <MainPanel>(new MainPanelData());
                }
            }
                       , e =>
            {
                if (e is HttpException)
                {
                    HttpException httpException = e as HttpException;
                    ToastManager.GetInstance().CreatToast(httpException.Message);
                    UIMgr.OpenPanel <LoginPanel>(new LoginPanelData(), UITransitionType.CLOUD);
                }
            }).AddTo(this);
        }
Exemplo n.º 2
0
    public static IObservable <string> GetWithSign(string url, Dictionary <string, object> param, bool showToast = true)
    {
        if (token.IsNullOrEmpty())
        {
            token = PlayerPrefsUtil.GetToken();
        }

        if (!token.IsNullOrEmpty())
        {
            param.Add("token", token);
        }

        var methodParams = SignUtil.getMethodParamStr(param);
        var sign         = SignUtil.getSign(param);

        url = url + "?" + methodParams + "&sign=" + sign + "&appid=" + AppConst.APPID;
        return(ObservableWWW.Get(url).DoOnError(e =>
        {
            LoadingManager.GetInstance().DismissLoading();
            if (showToast)
            {
                if (e is HttpException)
                {
                }
                else if (e is WWWErrorException)
                {
                    ToastManager.GetInstance().CreatToast("网络连接失败,请检查网络连接");
                }
                else
                {
                    ToastManager.GetInstance().CreatToast(e.Message);
                }
            }
        }));
    }
Exemplo n.º 3
0
    public static IObservable <string> PostWithSign(string url, Dictionary <string, object> param, bool showToast = true)
    {
        StringBuilder strParam  = new StringBuilder();
        var           formParam = new WWWForm();

        if (token.IsNullOrEmpty())
        {
            token = PlayerPrefsUtil.GetToken();
        }

        if (!token.IsNullOrEmpty())
        {
            param.Add("token", token);
        }

        if (param.Count > 0)
        {
            param.ForEach(pair =>
            {
                strParam.Append(pair.Key);
                strParam.Append(":");
                strParam.Append(pair.Value.ToString());
                strParam.Append("&");
                formParam.AddField(pair.Key, pair.Value.ToString());
            });
            string sign = SignUtil.getSign(param);
            formParam.AddField("sign", sign);
            formParam.AddField("appid", AppConst.APPID);
            strParam.Append("sign");
            strParam.Append(":");
            strParam.Append(sign);
            strParam.Append("&");
            strParam.Append("appid");
            strParam.Append(":");
            strParam.Append(AppConst.APPID);
        }
        Log.I("url==" + url);
        Log.I("formParam==" + strParam);
        return(ObservableWWW.Post(url, formParam).DoOnError(e =>
        {
            LoadingManager.GetInstance().DismissLoading();
            if (showToast)
            {
                if (e is HttpException)
                {
                    Log.E("e.Message: " + e.Message);
                }
                else if (e is WWWErrorException)
                {
                    ToastManager.GetInstance().CreatToast("网络连接失败,请检查网络连接");
                }
                else
                {
                    ToastManager.GetInstance().CreatToast(e.Message);
                }
            }
        }));
    }
Exemplo n.º 4
0
    public static IObservable <T> GetWithSign <T>(string url, Dictionary <string, object> param, bool showToast = true)
    {
        if (token.IsNullOrEmpty())
        {
            token = PlayerPrefsUtil.GetToken();
        }

        if (!token.IsNullOrEmpty())
        {
            param.Add("token", token);
        }

        var methodParams = SignUtil.getMethodParamStr(param);
        var sign         = SignUtil.getSign(param);

        url = url + "?" + methodParams + "&sign=" + sign + "&appid=" + AppConst.APPID;
        return(ObservableWWW.Get(url).Select <string, T>(s =>
        {
            Log.I("url==" + url + "\n网络请求返回内容\n" + s);
            BaseEntity <T> deserializeObject = JsonConvert.DeserializeObject <BaseEntity <T> >(s);
            if (deserializeObject.status != 1)
            {
                CommonUtil.error(deserializeObject.errCode, deserializeObject.message, deserializeObject.status);
                throw new HttpException(deserializeObject.errCode, deserializeObject.message, deserializeObject.status);
            }

            return deserializeObject.data;
        }).DoOnError(e =>
        {
            LoadingManager.GetInstance().DismissLoading();
            if (showToast)
            {
                if (e is HttpException)
                {
                    CommonUtil.toast(((HttpException)e).ErrMessage);
                }
                else if (e is WWWErrorException)
                {
                    ToastManager.GetInstance().CreatToast("网络连接失败,请检查网络连接");
                }
                else
                {
                    ToastManager.GetInstance().CreatToast(e.Message);
                }
            }
        }));
    }
Exemplo n.º 5
0
 /**
  * 吐司
  */
 public static void toast(string message)
 {
     // if (Application.platform == RuntimePlatform.Android)
     // {
     //     AndroidForUnity.CallAndroidForToast(message);
     // }
     // else if (Application.platform == RuntimePlatform.IPhonePlayer)
     // {
     //
     //     Dictionary<string, object> paramDic = new Dictionary<string, object>();
     //     Dictionary<string, object> subParam = new Dictionary<string, object>();
     //     subParam.Add("message",message);
     //     paramDic.Add("method",IOSClientUtil.Toast);
     //     paramDic.Add("params",subParam);
     //     IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson());
     // }
     Debug.Log("Unity Toast Msg:" + message);
     ToastManager.GetInstance().CreatToast(message);
 }
Exemplo n.º 6
0
    public static IObservable <string> PostWithSign(string url, Dictionary <string, object> param,
                                                    string fileName = null, string filePath = null, bool showToast = true)
    {
        var formParam = new WWWForm();

        if (token.IsNullOrEmpty())
        {
            token = PlayerPrefsUtil.GetToken();
        }

        if (!token.IsNullOrEmpty())
        {
            param.Add("token", token);
        }

        if (param.Count > 0)
        {
            param.ForEach(pair => { formParam.AddField(pair.Key, pair.Value.ToString()); });
            string sign = SignUtil.getSign(param);
            formParam.AddField("sign", sign);
            formParam.AddField("appid", AppConst.APPID);
        }

        return(ObservableWWW.Post(url, formParam).DoOnError(e =>
        {
            LoadingManager.GetInstance().DismissLoading();
            if (showToast)
            {
                if (e is HttpException)
                {
                }
                else if (e is WWWErrorException)
                {
                    ToastManager.GetInstance().CreatToast("网络连接失败,请检查网络连接");
                }
                else
                {
                    ToastManager.GetInstance().CreatToast(e.Message);
                }
            }
        }));
    }
Exemplo n.º 7
0
    public static IObservable <T> PostWithSign <T>(string url, Dictionary <string, object> param,
                                                   string fileName = null, string filePath = null, bool showToast = true)
    {
        StringBuilder strParam  = new StringBuilder();
        var           formParam = new WWWForm();

        if (token.IsNullOrEmpty())
        {
            token = PlayerPrefsUtil.GetToken();
        }

        if (!token.IsNullOrEmpty())
        {
            param.Add("token", token);
        }

        if (param.Count > 0)
        {
            param.ForEach(pair =>
            {
                strParam.Append(pair.Key);
                strParam.Append(":");
                strParam.Append(pair.Value.ToString());
                strParam.Append("&");
                formParam.AddField(pair.Key, pair.Value.ToString());
            });
            string sign = SignUtil.getSign(param);
            formParam.AddField("sign", sign);
            formParam.AddField("appid", AppConst.APPID);
            strParam.Append("sign");
            strParam.Append(":");
            strParam.Append(sign);
            strParam.Append("&");
            strParam.Append("appid");
            strParam.Append(":");
            strParam.Append(AppConst.APPID);
        }

        if (filePath.IsNotNullAndEmpty())
        {
            formParam.AddBinaryData("file", File.ReadAllBytes(filePath), fileName);
            strParam.Append("&");
            strParam.Append("file");
            strParam.Append(":");
            strParam.Append(File.ReadAllBytes(filePath));
        }

        return(ObservableWWW.Post(url, formParam).Select <string, T>(s =>
        {
            Log.I("url==" + url);
            Log.I("formParam==" + strParam);
            Log.I("返回信息是" + s);
            if (s.IsNullOrEmpty())
            {
                throw new HttpException("104", "网络连接失败", 104);
            }

            BaseEntity <T> deserializeObject = JsonConvert.DeserializeObject <BaseEntity <T> >(s);
            if (deserializeObject.status != 1)
            {
                CommonUtil.error(deserializeObject.errCode, deserializeObject.message, deserializeObject.status);
                throw new HttpException(deserializeObject.errCode, deserializeObject.message, deserializeObject.status);
            }

            return deserializeObject.data;
        }).DoOnError(e =>
        {
            LoadingManager.GetInstance().DismissLoading();
            if (showToast)
            {
                if (e is HttpException)
                {
                    CommonUtil.toast(((HttpException)e).ErrMessage);
                }
                else if (e is WWWErrorException)
                {
                    ToastManager.GetInstance().CreatToast("网络连接失败,请检查网络连接");
                }
                else
                {
                    ToastManager.GetInstance().CreatToast(e.Message);
                }
            }
        }));
    }