繁体   English   中英

Nexmo 2FA 不工作/存在错误,依赖项不包括接收代码和验证代码所需的一些方法

[英]Nexmo 2FA is not working/ is bugged, dependency doesn't include some methods needed for recieving the code and verifying it

https://dashboard.nexmo.com/getting-started/verify上显示的教程说一切都应该通过编码来工作:

1   NexmoClient client = NexmoClient.Builder()
2     .apiKey("HIDDEN-CODE-I-CANNOT-SHOW")
3     .apiSecret("HIDDEN-CODE-I-CANNOT-SHOW")
4     .build();
5   VerifyClient verifyClient = client.getVerifyClient();
6
7   VerifyRequest request = new VerifyRequest("HIDDEN-CODE-I-CANNOT-SHOW", "HIDDEN-CODE-I-CANNOT-SHOW");
8   request.setLength(4);
9   
10   VerifyResponse response = verifyClient.verify(request);
11
12   if (response.getStatus() == VerifyStatus.OK) {
13       System.out.printf("RequestID: %s", response.getRequestId());
14   } else {
15       System.out.printf("ERROR! %s: %s",
16         response.getStatus(),
17         response.getErrorText()
18       );
19   }

我的问题/错误是下一个:

request.SETLENGHT(4);
response.GETSTATUS();

这两行代码 (8-12) 是红色的(只有大写字母的字符)。 如果我将 cursor 留在上面,它会分别显示一条消息“无法解析符号'setLength' ”和“无法解析符号'getStatus' ”。

我坚持有人和我有同样的问题,但事实并非如此。 我已经进入了nexmo库开发者的存储库,两个函数都写在那里(我想说它们存在),但是在我的程序中它们没有被创建。

这些是开发人员的存储库:

  1. https://github.com/Nexmo/nexmo-java
  2. https://github.com/Nexmo/nexmo-java/blob/master/src/main/java/com/nexmo/client/verify/VerifyRequest.java
  3. https://github.com/vonage/vonage-java-sdk

In the first one they say and i quote "We recommend users begin migrating over to the Vonage Java Server SDK. If you have any questions, feel free to reach out to us at devrel@vonage.com or through our Community Slack at https: //developer.nexmo.com/community/slack"正如他们所说,我确实尝试迁移到项目的新版本,但是这两行的问题也仍然存在。

第二个链接显示了为 nexmo 库编写的一些函数。 从第 315 行到第 323 行,您可以看到 function ".setLenght" 确实存在,因为开发人员为其创建了一个构建器,以下是从该链接复制和粘贴的代码:

    /**
     * @param length (optional) The length of the verification code to be sent to the user. Must be either 4 or 6. Use
     *               -1 to use the default value.
     * @return {@link Builder}
     */
    public Builder length(Integer length) {
        this.length = length;
        return this;
    }

可能是什么问题呢? 图书馆? 兼容性? 我正在使用 Apache Maven 3.6.3。 这是我的pom:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.4.2</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.2FA</groupId>
        <artifactId>Auth-Two-Steps</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>Auth-Two-Steps</name>
        <description>Mini project to learn authentication</description>
        <properties>
            <java.version>11</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>com.nexmo</groupId>
                <artifactId>client</artifactId>
                <version>5.6.0</version>
            </dependency>
    
    
            <dependency>
                <groupId>com.2FA</groupId>
                <artifactId>Auth-Two-Steps</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

这些片段可以在 nexmo 4.x SDK 上运行,但在 5.x Nexmo SDK 和 6.x Vonage ZF20E3C5E54C0AB3D375D660B3F6AZ 上会失败,需要更新。 查看代码片段- 这将向您展示如何管理所有内容。 setLength看起来在将构建器模式添加到验证请求时已被删除,您应该改用构建器模式

例如

VerifyRequest request = VerifyRequest.builder("12018675309","acme").length(6).build();

getStatus()看起来应该可以工作 - 如果您仍然遇到问题,您可能需要确保它被导入。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM