Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            oauth_config config = oauth_helper.get_config("taobao");
            string       appkey = config.oauth_app_id; // "test";

            string secret = config.oauth_app_key;      // "test";

            string session = config.session;           // "test";

            string appurl = config.oauth_app_url;

            IDictionary <string, string> param = new Dictionary <string, string>();

            // param.Add("content", "文本信息");

            // param.Add("nick", "sandbox_c_1");

            //  appurl = "http://gw.api.tbsandbox.com/router/rest";

            //Util.Post 集成了 系统参数 和 计算 sign的方法
            string   resurtJson = Util.Post(appurl, appkey, secret, "taobao.top.ipout.get", session, param, "json");
            JsonData jd         = JsonMapper.ToObject(resurtJson);

            string str = string.Format("返回结果:" + jd["top_ipout_get_response"]["ip_list"].ToString());

            txtJson.Text = str;
        }
Exemplo n.º 2
0
        private void btnkeyword_Click(object sender, EventArgs e)
        {
            oauth_config config = oauth_helper.get_config("taobao");
            string       appkey = config.oauth_app_id; // "test";

            string secret = config.oauth_app_key;      // "test";

            string session = config.session;           // "test";

            string appurl = config.oauth_app_url;

            IDictionary <string, string> param = new Dictionary <string, string>();

            param.Add("content", "文本信息");

            // param.Add("nick", "sandbox_c_1");

            //  appurl = "http://gw.api.tbsandbox.com/router/rest";

            //Util.Post 集成了 系统参数 和 计算 sign的方法

            string str = string.Format("返回结果:" + Util.Post(appurl, appkey, secret, "taobao.kfc.keyword.search", session, param, "json"));

            txtJson.Text = str;
        }
Exemplo n.º 3
0
        private void btnlijing_Click(object sender, EventArgs e)
        {
            oauth_config config = oauth_helper.get_config("taobao");
            string       appkey = config.oauth_app_id; // "test";

            string secret = config.oauth_app_key;      // "test";

            string session = config.session;           // "test";

            string appurl = config.oauth_app_url;

            IDictionary <string, string> param = new Dictionary <string, string>();

            //param.Add("fields", "user_id,nick,type");

            // param.Add("nick", "sandbox_c_1");

            //  appurl = "http://gw.api.tbsandbox.com/router/rest";

            //Util.Post 集成了 系统参数 和 计算 sign的方法

            string str = string.Format("返回结果:" + Util.Post(appurl, appkey, secret, "qimen.taobao.lijing.test.read", session, param, "json"));

            txtJson.Text = str;
        }
