/// <summary> /// 登入 /// </summary> /// <param name="user"></param> /// <param name="password"></param> /// <returns></returns> private bool login(string user, string password) { if (line != null) { line.Logout(); } if (timer != null) { timer.Dispose(); } line = new LineClient(); line.OnLogin += new LineClient.LoggedInEvent((Result loginResult) => { //Everything worked if (loginResult == Result.OK) { msg = "Authed successfully!"; logger.Trace(msg); //Console.WriteLine(msg); List <Common.Contact> contacts = line.GetContacts(line.GetContactIDs()); foreach (Common.Contact ct in contacts.FindAll(x => x.Name.ToLower().Contains("wii"))) { line.SendMessage(ct.ID, "我登入了系統"); } } //Phone verification needed else if (loginResult == Result.REQUIRES_PIN_VERIFICATION) { //The user then is required to enter the pin (retrieved from calling string pin = line.Pin; //) msg = "Verify your account on your mobile device using PIN: " + pin + ". It times out after about 3 minutes."; logger.Trace(msg); //Then call this function, then enter the pin on the mobile device. line.VerifyPin(); //WARNING: This function will hang until the pin verifies. } else { msg = "Did not auth successfully. Paused."; logger.Trace(msg); } }); line.OnPinVerified += new LineClient.PinVerifiedEvent((Result pinVerifiedResult, string verifierToken) => { //The pin was verified, or it had timed out??? if (pinVerifiedResult == Result.OK) { //Success. Log in using this. After logging in this way, if there's a certificate, you should //save that somewhere and use it to log in again, because apparently it's nice not to have to //verify your pin every single time. I'll implement logging in and using a cert later though. line.Login(user, password, verifierToken); // :P } }); line.OnReceiveMessage += (o, eventArgs) => { logger.Trace(eventArgs.Message.Text); line.SendMessage(eventArgs.Message.From, @"我收到您的訊息了, 稍候給您回覆" + Environment.NewLine + @"謝謝"); }; line.OnNotifiedReceivedCall += (o, eventArgs) => { logger.Trace("[LineSharp] Got a call from " + line.GetContact(eventArgs.Operation.Param1).Name); line.SendMessage(eventArgs.Operation.Param1, @"很抱歉, 我無法接聽電話" + Environment.NewLine + @"請留言"); }; //line.Login("*****@*****.**", "chungyih", "qg2tNEsgGGgfTyiuL2IjNxjTAJpW7R0d"); line.Login(user, password); timer = new Timer(); timer.Elapsed += timer_Elapsed; timer.Interval = 100; timer.Start(); return(true); }