ETJava Beta | Java    注册   登录
  • java 获取github 2F验证码

    发表于 2024-05-07 21:03:44     阅读(206)     博客类别:J2SE

    添加依赖

     

    <dependency>
          <groupId>com.amdelamar</groupId>
          <artifactId>jotp</artifactId>
          <version>1.3.0</version>
        </dependency>

     

     

    执行下面代码

    public class TOTPTest {
    
        public static void main(String[] args) throws Exception{
            // Generate a Time-based OTP from the secret, using Unix-time
            // rounded down to the nearest 30 seconds.
            String hexTime = OTP.timeInHex(System.currentTimeMillis(), 30);
            String secret="123456";// github 的 secrt码
            String code = OTP.create(secret, hexTime, 6, Type.TOTP);
            System.out.println(code);
        }
    }