/// <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); } }
/// <summary> /// 获取登录用户自己的详细信息 /// </summary> /// <param name="access_token">临时的Access Token</param> /// <param name="open_id">用户openid</param> /// <returns>Dictionary</returns> public static Dictionary <string, object> 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 { Dictionary <string, object> dic = JsonHelper.DataRowFromJSON(result); if (dic.Count > 0) { return(dic); } } catch { return(null); } return(null); }
/// <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); }
/// <summary> /// 获取OAuth配置信息 /// </summary> public static oauth_config get_config(int site_oauth_id) { //读取接口配置信息 Model.site_oauth model = new BLL.site_oauth().GetModel(site_oauth_id); if (model != null) { Model.siteconfig sysConfig = new BLL.siteconfig().loadConfig(); //系统配置 Model.sites siteModel = new BLL.sites().GetModel(model.site_id); //站点配置 Model.oauth_app appModel = new BLL.oauth_app().GetModel(model.oauth_id); //OAuth应用 //赋值 oauth_config config = new oauth_config(); config.oauth_id = model.id; config.oauth_name = appModel.api_path.Trim(); config.oauth_app_id = model.app_id.Trim(); config.oauth_app_key = model.app_key.Trim(); config.site_path = siteModel.build_path; if (!string.IsNullOrEmpty(siteModel.domain.Trim()) && siteModel.is_default == 0) //如果有自定义域名且不是默认站点 { config.return_uri = "http://" + siteModel.domain + "/api/oauth/return_url.aspx"; } else if (siteModel.is_default == 0) //不是默认站点也没有绑定域名 { config.return_uri = "http://" + HttpContext.Current.Request.Url.Authority.ToLower() + sysConfig.webpath + siteModel.build_path.ToLower() + "/api/oauth/return_url.aspx"; } else //否则使用当前域名 { config.return_uri = "http://" + HttpContext.Current.Request.Url.Authority.ToLower() + sysConfig.webpath + "api/oauth/return_url.aspx"; } return(config); } return(null); }
/// <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("kaixin"); string send_url = "https://api.kaixin001.com/oauth2/access_token?grant_type=authorization_code&code=" + code + "&client_id=" + config.oauth_app_id + "&client_secret=" + config.oauth_app_key + "&state=" + state + "&redirect_uri=" + Utils.UrlEncode(config.return_uri); //发送并接受返回值 string result = Utils.HttpGet(send_url); if (result.Contains("error")) { return(null); } try { Dictionary <string, object> dic = JsonHelper.DataRowFromJSON(result); if (dic.Count > 0) { return(dic); } } catch { return(null); } return(null); }
/// <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); }
/// <summary> /// 获取登录用户自己的详细信息 /// </summary> /// <param name="access_token">临时的Access Token</param> /// <param name="open_id">用户openid</param> /// <returns>Dictionary</returns> public static Dictionary <string, object> 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 { Dictionary <string, object> dic = JsonHelper.DataRowFromJSON(result); if (dic.Count > 0) { return(dic); } } catch { return(null); } return(null); }
/// <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); }
/// <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 = "http://" + HttpContext.Current.Request.Url.Authority.ToLower() + siteConfig.webpath + "api/oauth/" + model.api_path + "/return_url.aspx"; return config; } return null; }
/// <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); }
/// <summary> /// 获取OAuth配置信息 /// </summary> /// <param name="oauth_name"></param> public static oauth_config get_config(string oauth_name) { //读取接口配置信息 Model.app_oauth model = new BLL.app_oauth().GetModel(oauth_name); if (model != null) { //读取站点配置信息 Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(DTKeys.FILE_SITE_XML_CONFING); //赋值 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 = Utils.DelLastChar(siteConfig.weburl, "/") + siteConfig.webpath + "api/oauth/" + model.api_path + "/return_url.aspx"; return config; } return null; }
/// <summary> /// 获取OAuth配置信息 /// </summary> /// <param name="oauth_name"></param> public static oauth_config get_config(string oauth_name) { //读取接口配置信息 Model.app_oauth model = new BLL.app_oauth().GetModel(oauth_name); if (model != null) { //读取站点配置信息 Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(DTKeys.FILE_SITE_XML_CONFING); //赋值 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 = Utils.DelLastChar(siteConfig.weburl, "/") + siteConfig.webpath + "api/oauth/" + model.api_path + "/return_url.aspx"; return(config); } return(null); }
/// <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); } }
/// <summary> /// 取得临时的Access Token /// </summary> /// <param name="code">临时Authorization Code,官方提示2小时过期</param> /// <returns>Dictionary</returns> public static Dictionary <string, object> get_access_token(string code) { //获得配置信息 oauth_config config = oauth_helper.get_config("weixin"); string send_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + config.oauth_app_id + "&secret=" + config.oauth_app_key + "&code=" + code + "&grant_type=authorization_code"; //发送并接受返回值 string result = Utils.HttpGet(send_url); if (result.Contains("errcode")) { return(null); } try { Dictionary <string, object> dic = JsonHelper.DataRowFromJSON(result); return(dic); } catch { return(null); } }
/// <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) { //获得配置信息 oauth_config config = oauth_helper.get_config("sina"); string send_url = "https://api.weibo.com/oauth2/access_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 = JsonHelper.DataRowFromJSON(result); return(dic); } catch { return(null); } }
/// <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); }