Files
soul-yongping/deploy_miniprogram.py

226 lines
7.1 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Soul创业派对 - 小程序一键部署脚本
功能:
1. 打开微信开发者工具
2. 自动编译小程序
3. 上传到微信平台
4. 显示审核指引
"""
import os
import sys
import time
import subprocess
from pathlib import Path
# 修复Windows控制台编码问题
if sys.platform == 'win32':
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
# 配置信息
CONFIG = {
'appid': 'wxb8bbb2b10dec74aa',
'project_path': Path(__file__).parent / 'miniprogram',
'version': '1.0.1',
'desc': 'Soul创业派对 - 1:1完整还原Web功能'
}
# 微信开发者工具可能的路径
DEVTOOLS_PATHS = [
r"D:\微信web开发者工具\微信开发者工具.exe",
r"C:\Program Files (x86)\Tencent\微信web开发者工具\微信开发者工具.exe",
r"C:\Program Files\Tencent\微信web开发者工具\微信开发者工具.exe",
]
def print_banner():
"""打印横幅"""
print("\n" + "=" * 70)
print(" 🚀 Soul创业派对 - 小程序一键部署")
print("=" * 70 + "\n")
def find_devtools():
"""查找微信开发者工具"""
print("🔍 正在查找微信开发者工具...")
for devtools_path in DEVTOOLS_PATHS:
if os.path.exists(devtools_path):
print(f"✅ 找到微信开发者工具: {devtools_path}\n")
return devtools_path
print("❌ 未找到微信开发者工具")
print("\n请确保已安装微信开发者工具")
print("下载地址: https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html\n")
return None
def open_devtools(devtools_path):
"""打开微信开发者工具"""
print("📱 正在打开微信开发者工具...")
try:
# 使用项目路径打开开发者工具
subprocess.Popen([devtools_path, str(CONFIG['project_path'])])
print("✅ 微信开发者工具已打开\n")
print("⏳ 等待开发者工具启动10秒...")
time.sleep(10)
return True
except Exception as e:
print(f"❌ 打开失败: {e}")
return False
def check_private_key():
"""检查上传密钥"""
key_path = CONFIG['project_path'] / 'private.key'
if not key_path.exists():
print("\n" + "" * 35)
print("\n❌ 未找到上传密钥文件 private.key\n")
print("📥 获取密钥步骤:")
print(" 1. 访问 https://mp.weixin.qq.com/")
print(" 2. 登录小程序后台")
print(" 3. 开发管理 → 开发设置 → 小程序代码上传密钥")
print(" 4. 点击「生成」,下载密钥文件")
print(" 5. 将下载的 private.*.key 重命名为 private.key")
print(f" 6. 放到目录: {CONFIG['project_path']}")
print("\n💡 温馨提示:")
print(" - 密钥只能生成一次,请妥善保管")
print(" - 如需重新生成,需要到后台重置密钥")
print("\n" + "" * 35 + "\n")
return False
print(f"✅ 找到密钥文件: private.key\n")
return True
def upload_miniprogram():
"""上传小程序"""
print("\n" + "-" * 70)
print("📦 准备上传小程序到微信平台...")
print("-" * 70 + "\n")
print(f"📂 项目路径: {CONFIG['project_path']}")
print(f"🆔 AppID: {CONFIG['appid']}")
print(f"📌 版本号: {CONFIG['version']}")
print(f"📝 描述: {CONFIG['desc']}\n")
# 检查密钥
if not check_private_key():
return False
# 切换到miniprogram目录执行上传脚本
upload_script = CONFIG['project_path'] / '上传小程序.py'
if not upload_script.exists():
print(f"❌ 未找到上传脚本: {upload_script}")
return False
print("⏳ 正在执行上传脚本...\n")
try:
result = subprocess.run(
[sys.executable, str(upload_script)],
cwd=CONFIG['project_path'],
capture_output=False, # 直接显示输出
text=True
)
return result.returncode == 0
except Exception as e:
print(f"❌ 上传出错: {e}")
return False
def show_next_steps():
"""显示后续步骤"""
print("\n" + "=" * 70)
print("✅ 部署完成!")
print("=" * 70 + "\n")
print("📱 后续操作:")
print("\n1⃣ 在微信开发者工具中:")
print(" - 查看编译结果")
print(" - 使用模拟器或真机预览测试")
print(" - 确认所有功能正常")
print("\n2⃣ 提交审核:")
print(" - 访问 https://mp.weixin.qq.com/")
print(" - 登录小程序后台")
print(" - 版本管理 → 开发版本")
print(" - 选择刚上传的版本 → 提交审核")
print("\n3⃣ 审核材料准备:")
print(" - 小程序演示视频(可选)")
print(" - 测试账号(如有登录功能)")
print(" - 功能说明(突出核心功能)")
print("\n4⃣ 审核通过后:")
print(" - 在后台点击「发布」")
print(" - 用户即可在微信中搜索使用")
print("\n" + "=" * 70 + "\n")
def main():
"""主函数"""
print_banner()
# 1. 查找微信开发者工具
devtools_path = find_devtools()
if not devtools_path:
print("💡 请先安装微信开发者工具,然后重新运行本脚本")
return False
# 2. 打开微信开发者工具
if not open_devtools(devtools_path):
print("❌ 无法打开微信开发者工具")
return False
print("\n✅ 微信开发者工具已打开,项目已加载")
print("\n💡 现在你可以:")
print(" 1. 在开发者工具中查看和测试小程序")
print(" 2. 使用模拟器或扫码真机预览")
print(" 3. 确认功能正常后,准备上传\n")
# 3. 询问是否立即上传
print("-" * 70)
user_input = input("\n是否立即上传到微信平台?(y/n默认n): ").strip().lower()
if user_input == 'y':
if upload_miniprogram():
show_next_steps()
return True
else:
print("\n❌ 上传失败")
print("\n💡 你可以:")
print(" 1. 检查 private.key 是否正确")
print(" 2. 确保已开启开发者工具的「服务端口」")
print(" 3. 或在开发者工具中手动点击「上传」按钮\n")
return False
else:
print("\n✅ 开发者工具已就绪,你可以:")
print(" 1. 在开发者工具中测试小程序")
print(" 2. 准备好后,运行本脚本并选择上传")
print(" 3. 或直接在开发者工具中点击「上传」按钮\n")
return True
if __name__ == '__main__':
try:
success = main()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n\n⚠️ 用户取消操作")
sys.exit(1)
except Exception as e:
print(f"\n❌ 发生错误: {e}")
import traceback
traceback.print_exc()
sys.exit(1)