Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            ulong  kdtId  = 0;
            Silent silent = new Silent("client_id", "client_appsecret", kdtId);

            OauthToken.TokenData silenToken = silent.GetToken();
            string token = silenToken.Token;

            //构建请求API
            GeneralApi generalApi = new GeneralApi();
            //设置请求参数
            GeneralApiParams apiParams = new GeneralApiParams();

            apiParams.AddParam("page_no", "1");
            apiParams.AddParam("page_size", "100");
            generalApi.SetAPIParams(apiParams);
            //设置API名称
            generalApi.SetName("youzan.ump.coupon.search");
            //设置API版本号
            generalApi.SetVersion("3.0.0");
            //指定鉴权类型
            generalApi.SetOAuthType(OAuthEnum.TOKEN);
            IYouZanClient defaultYZClient = new DefaultYZClient();
            //请求接口
            string result = defaultYZClient.Invoke(generalApi, new Token(token), null, null);

            Console.WriteLine("request result *******************" + result);
        }
Ejemplo n.º 2
0
        private void GetAccessToken(bool refresh = false)
        {
            Silent silent = new Silent(this.ClientId, this.ClientSecret, this.GrantId);

            if (refresh)
            {
                if (YouZanConfig.SaveAccessTokenToDB)
                {
                    oAuthToken = silent.GetNewTokenData(false);
                }
                else
                {
                    oAuthToken = silent.GetToken(refresh);
                }
            }
            else
            {
                oAuthToken = silent.GetToken();
            }
        }
Ejemplo n.º 3
0
        public ApiHelper(string clientId, string clientSecret, string grantId)
        {
            this.ClientId     = clientId;
            this.ClientSecret = clientSecret;
            this.GrantId      = grantId;

            _YouZanClient = new DefaultYZClient();

            Silent silent = new Silent(this.ClientId, this.ClientSecret, this.GrantId);

            oAuthToken = silent.GetToken();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //AuthorizationCode authorization = new AuthorizationCode("bifrost-console", "bifrost-console")
            //{
            //    Code = "ad43719a9b612347af08ac8b5e43acb8"
            //};
            //OauthToken.TokenData  tokenData=  authorization.GetToken();
            //string token = tokenData.Token;
            //GeneralApi generalApi = new GeneralApi();
            //GeneralApiParams apiParams = new GeneralApiParams();
            //generalApi.SetName("youzan.trade.get");
            //generalApi.SetVersion("4.0.0");
            //generalApi.SetOAuthType(common.constant.OAuthEnum.TOKEN);
            //apiParams.AddParam("tid", "E20190521143436044000035");
            //generalApi.SetAPIParams(apiParams);

            //IYouZanClient defaultYZClient = new DefaultYZClient();

            //string result  =  defaultYZClient.Invoke(generalApi,new Token("32dcf5274f846e41270a2e9fcd4bdd8a"),null,null);


            //Console.WriteLine("request result *******************"+result);


            //Console.WriteLine("Hello World!");
            //Console.WriteLine("获取Token"+token);
            //string content = "{\n    \"client_id\": \"bifrost-console\",\n    \"client_secret\": \"bifrost-console\",\n    \"authorize_type\": \"authorization_code\",\n    \"code\": \"ad43719a9b612347af08ac8b5e43acb8\"\n}";
            //var client = new RestClient("http://open.youzanyun.com");
            //var request = new RestRequest("/auth/token",Method.POST);
            //List<Parameter> parameter = request.Parameters;
            //string jsonStr = JsonConvert.SerializeObject(parameter);
            //request.AddParameter("application/json", content, ParameterType.RequestBody);
            //IRestResponse response = client.Execute(request);
            //var conterent = response.Content;
            //Console.WriteLine("request result *******************"+ conterent);

            //RefreshToken refresh = new RefreshToken("db9fe36d892719e921", "be58f76bbd80ee4af32c4f4655d20e9e")
            //{
            //    FreshToken = ""
            //};
            //OauthToken.TokenData tokenData = refresh.GetToken();

            Silent silent = new Silent("bifrost-console", "bifrost-console", 2003777768);

            OauthToken.TokenData silenToken = silent.GetToken();
            string token = silenToken.Token;

            Console.WriteLine("request result *******************" + token);
        }