pytho获取google验证码

import time
import base64
import sys
import hashlib
import hmac
import struct
def google_code():
key = base64.b32decode('CSF5WCJP5GH3CODA')
msg = struct.pack(">Q", int(time.time()) // 30)
code = hmac.new(key, msg, hashlib.sha1).digest()

# 版本判断
if sys.version_info > (2, 7):
o = code[19] & 15
else:
o = ord(code[19]) & 15
code = (struct.unpack(">I", code[o:o + 4])[0] & 0x7fffffff) % 1000000
return '%06d' % code

ggcode=google_code()
posted @ 2021-02-04 13:50  HUC-PASSER  阅读(101)  评论(0编辑  收藏  举报