├── requirements.txt ├── README.md ├── .gitignore ├── app.py └── templates └── index.html /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==3.1.0 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pikpak-Verification-Code 2 | 3 | 短效邮箱一键提取PikPak验证码 4 | 5 | ## 在线测试网站: 6 | 7 | https://code.kiteyuan.info/ 8 | 9 | ## 使用方法: 10 | 11 | ```python 12 | # 设置客户端 ID 和邮箱信息 13 | client_id = "" # 替换为你的 client_id 14 | email = "" # 替换为你的邮箱 15 | refresh_token = "" # 替换为你的 refresh_token 16 | ``` 17 | 对比源代码,新增前端以及自动识别功能 18 | ![image](https://github.com/user-attachments/assets/45cdc15b-c92d-4e34-9716-b58de3bfc33d) 19 | 20 | 21 | 由于微软邮箱新机制,闪邮箱提供了refresh_token为用户提供登录邮箱的服务:[邮箱批发|-闪邮箱 (shanyouxiang.com)](https://shanyouxiang.com/) 22 | 23 | ``` 24 | 闪邮箱提供的邮箱信息(此为举例参考): 25 | 26 | [email] f73e6XXXlt1g@hotmail.com 27 | [password] GDrQ2BSb8 28 | [refresh_token] M.C523_BAY.0.U.-CgeAVXXbUEcbmFRjAS4UURT!ZNo0zq0Co!OvgroOByjwBHW8t3KloX6rdDAp2Ugpy4qIz84Xa2oyIPDUwvuEdb7xSYBPna74RRIGnOp5yp6D5Rb*GgdBEDxEZdEkCOdbwsC9JMLg6FlVnwgY6ubWIYKvULJmKOGKs*YXXXXXXXXXXXXXXXXX6QjBjjMY2ezziJDfga4TI*z9AMDW3*DSvSpGAkKtHG8bdFO4B7NItxLlMHiAEaVaOxSeqQuKAZVxy7N8kzKMcVNxTcjX1sbjfAZIznfKZXU*rQ4z64lTc6vMq*7hf774q3yFXQj2OMJoNXr6KUr9WcG!vrKHp1F5lVX!6defcYA8SgtXtMCFtrh3JrNsJJAAnUXNbXOgnGmwvdnZ5jxnYxegjVIn6!yv*tw$ 29 | [client_id] 8b4ba9dd-3ea5-4e5f-86f1-ddba2230dcf2 30 | ``` 31 | 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 110 | .pdm.toml 111 | .pdm-python 112 | .pdm-build/ 113 | 114 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 115 | __pypackages__/ 116 | 117 | # Celery stuff 118 | celerybeat-schedule 119 | celerybeat.pid 120 | 121 | # SageMath parsed files 122 | *.sage.py 123 | 124 | # Environments 125 | .env 126 | .venv 127 | env/ 128 | venv/ 129 | ENV/ 130 | env.bak/ 131 | venv.bak/ 132 | 133 | # Spyder project settings 134 | .spyderproject 135 | .spyproject 136 | 137 | # Rope project settings 138 | .ropeproject 139 | 140 | # mkdocs documentation 141 | /site 142 | 143 | # mypy 144 | .mypy_cache/ 145 | .dmypy.json 146 | dmypy.json 147 | 148 | # Pyre type checker 149 | .pyre/ 150 | 151 | # pytype static type analyzer 152 | .pytype/ 153 | 154 | # Cython debug symbols 155 | cython_debug/ 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | #.idea/ 163 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request, jsonify 2 | import imaplib 3 | import re 4 | import logging 5 | import email 6 | 7 | # 设置日志记录 8 | logging.basicConfig(level=logging.INFO) 9 | logger = logging.getLogger(__name__) 10 | 11 | app = Flask(__name__) 12 | 13 | # IMAP 服务器信息 14 | IMAP_SERVER = 'imap.shanyouxiang.com' 15 | IMAP_PORT = 993 # IMAP SSL 端口 16 | 17 | # 邮件发送者列表(用于查找验证码) 18 | VERIFICATION_SENDERS = ['noreply@accounts.mypikpak.com'] 19 | 20 | 21 | # --------------------------- IMAP 获取验证码 --------------------------- 22 | 23 | def connect_imap(email_user, email_password, folder='INBOX'): 24 | """ 25 | 使用 IMAP 连接并检查指定文件夹中的验证码邮件 26 | """ 27 | try: 28 | # 连接 IMAP 服务器 29 | mail = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT) 30 | mail.login(email_user, email_password) # 直接使用邮箱密码登录 31 | 32 | # 选择文件夹 33 | status, _ = mail.select(folder) 34 | if status != 'OK': 35 | return {"code": 0, "msg": f"无法访问 {folder} 文件夹"} 36 | 37 | # 搜索邮件 38 | status, messages = mail.search(None, 'ALL') 39 | if status != 'OK' or not messages[0]: 40 | return {"code": 0, "msg": f"{folder} 文件夹为空"} 41 | 42 | message_ids = messages[0].split() 43 | verification_code = None 44 | timestamp = None 45 | 46 | for msg_id in message_ids[::-1]: # 从最新邮件开始查找 47 | status, msg_data = mail.fetch(msg_id, '(RFC822)') 48 | if status != 'OK': 49 | continue 50 | 51 | for response_part in msg_data: 52 | if isinstance(response_part, tuple): 53 | msg = email.message_from_bytes(response_part[1]) 54 | from_email = msg['From'] 55 | 56 | if any(sender in from_email for sender in VERIFICATION_SENDERS): 57 | timestamp = msg['Date'] 58 | 59 | # 解析邮件正文 60 | if msg.is_multipart(): 61 | for part in msg.walk(): 62 | if part.get_content_type() == 'text/html': 63 | body = part.get_payload(decode=True).decode('utf-8') 64 | break 65 | else: 66 | body = msg.get_payload(decode=True).decode('utf-8') 67 | 68 | # 提取验证码 69 | match = re.search(r'\b(\d{6})\b', body) 70 | if match: 71 | verification_code = match.group(1) 72 | break 73 | 74 | if verification_code: 75 | break 76 | 77 | mail.logout() 78 | 79 | if verification_code: 80 | return {"code": 200, "verification_code": verification_code, "time": timestamp, 81 | "msg": f"成功获取验证码 ({folder})"} 82 | else: 83 | return {"code": 0, "msg": f"{folder} 中未找到验证码"} 84 | 85 | except imaplib.IMAP4.error as e: 86 | logger.error(f"IMAP 认证失败: {e}") 87 | return {"code": 401, "msg": "IMAP 认证失败,请检查邮箱和密码是否正确"} 88 | except Exception as e: 89 | logger.error(f"IMAP 发生错误: {e}") 90 | return {"code": 500, "msg": f"错误: {str(e)}"} 91 | 92 | 93 | # --------------------------- Flask 端点 --------------------------- 94 | 95 | @app.route('/') 96 | def index(): 97 | return render_template('index.html') 98 | 99 | 100 | @app.route('/get_verification', methods=['POST']) 101 | def get_verification(): 102 | """ 103 | 处理获取验证码的请求 104 | """ 105 | email_user = request.form['email'] 106 | email_password = request.form['password'] 107 | 108 | # 先尝试从收件箱获取验证码 109 | result = connect_imap(email_user, email_password, 'INBOX') 110 | 111 | # 如果收件箱没有找到验证码,则尝试从垃圾邮件中查找 112 | if result["code"] == 0: 113 | logger.info("未找到验证码,检查垃圾邮件") 114 | result = connect_imap(email_user, email_password, 'Junk') 115 | 116 | return jsonify(result) 117 | 118 | 119 | if __name__ == '__main__': 120 | app.run(host='0.0.0.0', port=5000, debug=True) 121 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | PikPak验证码获取器 8 | 9 | 88 | 89 | 90 | 91 |
92 | 作者源代码 94 |

PikPak验证码获取器

95 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 |
105 |
106 | 176 | 177 | 178 | 179 | --------------------------------------------------------------------------------