【问题标题】:How to implement One time Verification(OTP) using Twilio SMS/Voice api如何使用 Twilio SMS/Voice api 实现一次性验证(OTP)
【发布时间】:2015-09-26 00:33:13
【问题描述】:

我可以使用 twilio SMS APi 发送 SMS

Map<String,String> params = new HashMap<String,String>();
params.put("From", fromNumber);
params.put("To", toNumber);
params.put("Body", "Bad news " + admins.get(toNumber) + ", take this");

try {
    // send an sms a call
    // ( This makes a POST request to the SMS/Messages resource)
    Sms sms = smsFactory.create(params);
    System.out.println("Success sending SMS: " + sms.getSid());
}

并希望在基于 SPring MVC 的 Web 应用程序中实现基于一次性密码 (OTP) 的身份验证。基于百里香叶的矿山视图。我得到了这个链接,但这个实现是在 PHP 中。https://www.twilio.com/docs/howto/two-factor-authentication

还尝试使用 Node.js 实现(https://www.twilio.com/docs/node/install#using)in 此案例脚本已执行,但没有发生 SMS 发送

<script>
// Your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACabdb218474d12644b16a5cfe891ce962';
var authToken = 'a4ba7b6ec6eb09aeccfbbb2143bc951d';
var client = require('twilio')(accountSid, authToken);

client.messages.create({
        to: '+918800989508',
        from:'+1 415-099-2671',
        body: 'Jenny please?! I love you 3',

    }, function(err, message) {
        process.stdout.write(message.sid);
    });

</script>

基于 Java 的应用程序的任何实现。

【问题讨论】:

  • 有一个twilio-java-sdk:twilio.com/docs/java/install
  • @PatrickLC 我实现了相同并且能够发送短信。但是想使用 Java 脚本来实现相同的事情,因为我可以生成 no 并通过 SMS 发送生成的 no 并在固定时间段内在 UI 上进行验证。你能建议我用java脚本来做吗?

标签: javascript spring-mvc authentication twilio


【解决方案1】:

来自 Twilio 的 Ricky 在这里。

我们有一个更新的教程,展示了如何使用 Java 实现这一点:

https://www.twilio.com/docs/tutorials/walkthrough/two-factor-authentication/java/servlets

我们使用 Authy 来验证用户,这里是处理这个的代码:

private Result sendApprovalRequest(User user) throws IOException {
    Parameters parameters = Parameters.builder()
            .addDetail("email", user.getEmail())
            .build();

    return client.sendApprovalRequest(
            user.getAuthyId(), "Request login to Twilio demo app", parameters);
}

【讨论】:

    猜你喜欢
    • 2017-12-24
    • 2019-02-04
    • 2022-11-11
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多