Пример #1
0
 /// <summary>
 /// 构造函数,初始化访问环境
 /// </summary>
 /// <param name="consumerKey"></param>
 /// <param name="consumerSecret"></param>
 /// <param name="oAuthToken"></param>
 /// <param name="oAuthTokenSecret"></param>
 /// <param name="authorized_verifier"></param>
 /// <param name="isApi"></param>
 /// <param name="openId"></param>
 public Qzone(string consumerKey, 
     string consumerSecret,
     string oAuthToken, 
     string oAuthTokenSecret, 
     string authorized_verifier,
     bool isApi =false,string openId = "")
 {
     if (string.IsNullOrEmpty(consumerKey) || string.IsNullOrEmpty(consumerSecret) || string.IsNullOrEmpty(oAuthToken)
         || string.IsNullOrEmpty(oAuthTokenSecret))
     {
         throw new ArgumentNullException("参数consumerKey、consumerSecret、oAuthToken、oAuthTokenSecret不能为空");
     }
     if (isApi)
     {
         if (string.IsNullOrEmpty(openId))
         {
             throw new ArgumentNullException("访问Qzone的api要求带获取到的token(access token)、token secret(access token secret)、openid。");
         }
     }
     if (!isApi)
     {
         QzoneContext context = new QzoneContext(consumerKey, consumerSecret);
         var accessToken = context.GetAccessToken(oAuthToken, oAuthTokenSecret, authorized_verifier);
         context.OAuthTokenKey = accessToken.TokenKey;
         context.OAuthTokenSecret = accessToken.TokenSecret;
         Init(accessToken.TokenKey, accessToken.TokenSecret, accessToken.Openid, context);
     }
     else
     {
         QzoneContext context = new QzoneContext(consumerKey, consumerSecret, oAuthToken, oAuthTokenSecret, openId);
         Init(oAuthToken, oAuthTokenSecret, openId, context);
     }
 }
 /// <summary>
 /// 用qq登录,跳转到腾讯提供的登录页面
 /// </summary>
 /// <returns></returns>
 public ActionResult Login()
 {
     //return JavaScript("<script>alert('hello');</script>");
     QzoneContext context = new QzoneContext(appid, appkey);
     string cbUrl = "/qq/callback";
     OAuthToken token = context.GetRequestToken(cbUrl);
     TempData["TokenKey"] = token.TokenKey;
     TempData["TokenSecret"] = token.TokenSecret;
     string authUrl = context.GetAuthorizationUrl(token, cbUrl);
     return Redirect(authUrl);
 }
Пример #3
0
 private void Init(string oAuthToken, string oAuthTokenSecret, string openId, QzoneContext context)
 {
     OAuthTokenKey = oAuthToken;
     OAuthTokenSecret = oAuthTokenSecret;
     OpenID = openId;
     restApi = new RestApi(context);
 }