コード例 #1
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);
                }
            }
        }));
    }
コード例 #2
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);
                }
            }
        }));
    }