效果如下所示:apikey会每天更新,增加用户粘性
代码:
<iframe src="https://share.opao.xyz/" width="500" height="400" style="border: none;"></iframe>
源码:
from flask import Flask, render_template
import time
import requests
from flask_cors import CORS
import os
app = Flask(__name__)
CORS(app)
API_token=os.getenv('',"")
burl='https://api.openai.com'
current_timestamp = int(time.time())
one_day_later_timestamp = current_timestamp + 86400
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Sec-Fetch-Mode': 'cors',
'Authorization': 'Bearer '+API_token,
}
def get_key():
url=burl+"/api/token/?p=0&size=10"
req=requests.get(url ,headers=headers,timeout=10).json()
return req
def creat_key():
url=burl+'/api/token'
data={"name":"free","remain_quota":1000000,"expired_time":one_day_later_timestamp,"unlimited_quota":False,"model_limits_enabled":False,"model_limits":"","allow_ips":"","group":""}
req=requests.post(url,json=data,headers=headers,timeout=10).json()
return req
def delete_key():
id=get_key()['data'][0]['id']
url=f'{burl}/api/token/{id}'
req=requests.delete(url,headers=headers,timeout=10).json()
return req
print(delete_key())
print(creat_key())
key=get_key()['data'][0]['key']
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# 路由,渲染动态内容
@app.route('/')
def index():
# 渲染 HTML 模板并传递时间戳变量
return render_template('index.html',burl=burl, current_time=current_time, apikey='sk-'+key)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=45002)
html源码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Timestamps</title>
<style>
/* 页面全局样式 */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
/* 容器样式 */
.container {
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
text-align: center;
}
/* 标题样式 */
h1 {
font-size: 24px;
color: #333;
margin-bottom: 20px;
}
/* 预格式化展示的样式 */
pre {
background-color: #eaeaea;
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
white-space: pre-wrap;
word-wrap: break-word;
font-family: 'Courier New', Courier, monospace;
font-size: 16px;
color: #333;
}
/* 响应式处理 */
@media (max-width: 600px) {
.container {
padding: 15px;
}
h1 {
font-size: 20px;
}
pre {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>每日更新:{{ current_time }}</h1>
<p>baseurl:</p>
<pre>{{ burl }}</pre>
<p>apikey:</p>
<pre>{{ apikey }}</pre>
</div>
</body>
</html>