2024-06-05 05:10:50 +08:00
|
|
|
|
import aiohttp
|
2024-10-18 21:17:49 +08:00
|
|
|
|
from django.http import HttpResponse, StreamingHttpResponse,HttpResponseRedirect
|
2024-06-05 05:10:50 +08:00
|
|
|
|
import os
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
import requests
|
|
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
|
from django.views import View
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
from urllib.parse import quote
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
from aiohttp import ClientSession
|
2024-10-18 21:17:49 +08:00
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
from django.urls import reverse
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
|
|
|
|
import qrcode
|
|
|
|
|
from io import BytesIO
|
|
|
|
|
import base64
|
|
|
|
|
from django.views.decorators.http import require_GET
|
|
|
|
|
from MyApi.API_Log import get_logger
|
|
|
|
|
log_file = '网页授权登录日志.log'
|
|
|
|
|
logger = get_logger('网页授权登录日志', log_file, when='midnight', backup_count=7)
|
|
|
|
|
|
2024-06-05 05:10:50 +08:00
|
|
|
|
|
2024-10-18 21:17:49 +08:00
|
|
|
|
def acme_challenge(request):
|
|
|
|
|
|
|
|
|
|
content = f'd692debbc196f8a9849ee230e56f3b24'
|
2024-06-05 05:10:50 +08:00
|
|
|
|
return HttpResponse(content, content_type='text/plain')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
async def download_proxy(request):
|
|
|
|
|
video_url = request.GET.get('url')
|
|
|
|
|
if not video_url:
|
|
|
|
|
return HttpResponse("URL is required", status=400)
|
|
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async with ClientSession() as session:
|
|
|
|
|
try:
|
|
|
|
|
async with session.get(video_url, headers=headers) as response:
|
|
|
|
|
if response.status == 200:
|
|
|
|
|
content = await response.read() # 读取内容到内存中,注意这不适用于大文件
|
|
|
|
|
|
|
|
|
|
# 创建一个 HttpResponse 对象并设置 Content-Type
|
|
|
|
|
response = HttpResponse(content, content_type=response.headers['Content-Type'])
|
|
|
|
|
|
|
|
|
|
# 添加自定义响应头
|
|
|
|
|
response['X-Content-Length'] = str(len(content))
|
|
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
else:
|
|
|
|
|
return HttpResponse("Failed to download video", status=response.status)
|
|
|
|
|
except aiohttp.ClientConnectionError:
|
|
|
|
|
return HttpResponse("Connection closed", status=500)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProxyView(View):
|
|
|
|
|
@method_decorator(csrf_exempt)
|
|
|
|
|
def dispatch(self, *args, **kwargs):
|
|
|
|
|
return super().dispatch(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
# 获取目标URL
|
|
|
|
|
target_url = request.GET.get('url')
|
|
|
|
|
if not target_url:
|
|
|
|
|
return HttpResponse("Missing 'url' parameter", status=400)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# 请求目标URL
|
|
|
|
|
response = requests.get(target_url, stream=True)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
|
|
return HttpResponse(f"Error fetching target URL: {e}", status=500)
|
|
|
|
|
|
|
|
|
|
# 获取文件类型并强制设置为 video/mp4
|
|
|
|
|
content_type = 'video/mp4'
|
|
|
|
|
|
|
|
|
|
# 获取文件名并强制使用 .mp4 后缀
|
|
|
|
|
filename = target_url.split("/")[-1].split('?')[0] # 移除查询参数
|
|
|
|
|
if not filename.endswith('.mp4'):
|
|
|
|
|
filename = f"{filename}.mp4"
|
|
|
|
|
|
|
|
|
|
# 设置Content-Disposition头部,确保文件在浏览器中直接播放而不是下载
|
|
|
|
|
content_disposition = f'inline; filename="{filename}"'
|
|
|
|
|
|
|
|
|
|
# 创建响应对象并将内容传递给客户端
|
|
|
|
|
proxy_response = HttpResponse(content=response.content, content_type=content_type)
|
|
|
|
|
proxy_response['Content-Disposition'] = content_disposition
|
|
|
|
|
|
2024-10-18 21:17:49 +08:00
|
|
|
|
return proxy_response
|
|
|
|
|
|
|
|
|
|
def pay(request):
|
|
|
|
|
return render(request, 'pay/index.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_status(request):
|
|
|
|
|
param = request.GET.get('param') # 获取参数值
|
|
|
|
|
if param is None: # 如果参数不存在,设置默认值
|
|
|
|
|
param = 1
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
param = int(param) # 类型转换
|
|
|
|
|
except ValueError:
|
|
|
|
|
return JsonResponse({'error': 'param 参数必须是整数'}, status=400)
|
|
|
|
|
data={
|
|
|
|
|
"list": [
|
|
|
|
|
{
|
|
|
|
|
"title": "下载视频请添加机器人微信:【post3933】并转发视频给机器人",
|
|
|
|
|
"url": "https://mp.weixin.qq.com/s/xEvhtVFmXSvmC0nRoaTfXQ"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"title": "下载视频请添加机器人微信:【post3933】不会使用的点击这里查看教程。",
|
|
|
|
|
"url": "https://mp.weixin.qq.com/s/CI5YF0yjQ_wfK-J17j04og"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"title": "下载视频请添加机器人微信:【post3933】有问题或需要合作联系客服微信:post0025",
|
|
|
|
|
"url": ""
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"pay_url": "https://unapp.guimiaokeji.com/pay/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if param == 0:
|
|
|
|
|
return JsonResponse({'status':True,"data":data})
|
|
|
|
|
return JsonResponse({'status': True,"data":data})
|
|
|
|
|
|