首页 文章

如何使用TWILIO ASP.Net Web API发送和验证OTP

提问于
浏览
2

我可以使用twilio从我们的应用程序向用户发送SMS消息 .

以下是通过Twilio How to send sms using C# and twilio API向用户发送消息的链接

现在我想生成OTP(一次性密码) . 通过twilio将OTP发送给用户 . 用户必须回复OTP到twilio号码是否有可能在twilio?

如果是,如何将OTP SMS消息回复给Twilio号码 .

有人可以帮助我并展示/举一些例子吗?

1 回答

  • 0

    您必须生成OTP并通过短信发送它保存并验证您,Twillo不生成该OTP .

    此代码生成OTP:

    protected void GenerateOTP(object sender, EventArgs e)
    {
        string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
        string numbers = "1234567890";
    
        string characters = numbers;
        if (rbType.SelectedItem.Value == "1")
        {
             characters += alphabets + small_alphabets + numbers;
        }
        int length = int.Parse(ddlLength.SelectedItem.Value);
        string otp = string.Empty;
        for (int i = 0; i < length; i++)
        {
            string character = string.Empty;
            do
            {
                int index = new Random().Next(0, characters.Length);
                character = characters.ToCharArray()[index].ToString();
            } while (otp.IndexOf(character) != -1);
            otp += character;
        }
        lblOTP.Text = otp;
     }
    

相关问题