最后,它正在python3
使用https://github.com/pyotp/pyotp/tree/master/src/pyotp
示例:
from pyotp.hotp import HOTP
import time
hotp=HOTP()
secret_KEY="12345678901234567890123456789012"
while 1:
time.sleep(0.5)
print(hotp.counter_from_time())
hotp.generate_code_from_time(secret_key=secret_KEY, code_length=6, period=30)
这给了:
(b'\x00\x00\x00\x00\x03\n\x90\x90', 7.0)
('079310', 23)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 7.0)
('079310', 23)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 8.0)
('079310', 22)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 8.0)
('079310', 22)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 9.0)
('079310', 21)
[...]