前提是你需要有refresh_token,没有的先努力升级3级吧
利用始皇的接口,根据rt更新at,根据at更新st,把st拼接成url,放到nginx反代配置文件然后reload,以后只需要访问代理就行了。
##脚本代码
#!/bin/bash
# 定义Nginx配置文件路径
config_path="/etc/nginx/conf.d/t.chatweb.conf"
# 定义请求URL和参数
url="https://token.oaifree.com/api/auth/refresh"
refresh_token="你的refreshtoken"
share_url="https://chat.oaifree.com/token/register"
# 发送POST请求并获取新的access_token
response=$(curl -s -X POST -d "refresh_token=$refresh_token" "$url")
# 使用jq工具解析JSON并提取access_token(需要先安装jq: yum install jq)
access_token=$(echo $response | jq -r .access_token)
# 检查提取的token是否为空
if [ -z "$access_token" ] || [ "$access_token" == "null" ]; then
echo "No valid access_token found in the response."
exit 1
fi
# 使用access_token获取sharetoken
share_response=$(curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" \
--data-urlencode "unique_name=随便填" \
--data-urlencode "access_token=$access_token" \
--data-urlencode "expires_in=0" \
--data-urlencode "site_limit=" \
--data-urlencode "gpt35_limit=-1" \
--data-urlencode "gpt4_limit=-1" \
--data-urlencode "show_conversations=true" \
"$share_url")
#echo "Using access_token: $access_token"
#echo "Share response: $share_response" # 添加这行来打印响应内容
share_token=$(echo $share_response | jq -r .token_key)
# 检查提取的share_token是否为空
if [ -z "$share_token" ] || [ "$share_token" == "null" ]; then
echo "No valid share token found in the response."
exit 1
fi
# 更新配置文件中的token部分
#sed -i "s/\(token=\)[^;]*/\1$access_token/" "$config_path"
sed -i "s/\(token=\)[^;]*/\1$share_token/" "$config_path"
# 重新加载Nginx配置以使更改生效
#nginx -s reload
# 测试新的Nginx配置
nginx -t
if [ $? -ne 0 ]; then
echo "Nginx configuration test failed, reload aborted."
exit 1
else
# 重新加载Nginx配置以使更改生效
nginx -s reload
echo "Nginx configuration updated and reloaded successfully."
fi
# 可选:记录操作
#echo "Nginx configuration updated with new token: $access_token" >> /var/log/update_nginx_token.log
echo "Nginx configuration updated with new share token: $share_token" >> /var/log/update_nginx_token.log
##nginx配置
server {
listen 6389;
server_name 47.11.11.11;
location /chatweb {
return 301 https://new.oaifree.com/auth/login_share?token=fk-PMyo;
}
}
#crontab -e
10 0 * * * /root/deploy/pandoraHelper/update_nginx_token.sh
然后访问http://ip:port/chatweb就可以用了