Пример #1
0
        public async Task <T> InvokeAction <T>(string actionKey, params object[] p)
        {
            Setting    actionModel = SettingModel.Action[actionKey];
            UrlEncoder urlEncoder  = new UrlEncoder();

            this.OnConfigUrlEncoder(actionKey, urlEncoder, p);
            this.ConfigUrlParams(urlEncoder);
            string url = this.GetActionUrl(actionKey);

            url = url.AppendRequestString(urlEncoder.ToString());
            IHttpParams httpParams = CreateHttpParams(url, HttpMethod.Get);
            T           o          = await this.Get <T>(httpParams);

            return(o);
        }
Пример #2
0
        public async Task <Account> LoginWithToken(string baseUrl)
        {
            Uri    uri      = new Uri(baseUrl);
            var    names    = HttpUtility.ParseQueryString(uri.Query);
            string key      = "code";
            bool   hasToken = names.ContainsKey(key);

            if (hasToken)
            {
                UrlEncoder urlEncoder  = new UrlEncoder();
                string     code        = "code";
                Setting    access_toke = SettingModel.Action[SettingModel.act_access_token];
                string     url         = access_toke.Extras[0].Value + access_toke.Value;

                var p = CreateHttpParams(url, HttpMethod.Post, false);
                urlEncoder.Add(code, names[key]);
                urlEncoder.Add(SettingModel.act_client_id, App.ClientID);
                urlEncoder.Add("client_secret", SettingModel.Action[SettingModel.act_app_secret].Value);
                urlEncoder.Add("grant_type", "authorization_code");
                urlEncoder.Add("redirect_uri", SettingModel.Action[SettingModel.act_callback_url].Value);
                this.ConfigUrlParams(urlEncoder);

                string str = urlEncoder.ToString();
                p.Content     = Encoding.UTF8.GetBytes(str);
                p.ContentType = "application/x-www-form-urlencoded";
                StringContent content = new StringContent(str, Encoding.UTF8, "application/x-www-form-urlencoded");
                p.HttpContent = content;

                Token token = await this.Get <Token>(p);

                Account account = new Account();
                account.Token     = token;
                account.TokenCode = code;
                return(account);
            }
            return(null);
        }