コード例 #1
0
        private static void PerformVerify(string[] args, VerificationMethod method)
        {
            CheckArgument.ArrayLengthAtLeast(args, 1, "args");

            string phoneNumber = args[0];

            string code = null;

            if (args.Length >= 2)
            {
                code = args[1];
            }

            string language = "en";

            if (args.Length >= 3)
            {
                language = args[2];
            }

            VerifyService  verify         = new VerifyService(GetConfiguration());
            VerifyResponse verifyResponse = null;

            if (method == VerificationMethod.Sms)
            {
                verifyResponse = verify.SendSms(phoneNumber, code, string.Empty, language);
            }
            else if (method == VerificationMethod.Call)
            {
                verifyResponse = verify.InitiateCall(phoneNumber, code, language);
            }
            else
            {
                throw new NotImplementedException("Invalid verification method");
            }

            foreach (TeleSignApiError e in verifyResponse.Errors)
            {
                Console.WriteLine(
                    "ERROR: [{0}] - {1}",
                    e.Code,
                    e.Description);
            }

            while (true)
            {
                Console.Write("Enter the code sent to phone [Just <enter> checks status. 'quit' to exit]: ");
                string enteredCode = Console.ReadLine();

                if (enteredCode.Equals("quit", StringComparison.InvariantCultureIgnoreCase))
                {
                    break;
                }

                Console.WriteLine(string.IsNullOrEmpty(enteredCode) ? "Checking status..." : "Validating code...");

                VerifyResponse statusResponse = verify.ValidateCode(
                    verifyResponse.ReferenceId,
                    enteredCode);

                Console.WriteLine(
                    "Transaction Status: {0} -- {1}\r\nCode State: {2}",
                    statusResponse.Status.Code,
                    statusResponse.Status.Description,
                    statusResponse.VerifyInfo.CodeState);

                if (statusResponse.VerifyInfo.CodeState == CodeState.Valid)
                {
                    Console.WriteLine("Code was valid. Exiting.");
                    break;
                }
            }
        }