用户身份的标识
Esempio n. 1
0
 /// <summary>
 /// 获取用户身份的标识
 /// </summary>
 /// <returns>用户身份的标识</returns>
 public openId GetOpenId()
 {
     if (IsToken)
     {
         string json = config.Request.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 (fastCSharp.emit.jsonParser.Parse(formatJson(json), ref openId))
                 {
                     isJson = true;
                 }
             }
             catch (Exception error)
             {
                 isError = true;
                 log.Error.Add(error, json, false);
             }
             if (isJson && openId.openid != null)
             {
                 return(openId);
             }
             if (!isError)
             {
                 log.Default.Add(json, new System.Diagnostics.StackFrame(), false);
             }
         }
     }
     return(default(openId));
 }
Esempio n. 2
0
 /// <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;
 }
Esempio n. 3
0
        /// <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));
        }
Esempio n. 4
0
 /// <summary>
 /// 获取api调用
 /// </summary>
 /// <param name="code">authorization_code</param>
 /// <returns>API调用,失败返回null</returns>
 public api GetApi(string code)
 {
     if (string.IsNullOrEmpty(site))
     {
         log.Error.Add("网站名称不能为空", new System.Diagnostics.StackFrame(), true);
     }
     else
     {
         token  token  = getToken(code);
         openId openId = token.GetOpenId();
         if (openId.openid != null)
         {
             return(new api(this, ref token, ref openId));
         }
     }
     return(null);
 }