/// <summary> /// 获取OPENID /// </summary> /// <param name="appid"></param> /// <param name="secret"></param> /// <param name="code_s"></param> /// <returns></returns> public static string GetOpenid(string appid, string secret, string code_s) { string url_s = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + code_s + "&grant_type=authorization_code"; string user_grxx = new YJYSoft.YL.Common.MyHttp().GetUrl(url_s); WeChatOpenIdInfo n_class_openId = Newtonsoft.Json.JsonConvert.DeserializeObject <WeChatOpenIdInfo>(user_grxx); if (n_class_openId.errcode == null) { return(n_class_openId.openid); } return(""); }
public static QQUserInfo GetUserInfo(string accessToken, string openid, string appid) { string url_s_openid = string.Format("https://graph.qq.com/user/get_user_info?access_token={0}&oauth_consumer_key={1}&openid={2}", accessToken, appid, openid); string str = new YJYSoft.YL.Common.MyHttp().GetUrl(url_s_openid); QQUserInfo n_qq_user_grxx = Newtonsoft.Json.JsonConvert.DeserializeObject <QQUserInfo>(str); if (n_qq_user_grxx != null) { if (n_qq_user_grxx.ret == 0) { return(n_qq_user_grxx); } else { return(null); } } else { return(null); } }
public static WeChatUserInfo GetWXUserInfo2(string accessToken, string openid) { string url_s_openid = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + accessToken + "&openid=" + openid + "&lang=zh_CN"; string str = new YJYSoft.YL.Common.MyHttp().GetUrl(url_s_openid); WeChatUserInfo n_wx_user_grxx = Newtonsoft.Json.JsonConvert.DeserializeObject <WeChatUserInfo>(str); if (n_wx_user_grxx != null) { if (n_wx_user_grxx.errcode == null) { return(n_wx_user_grxx); } else { return(null); } } else { return(null); } }
/// <summary> /// 获取token /// </summary> /// <param name="appid"></param> /// <param name="appsecret"></param> /// <returns></returns> public static string GetAccessToken(string appid, string appsecret) { ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + appsecret; string data = new YJYSoft.YL.Common.MyHttp().GetUrl(url); if (!string.IsNullOrWhiteSpace(data)) { dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(data); if (json.access_token != null && json.access_token != "") { return(json.access_token); } else { return(""); } } else { return(""); } }
public static bool CheckUserInfo(string accessToken, string openid, string appid) { string str = "https://graph.qq.com/oauth2.0/me?access_token=" + accessToken; string rs = new YJYSoft.YL.Common.MyHttp().GetUrl(str); rs = rs.Replace("callback(", ""); rs = rs.Replace(")", ""); rs = rs.Replace(";", ""); QQOpenIdInfo me = Newtonsoft.Json.JsonConvert.DeserializeObject <QQOpenIdInfo>(rs); if (me != null) { if (me.error == null) { if (me.openid == openid && me.client_id == appid) { return(true); } } } return(false); }