/// <summary> /// 获取用户身份的标识 /// </summary> /// <returns>用户身份的标识</returns> public OpenId GetOpenId() { if (IsToken) { string json = Config.Client.RequestForm(@"https://graph.qq.com/oauth2.0/me?access_token=" + access_token); if (json != null) { bool isError = false, isJson = false; OpenId openId = new OpenId(); try { if (AutoCSer.Json.Parser.Parse(formatJson(json), ref openId)) { isJson = true; } } catch (Exception error) { isError = true; AutoCSer.Log.Pub.Log.add(Log.LogType.Error, error, json); } if (isJson && openId.openid != null) { return(openId); } if (!isError) { AutoCSer.Log.Pub.Log.add(Log.LogType.Debug | Log.LogType.Info, json); } } } return(default(OpenId)); }
/// <summary> /// API调用 /// </summary> /// <param name="config">应用配置</param> /// <param name="token">访问令牌</param> /// <param name="openId">用户身份的标识</param> internal API(Config config, ref Token token, ref OpenId openId) { this.config = config; this.token = token; this.openId = openId; query = "access_token=" + token.access_token + "&oauth_consumer_key=" + config.client_id + "&openid=" + openId.openid; }
/// <summary> /// 获取用户身份的标识 /// </summary> /// <returns>用户身份的标识</returns> public OpenId GetOpenId() { if (IsToken) { string json = Config.Client.RequestForm(@"https://graph.qq.com/oauth2.0/me?access_token=" + access_token); if (json != null) { bool isError = false, isJson = false; OpenId openId = new OpenId(); try { if (AutoCSer.JsonDeSerializer.DeSerialize(formatJson(json), ref openId)) { isJson = true; } } catch (Exception error) { isError = true; AutoCSer.LogHelper.Exception(error, json, LogLevel.Exception | LogLevel.AutoCSer); } if (isJson && openId.openid != null) { return(openId); } if (!isError) { AutoCSer.LogHelper.Debug(json, LogLevel.Debug | LogLevel.Info | LogLevel.AutoCSer); } } } return(default(OpenId)); }
/// <summary> /// 获取api调用 /// </summary> /// <param name="tokenOpenId">访问令牌+用户身份的标识</param> /// <returns>API调用,失败返回null</returns> public API GetApi(ref TokenOpenId tokenOpenId) { if (string.IsNullOrEmpty(tokenOpenId.Token) || string.IsNullOrEmpty(tokenOpenId.OpenId)) { return(null); } Token token = new Token { access_token = tokenOpenId.Token, expires_in = -1 }; OpenId openId = new OpenId { openid = tokenOpenId.OpenId, client_id = client_id }; return(new API(this, ref token, ref openId)); }
/// <summary> /// 获取api调用 /// </summary> /// <param name="code">authorization_code</param> /// <returns>API调用,失败返回null</returns> public API GetApi(string code) { if (string.IsNullOrEmpty(site)) { AutoCSer.Log.Pub.Log.add(Log.LogType.Error, "网站名称不能为空"); } else { Token token = getToken(code); OpenId openId = token.GetOpenId(); if (openId.openid != null) { return(new API(this, ref token, ref openId)); } } return(null); }
/// <summary> /// 获取api调用 /// </summary> /// <param name="code">authorization_code</param> /// <returns>API调用,失败返回null</returns> public API GetApi(string code) { if (string.IsNullOrEmpty(site)) { AutoCSer.LogHelper.Error("网站名称不能为空", LogLevel.Error | LogLevel.AutoCSer); } else { Token token = getToken(code); OpenId openId = token.GetOpenId(); if (openId.openid != null) { return(new API(this, ref token, ref openId)); } } return(null); }