Beispiel #1
0
 /// <summary>
 /// 判断Token是否需要刷新
 /// </summary>
 public static void JudgeToken(SocialDataInfo social)
 {
     if (string.IsNullOrEmpty(social.RefreshToken))
     {
         social.IsBinded = false;
         return;
     }
     if (DateTime.Now.Ticks >= social.Expire)
     {
         var renren = new RenrenApiClient();
         renren.RefreshToken(social.RefreshToken, responseData =>
         {
             try
             {
                 var jsonObj   = JObject.Parse(responseData);
                 var new_token = jsonObj["access_token"].ToString();
                 if (social.AcessToken == new_token)
                 {
                     return;
                 }
                 social.AcessToken   = new_token;
                 social.Expire       = DateTime.Now.AddSeconds(Convert.ToInt32(jsonObj["expires_in"].ToString())).Ticks;
                 social.RefreshToken = jsonObj["refresh_token"].ToString();
             }
             catch
             {
                 social.IsBinded = false;
             }
             SocialViewModel.Instance.DataContext.SubmitChanges();
         });
     }
 }
Beispiel #2
0
        /// <summary>
        /// 人人网发布
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="channelUrl"></param>
        /// <param name="message"></param>
        protected override void SocialSharePublish(string channelName,
                                                   string channelUrl, string message, SocialBase.SocialShareHandler callBack)
        {
            JudgeToken(SocialViewModel.Instance.DataInfos[SocialType.RENREN]);
            var renren = new RenrenApiClient();

            try
            {
                renren.CallPublishShare(channelName, channelUrl, message, responseData =>
                {
                    var responseMsg = string.Empty;
                    try
                    {
                        JObject.Parse(responseData);
                        callBack(true, responseData);
                    }
                    catch
                    {
                        callBack(false, responseData);
                    }
                });
            }
            catch (Exception ex)
            {
                callBack(false, ex.Message);
            }
        }
        /// <summary>
        /// 页面正在导航,用于获取页面跳转间的参数决定下一步动作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void xWebBrowser_Navigating(object sender, Microsoft.Phone.Controls.NavigatingEventArgs e)
        {
            var code = HttpUtils.GetQuerystring(e.Uri, "code");

            if (!string.IsNullOrEmpty(code))
            {
                var renren = new RenrenApiClient();
                renren.AccessToken(code, responseData => {
                    if (AcessTokenCompletedEvent != null)
                    {
                        AcessTokenCompletedEvent(this, new RenrenEventArgs(responseData));
                    }
                });
            }
            var error = HttpUtils.GetQuerystring(e.Uri, "error");

            if (error == "login_denied")
            {
                if (OAuthDeniedEvent != null)
                {
                    OAuthDeniedEvent(this, new RenrenEventArgs());
                }
            }
        }