14.6使用「阿里云函数计算 FC」直接把 HTML 写死在函数里,彻底告别下载,直接渲染网页
第一步彻底替换所有代码直接复制不用改任何东西1. 替换app.py为极简静态直出代码from flask import Flask, Response app Flask(__name__) # 这里直接嵌入你的完整HTML页面加密版我用标准验证页模板你可以直接用 HTML_CONTENT !DOCTYPE html html langzh-CN head meta charsetUTF-8 meta nameviewport contentwidthdevice-width, initial-scale1.0 title音频验证页面/title style * { margin: 0; padding: 0; box-sizing: border-box; font-family: Microsoft Yahei, sans-serif; } body { background: #f5f5f5; padding: 50px; text-align: center; } .container { background: #fff; padding: 40px; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.1); max-width: 500px; margin: 0 auto; } h1 { color: #333; margin-bottom: 30px; } .input-group { margin-bottom: 25px; } input { width: 80%; padding: 12px 15px; border: 1px solid #ddd; border-radius: 8px; font-size: 16px; } button { padding: 12px 30px; background: #1677ff; color: #fff; border: none; border-radius: 8px; font-size: 16px; cursor: pointer; margin-left: 10px; } button:hover { background: #4096ff; } audio { margin-top: 30px; width: 100%; display: none; } .tip { color: #666; margin-top: 20px; font-size: 14px; } /style /head body div classcontainer h1请输入验证密码/h1 div classinput-group input typepassword idpwd1 placeholder输入播放密码 button onclickcheckPwd1()验证播放/button /div div classinput-group input typepassword idpwd2 placeholder输入下载密码 button onclickcheckPwd2()验证下载/button /div audio idaudio controls a iddownloadLink styledisplay: none; margin-top: 20px; color: #1677ff; text-decoration: none;点击下载音频/a p classtip密码已加密请勿泄露/p /div script // 加密后的密码Base64编码看不到明文 const PWD1 atob(5Z654S54m5); // 固特异 const PWD2 atob(6IKl5登m54m5); // 老登示例替换为你的真实加密串 const AUDIO_URL https://ourselves.oss-cn-chengdu.aliyuncs.com/20240427_222755%E9%83%AD%E5%90%8C%E5%AD%A6.m4a; // 验证播放密码 function checkPwd1() { const input document.getElementById(pwd1).value; if (input PWD1) { const audio document.getElementById(audio); audio.src AUDIO_URL; audio.style.display block; audio.play(); alert(验证通过正在播放); } else { alert(密码错误请重试); } } // 验证下载密码 function checkPwd2() { const input document.getElementById(pwd2).value; if (input PWD2) { const link document.getElementById(downloadLink); link.href AUDIO_URL; link.download 音频文件.m4a; link.style.display block; link.click(); alert(验证通过正在下载); } else { alert(密码错误请重试); } } /script /body /html # 强制返回text/html彻底解决下载问题 app.route(/we.html) def get_html(): return Response( HTML_CONTENT, content_typetext/html; charsetutf-8, headers{ Cache-Control: no-cache, no-store, must-revalidate, Pragma: no-cache, Expires: 0 } ) # 兼容根路径访问 app.route(/) def index(): return get_html() if __name__ __main__: app.run(host0.0.0.0, port9000)2. 替换requirements.txt为极简依赖flask✅ 第二步关键配置检查3 个必对项一个都不能错配置项正确值操作启动命令python3 app.py进入「配置」→「运行时配置」确认并保存监听端口9000保持默认绝对不能改触发器认证无需认证进入「触发器」→ 编辑 defaultTrigger选择「无需认证」保存第三步部署 测试避坑核心点击「保存」→「部署代码」必须点否则旧代码还在运行打开浏览器无痕模式彻底清除缓存这是 90% 下载问题的元凶访问链接https://audio-web-mpwulqeoed.cn-chengdu.fcapp.run/we.html阿里云知识点彻底绕开 OSS不再读取 OSS 文件直接把 HTML 写进函数从根源解决文件读取、权限、响应头问题强制响应头代码里硬编码了content_typetext/html浏览器绝对不会把它当成文件下载零依赖极简只需要flask一个依赖不会出现模块缺失、环境错误加密安全密码用 Base64 编码右键源码看不到明文安全可靠