Exemplo n.º 1
0
        /// <summary>
        /// 获取登录用户自己的详细信息
        /// </summary>
        /// <param name="access_token">临时的Access Token</param>
        /// <param name="open_id">用户openid</param>
        /// <returns>Dictionary</returns>
        public static JsonData get_info(string access_token, string open_id)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("qq");
            string       send_url = "https://graph.qq.com/user/get_info?access_token=" + access_token + "&oauth_consumer_key=" + config.oauth_app_id + "&openid=" + open_id;
            //发送并接受返回值
            string result = Utils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                JsonData jd = JsonMapper.ToObject(result);
                if (jd.Count > 0)
                {
                    return(jd);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 取得临时的Access Token
        /// </summary>
        /// <param name="code">临时Authorization Code,官方提示10分钟过期</param>
        /// <param name="state">防止CSRF攻击,成功授权后回调时会原样带回</param>
        /// <returns>Dictionary</returns>
        public static Dictionary <string, object> get_access_token(string code, string state)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("qq");
            string       send_url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=" + config.oauth_app_id + "&client_secret=" + config.oauth_app_key + "&code=" + code + "&state=" + state + "&redirect_uri=" + Utils.UrlEncode(config.return_uri);
            //发送并接受返回值
            string result = Utils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                string[] parm                   = result.Split('&');
                string   access_token           = parm[0].Split('=')[1]; //取得access_token
                string   expires_in             = parm[1].Split('=')[1]; //Access Token的有效期,单位为秒
                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("access_token", access_token);
                dic.Add("expires_in", expires_in);
                return(dic);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 取得临时的Access Token
        /// </summary>
        /// <param name="code">Authorization Code</param>
        /// <returns>JsonData</returns>
        public static JsonData get_access_token(string code)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("renren");
            string       send_url = "https://graph.renren.com/oauth/token?grant_type=authorization_code&client_id=" + config.oauth_app_id + "&client_secret=" + config.oauth_app_key + "&code=" + code + "&redirect_uri=" + Utils.UrlEncode(config.return_uri);
            //发送并接受返回值
            string result = Utils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                JsonData jd = JsonMapper.ToObject(result);
                if (jd.Count > 0)
                {
                    return(jd);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取登录用户自己的基本资料
        /// </summary>
        /// <param name="access_token">临时的Access Token</param>
        /// <param name="open_id">用户openid</param>
        /// <returns>Dictionary</returns>
        public static Dictionary <string, object> get_user_info(string access_token, string open_id)
        {
            //获得配置信息
            oauth_config config   = oauth_helper.get_config("qq");
            string       send_url = "https://graph.qq.com/user/get_user_info?access_token=" + access_token + "&oauth_consumer_key=" + config.oauth_app_id + "&openid=" + open_id;
            //发送并接受返回值
            string result = Utils.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            //反序列化JSON
            Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result);

            return(dic);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 获取OAuth配置信息
 /// </summary>
 /// <param name="oauth_name"></param>
 public static oauth_config get_config(string oauth_name)
 {
     //读取接口配置信息
     Model.users.user_oauth_app model = new BLL.users.user_oauth_app().GetModel(oauth_name);
     if (model != null)
     {
         //读取站点配置信息
         Model.configs.siteconfig siteConfig = new BLL.configs.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);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 获取OAuth配置信息
 /// </summary>
 /// <param name="oauth_name"></param>
 public static oauth_config get_config(string oauth_name)
 {
     //读取接口配置信息
     Model.users.user_oauth_app model = new BLL.users.user_oauth_app().GetModel(oauth_name);
     if (model != null)
     {
         //读取站点配置信息
         Model.configs.siteconfig siteConfig = new BLL.configs.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;
 }
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("feixin");
            string       send_url = "https://i.feixin.10086.cn/oauth2/access_token?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.HttpGet(send_url);

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result);
                return(dic);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取登录用户自己的详细信息
        /// </summary>
        /// <param name="access_token">临时的Access Token</param>
        /// <param name="open_id">用户openid</param>
        /// <returns>Dictionary</returns>
        public static JsonData get_info(string access_token, string fields)
        {
            //获得配置信息
            oauth_config  config   = oauth_helper.get_config("renren");
            string        send_url = "http://api.renren.com/restserver.do";
            StringBuilder param    = new StringBuilder();

            param.Append("method=users.getInfo&");
            param.Append("access_token=" + access_token + "&");
            param.Append("fields=" + fields + "&");
            param.Append("format=json&");
            param.Append("v=1.0&");
            param.Append("sig=" + MD5Encrpt("access_token=" + access_token + "fields=" + fields + "format=jsonmethod=users.getInfov=1.0" + config.oauth_app_key));
            //发送并接受返回值
            string result = Utils.HttpPost(send_url, param.ToString());

            if (result.Contains("error"))
            {
                return(null);
            }
            try
            {
                //int str_start = result.IndexOf('[') + 1;
                //int str_last = result.LastIndexOf(']') - 1;
                //result = result.Substring(str_start, (str_last - str_start));
                JsonData jd = JsonMapper.ToObject(result);
                if (jd.Count > 0)
                {
                    return(jd);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }