You can add below code to get the correct TOTP
GoogleAuthenticator gAuth = new GoogleAuthenticator();
int totp = gAuth.getTotpPassword(secretKey);
and below dependency from https://github.com/wstrange/GoogleAuth
<dependency>
<groupId>com.warrenstrange</groupId>
<artifactId>googleauth</artifactId>
<version>1.4.0</version>
</dependency>