import logging import uuid import hmac import hashlib from . import config def encrypt_phone(phone): return hmac.new( config.PHONE_HMAC_KEY.encode("utf-8"), phone.encode("utf-8"), hashlib.sha256, ).hexdigest() def create_session_token(): """生成写入 auth_sessions 的会话 token(长度适合 token VARCHAR(64))。""" return uuid.uuid4().hex + uuid.uuid4().hex[:16]