//授权
        private void Autho()
        {
            if (oauthClient == null || oauthClient.IsAuthorized == false)
            {
                oauthClient = new ClientOAuth();
                oauthClient.IsAuthorized = false;
            }
          
            // 判断是否已经授权或者授权是否过期.
            if (oauthClient.IsAuthorized == false)
            {
                oauthClient.LoginCallback += (isSucces, err, response) =>
                {

                    if (isSucces)
                    {
                        oauthClient.IsAuthorized = true;
                        BT_Cancel.Visibility = Visibility.Visible;
                    }
                    else
                    {

                    }
                };
                oauthClient.BeginOAuth();//异步方法,如果需要在之后执行代码,请加到上面的LoginCallback中
            }
            else
            {
                BT_Cancel.Visibility = Visibility.Visible;
            }
        }
Example #2
0
        public GoodNightPage()
        {
            var oauthClient = new ClientOAuth();

            this.InitializeComponent();
            Initialization();
        }
Example #3
0
        private bool SendSms(ISmsNotificationModel message)
        {
            try
            {
                if (message.Valid)
                {
                    IClient client = new ClientOAuth(message.Config.Token);
                    var     api    = new SMSFactory(client);

                    var builder =
                        api.ActionSend()
                        .SetText(message.Text)
                        .SetTo(message.PhoneNumbers.ToArray());

                    if (message.Date.HasValue)
                    {
                        builder.SetDateSent(message.Date.Value);
                    }

                    builder.Execute();
                }
            }
            catch (System.Exception)
            {
                // log
            }

            return(false);
        }
        private async void weibo_login()
        {
            await Task.Delay(1000);

            var Weibo_oauthClient = new ClientOAuth();

            Weibo_oauthClient.BeginOAuth();
        }
Example #5
0
        private void logout_test_Button_Click(object sender, RoutedEventArgs e)
        {
            var Weibo_oauthClient = new ClientOAuth();

            Weibo_oauthClient.QuitOAuth();
            Frame frame = new Frame();

            frame = Window.Current.Content as Frame;
            frame.Navigate(typeof(LoginPage));
        }
Example #6
0
        private void is_weibo_login()
        {
            var Weibo_oauthClient = new ClientOAuth();

            // 判断是否已经授权或者授权是否过期.
            if (Weibo_oauthClient.IsAuthorized == false)
            {
                Frame frame = Window.Current.Content as Frame;
                frame.Navigate(typeof(LoginPage));
            }
            else
            {
                Frame frame = new Frame();
                frame = Window.Current.Content as Frame;
                frame.Navigate(typeof(GoodNightPage));
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            MyHashTable myAppSettings = new MyHashTable();

            ApplicationData.Current.LocalSettings.Values = myAppSettings;

            SdkData.AppKey      = "2999701648";
            SdkData.AppSecret   = "bb4d9b4617847315b057967acfd75481";
            SdkData.RedirectUri = "https://api.weibo.com/oauth2/default.html";
            MyWeiboViewDelegate myWeibo = new MyWeiboViewDelegate();

            myWeibo.NotifyDelegate = new EventNotifyDelegate(this.weiboVisitFinish);
            weiboView.Delegate     = myWeibo;

            // Perform any additional setup after loading the view, typically from a nib.
            oauthClient = new ClientOAuth();
            // 判断是否已经授权或者授权是否过期.
            if (oauthClient.IsAuthorized == false)
            {
                oauthClient.LoginCallback += (isSucces, err, response) =>
                {
                    if (isSucces)
                    {
                        // TODO: deal the OAuth result.
                        System.Console.WriteLine("Congratulations, Authorized successfully!");
                        System.Console.WriteLine(string.Format("AccesssToken:{0}, ExpriesIn:{1}, Uid:{2}",
                                                               response.AccessToken, response.ExpriesIn, response.Uid));
                    }
                    else
                    {
                        // TODO: handle the err.
                        System.Console.WriteLine(err.errMessage);
                    }
                };
                string       url     = oauthClient.GetAuthorizeUrl();
                NSUrlRequest request = NSUrlRequest.FromUrl(NSUrl.FromString(url));
                weiboView.LoadRequest(request);
//				oauthClient.BeginOAuth();
            }
        }
        public void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs ex)
        {
            var oauthClient = new ClientOAuth();

            oauthClient.LoginCallback += (isSucces, err, response) =>
            {
                if (isSucces)
                {
                    // TODO: deal the OAuth result.
                    Frame frame = new Frame();
                    frame = Window.Current.Content as Frame;
                    frame.Navigate(typeof(GoodNightPage));
                }
                else
                {
                    // TODO: handle the err.
                    Frame frame = new Frame();
                    frame = Window.Current.Content as Frame;
                    frame.Navigate(typeof(LoginPage));
                }
            };
            oauthClient.continueAuth(ex.WebAuthenticationResult);
        }