Exemplo n.º 4
0
        private void btnOAuth_Click(object sender, EventArgs e)
        {
            try
            {
                oauth_config config = oauth_helper.get_config("taobao");

                string strUrl       = "";
                string client_id    = config.oauth_app_id; //appkey;          //appkey
                string redirect_uri = config.return_uri;   //callbackUrl; //"http://127.0.0.1:1608/AuthorityService/client/GetCallbackCode";//?code='1212341dsf'&state='1'
                //权限授权
                strUrl = string.Format(@"https://oauth.taobao.com/authorize?response_type=code&client_id={0}&redirect_uri={1}&view=1", client_id, redirect_uri);
                //打开浏览器
                System.Diagnostics.Process.Start(strUrl);
                labTest.Text = "正在授权";

                //回掉事件
                btnOAuth.Text = "确认已平台验证";
                config        = oauth_helper.get_config("taobao");
                if (config.code != "0" && config.code != "")
                {
                    Dictionary <string, object> obj = taobao_helper.get_access_token(config.code);

                    #region 方式1
                    //WebUtils webUtils = new WebUtils();
                    //IDictionary<string, string> pout = new Dictionary<string, string>();
                    //pout.Add("grant_type", "authorization_code");
                    //pout.Add("client_id", appkey);
                    //pout.Add("client_secret", secret);
                    //pout.Add("code", code);
                    //pout.Add("redirect_uri", callbackUrl);
                    //string output = webUtils.DoPost("https://oauth.taobao.com/token", pout);
                    //Console.Write(output);

                    //if (!string.IsNullOrEmpty(output.ToString()))
                    //{
                    //    JavaScriptSerializer Serializers = new JavaScriptSerializer();
                    //    Root objroot = Serializers.Deserialize<Root>(output.ToString());
                    //    txtjson.Text = objroot.refresh_token;

                    //    string xmlPath = "./Configxml/configtaobao.xml";
                    //    XmlDocument doc = new XmlDocument();
                    //    doc.Load(xmlPath);
                    //    XmlNode xn = doc.SelectSingleNode("//session");
                    //    xn.InnerText = objroot.refresh_token;
                    //    sessionKey = objroot.refresh_token;
                    //    doc.Save(xmlPath);
                    //}
                    #endregion
                }
                else
                {
                    //   MessageBox.Show("请确认在平台验证");
                }
            }
            catch (Exception ex)
            {
                WriteExceptionLog(ex);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取OAuth配置信息
        /// </summary>
        /// <param name="oauth_name"></param>
        public static oauth_config get_config(string oauth_name)
        {
            ////读取接口配置信息
            //Model.user_oauth_app model = new BLL.user_oauth_app().GetModel(oauth_name);
            //if (model != null)
            //{
            //    //读取站点配置信息
            //    Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig();
            //    //赋值
            //    oauth_config config = new oauth_config();
            //    config.oauth_name = model.api_path.Trim();
            //    config.oauth_app_id = model.app_id.Trim();
            //    config.oauth_app_key = model.app_key.Trim();
            //    config.return_uri = HttpContext.Current.Request.Url.Authority.ToLower() + siteConfig.webpath + "api/oauth/" + model.api_path + "/return_url.aspx";
            //    return config;
            //}
            //return null;

            //配置文件
            if (oauth_name == "taobao")
            {
                string fullPath = Utils.GetMapPath("./xmlconfig/configtaobao.xml");

                //   file:///E:/WFC-Test/WPF-Test/WPF-Test/Shell/TaobaoTest/bin/Debug/xmlconfig/configtaobao.xml
                XmlDocument doc = new XmlDocument();
                doc.Load(fullPath);
                XmlNode _appUrl     = doc.SelectSingleNode(@"Root/appUrl");
                XmlNode _appKey     = doc.SelectSingleNode(@"Root/appKey");
                XmlNode _appSecret  = doc.SelectSingleNode(@"Root/appSecret");
                XmlNode _return_url = doc.SelectSingleNode(@"Root/return_url");

                XmlNode _appcode    = doc.SelectSingleNode(@"Root/code");
                XmlNode _appsession = doc.SelectSingleNode(@"Root/session");


                //赋值
                oauth_config config = new oauth_config();
                config.oauth_name    = oauth_name;
                config.oauth_app_id  = _appKey.InnerText;
                config.oauth_app_key = _appSecret.InnerText;
                config.oauth_app_url = _appUrl.InnerText;
                config.return_uri    = _return_url.InnerText;
                config.code          = _appcode.InnerText;
                config.session       = _appsession.InnerText;
                return(config);
            }
            return(null);
        }
Exemplo n.º 6
0
        // 服务器端输出信息
        private void SeverPrint(string info)
        {
            Console.WriteLine(info);

            if (labTest.IsDisposed)
            {
                server.print = null;
            }
            else
            {
                if (labTest.InvokeRequired)
                {
                    SocketsServer.Print F = new SocketsServer.Print(SeverPrint);
                    this.Invoke(F, new object[] { info });
                }
                else
                {
                    if (info != "")
                    {
                        labTest.Text  = info;
                        btnOAuth.Text = "授权成功";
                        txtJson.Text  = "";
                        oauth_config config = oauth_helper.get_config("taobao");

                        if (config == null)
                        {
                            return;
                        }
                        foreach (System.Reflection.PropertyInfo p in config.GetType().GetProperties())
                        {
                            txtJson.Text += string.Format("Name:{0} Value:{1}", p.Name, p.GetValue(config, null)) + "\r\n";
                        }
                        //labTest.SelectionColor = Color.Green;
                        //labTest.AppendText(info);
                        //labTest.AppendText(Environment.NewLine);
                        //labTest.ScrollToCaret();
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 取得Access Token
        /// </summary>
        /// <param name="code">临时Authorization Code</param>
        /// <returns>Dictionary</returns>
        public static Dictionary <string, object> get_access_token(string code)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("taobao");
            string       send_url = "https://oauth.taobao.com/token";
            string       param    = "grant_type=authorization_code&code=" + code + "&client_id=" + config.oauth_app_id + "&client_secret=" + config.oauth_app_key + "&redirect_uri=" + Utils.UrlEncode(config.return_uri);
            //发送并接受返回值
            string result = Utils.HttpPost(send_url, param);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result);
                return(dic);
            }
            catch
            {
                return(null);
            }
        }