Example #9
0
        private static string SmsSender2(string messageText, string phoneNumber, string token)
        {
            string errors = string.Empty;

            try
            {
                IClient client = new ClientOAuth(token);
                var     smsApi = new SMSFactory(client);

                // .SetSender(_senderName) //Sender name
                var result =
                    smsApi.ActionSend()
                    .SetText(messageText)
                    .SetTo(phoneNumber)
                    .Execute();

                // System.Console.WriteLine("Send: " + result.Count);

                string[] ids = new string[result.Count];

                for (int i = 0, l = 0; i < result.List.Count; i++)
                {
                    if (!result.List[i].isError())
                    {
                        if (!result.List[i].isFinal())
                        {
                            ids[l] = result.List[i].ID;
                            l++;
                        }
                    }
                }
            }
            catch (SMSApi.Api.ActionException e)
            {
                errors += $"Action error: {e.Message}\n";
            }
            catch (SMSApi.Api.ClientException e)
            {
                /**
                 * Error codes (list available in smsapi docs). Example:
                 * 101  Invalid authorization info
                 * 102  Invalid username or password
                 * 103  Insufficient credits on Your account
                 * 104  No such template
                 * 105  Wrong IP address (for IP filter turned on)
                 * 110	Action not allowed for your account
                 */
                errors += $"Client error: {e.Message}\n";
            }
            catch (SMSApi.Api.HostException e)
            {
                /*
                 * Server errors
                 * SMSApi.Api.HostException.E_JSON_DECODE - problem with parsing data
                 */
                errors += $"Server error: {e.Message}\n";
            }
            catch (SMSApi.Api.ProxyException e)
            {
                // communication problem between client and sever
                errors += $"Proxy error: {e.Message}\n";
            }
            return(errors);
        }
        private void weibo_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(SdkData.AppKey) || string.IsNullOrEmpty(SdkData.AppSecret) ||
                string.IsNullOrEmpty(SdkData.RedirectUri))
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("请在中MainPage.xmal.cs的构造函数中设置自己的appkey、appkeysecret、RedirectUri.");
                });
                return;
            }
            AuthenticationView.OAuth2VerifyCompleted = (e1, e2, e3) => VerifyBack(e1, e2, e3);
            AuthenticationView.OBrowserCancelled     = new EventHandler(cancleEvent);
            //其它通知事件...

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                NavigationService.Navigate(new Uri("/WeiboSdk;component/PageViews/AuthenticationView.xaml"
                                                   , UriKind.Relative));
            });


            ClientOAuth.GetAccessToken("username", "password", (e1, e2, e3) =>
            {
                if (true == e1)
                {
                    Debug.WriteLine("accessToken:" + e3.accesssToken);
                    Debug.WriteLine("refleshToken:" + e3.refleshToken);
                    Debug.WriteLine("expriesIn:" + e3.expriesIn);
                }
                else
                {
                    if (e2.errCode == SdkErrCode.NET_UNUSUAL)
                    {
                        Debug.WriteLine("测试");
                    }
                    else if (e2.errCode == SdkErrCode.SERVER_ERR)
                    {
                        Debug.WriteLine("服务器返回错误,错误码:" + e2.specificCode);
                    }
                }
            });

            ClientOAuth.RefleshAccessToken("服务器获取的reflesh_token", (e1, e2, e3) =>
            {
                if (true == e1)
                {
                    Debug.WriteLine("accessToken:" + e3.accesssToken);
                    Debug.WriteLine("refleshToken:" + e3.refleshToken);
                    Debug.WriteLine("expriesIn:" + e3.expriesIn);
                }
                else
                {
                    if (e2.errCode == SdkErrCode.NET_UNUSUAL)
                    {
                    }
                    else if (e2.errCode == SdkErrCode.SERVER_ERR)
                    {
                        Debug.WriteLine("服务器返回错误,错误码:" + e2.specificCode);
                    }
                }
            });
        }