Skip to content

Commit

Permalink
feat: qrcode uc cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
DDSRem committed Sep 21, 2024
1 parent fe31251 commit a5e7f76
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 10 deletions.
60 changes: 52 additions & 8 deletions all_in_one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,42 @@ function qrcode_quark_cookie() {

}

function qrcode_uc_cookie() {

clear_qrcode_container
cpu_arch=$(uname -m)
case $cpu_arch in
"x86_64" | *"amd64"* | "aarch64" | *"arm64"* | *"armv8"* | *"arm/v8"*)
INFO "UC Cookie 扫码获取"
local local_ip
INFO "拉取镜像中..."
docker_pull ddsderek/xiaoya-glue:python
if [[ "${OSNAME}" = "macos" ]]; then
local_ip=$(ifconfig "$(route -n get default | grep interface | awk -F ':' '{print$2}' | awk '{$1=$1};1')" | grep 'inet ' | awk '{print$2}')
else
local_ip=$(ip address | grep inet | grep -v 172.17 | grep -v 127.0.0.1 | grep -v inet6 | awk '{print $2}' | sed 's/addr://' | head -n1 | cut -f1 -d"/")
fi
if [ -z "${local_ip}" ]; then
local_ip="小雅服务器IP"
fi
INFO "请稍等片刻直到 Flask 启动后浏览器访问 http://${local_ip}:34256 并使用UC浏览器APP扫描二维码!"
docker run -i --rm \
-v "${1}:/data" \
-e LANG=C.UTF-8 \
--net=host \
ddsderek/xiaoya-glue:python \
/uc_cookie/uc_cookie.py
INFO "清理镜像中..."
docker rmi ddsderek/xiaoya-glue:python
INFO "操作全部完成!"
;;
*)
WARN "目前 UC Cookie 扫码获取只支持amd64和arm64架构,你的架构是:$cpu_arch"
;;
esac

}

function enter_aliyunpan_refreshtoken() {

INFO "是否使用扫码自动 Token [Y/n](默认 Y)"
Expand Down Expand Up @@ -598,14 +634,22 @@ function settings_quark_cookie() {
function enter_uc_cookie() {

touch ${1}/uc_cookie.txt
while true; do
INFO "输入你的 UC Cookie"
read -erp "Cookie:" uc_cookie
echo -e "${uc_cookie}" > ${1}/uc_cookie.txt
if check_uc_cookie "${1}"; then
break
fi
done
INFO "是否使用扫码自动 Cookie [Y/n](默认 Y)"
read -erp "Cookie:" choose_qrcode_uc_cookie
[[ -z "${choose_qrcode_uc_cookie}" ]] && choose_qrcode_uc_cookie="y"
if [[ ${choose_qrcode_uc_cookie} == [Yy] ]]; then
qrcode_uc_cookie "${1}"
fi
if ! check_uc_cookie "${1}"; then
while true; do
INFO "输入你的 UC Cookie"
read -erp "Cookie:" uc_cookie
echo -e "${uc_cookie}" > ${1}/uc_cookie.txt
if check_uc_cookie "${1}"; then
break
fi
done
fi

}

Expand Down
3 changes: 2 additions & 1 deletion glue_python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ RUN pip install --no-cache --upgrade pip && \
pip install --no-cache -r /aliyuntvtoken/requirements.txt && \
pip install --no-cache -r /aliyuntoken/requirements.txt && \
pip install --no-cache -r /aliyunopentoken/requirements.txt && \
pip install --no-cache -r /quark_cookie/requirements.txt
pip install --no-cache -r /quark_cookie/requirements.txt && \
pip install --no-cache -r /uc_cookie/requirements.txt
3 changes: 2 additions & 1 deletion glue_python/quark_cookie/quark_cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def poll_qrcode_status(token):
break
elif re_data['status'] == 50004002:
logging.error('二维码无效或已过期!')
last_status = 2
break
elif re_data['status'] == 50004001:
logging.info('等待用户扫码...')
time.sleep(1)
time.sleep(2)


@app.route("/")
Expand Down
6 changes: 6 additions & 0 deletions glue_python/uc_cookie/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# UC Cookie

- uc.cn
- api.open.uc.cn
- drive.uc.cn
- su.uc.cn
2 changes: 2 additions & 0 deletions glue_python/uc_cookie/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
qrcode
Binary file added glue_python/uc_cookie/static/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions glue_python/uc_cookie/static/jquery.min.js

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions glue_python/uc_cookie/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>UC Cookie</title>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<style>
body {
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
flex-direction: column;
}
</style>
<script src="{{ url_for('static', filename='jquery.min.js') }}"></script>
</head>
<body>
<h1>请打开UC浏览器APP扫描此二维码!</h1>
<img src="{{ url_for('serve_image') }}" alt="image">
<script>
var poll = function() {
$.get('/status', function(data) {
if (data.status === 'success') {
alert('扫码成功,Cookie 已写入文件!');
shutdown();
} else if (data.status === 'failure') {
alert('扫码失败!');
shutdown();
}
});
}

var shutdown = function() {
$.ajax({
url: '/shutdown_server',
type: 'get',
complete: function() {
window.close();
clearInterval(pollInterval);
}
});
}

var pollInterval = setInterval(poll, 1000);
</script>
</body>
</html>
115 changes: 115 additions & 0 deletions glue_python/uc_cookie/uc_cookie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/local/bin/python3

import json
import requests
import time
import logging
import os
import threading
import sys
import qrcode
import random
from flask import Flask, send_file, render_template, jsonify


app = Flask(__name__)
logging.basicConfig(level=logging.INFO)
last_status = 0
if sys.platform.startswith('win32'):
qrcode_dir = 'qrcode.png'
else:
qrcode_dir= '/uc_cookie/qrcode.png'


def cookiejar_to_string(cookiejar):
cookie_string = ""
for cookie in cookiejar:
cookie_string += cookie.name + "=" + cookie.value + "; "
return cookie_string.strip('; ')


def poll_qrcode_status(token):
global last_status
while True:
__t = int(time.time() * 1000)
data = {
'client_id': 381,
'v': 1.2,
'request_id': __t,
'token': token
}
re = requests.post(f'https://api.open.uc.cn/cas/ajax/getServiceTicketByQrcodeToken?__dt={random.randint(100, 999)}&__t={__t}', data=data)
if re.status_code == 200:
re_data = json.loads(re.content)
if re_data['status'] == 2000000:
logging.info('扫码成功!')
service_ticket = re_data['data']['members']['service_ticket']
re = requests.get(f'https://drive.uc.cn/account/info?st={service_ticket}')
if re.status_code == 200:
uc_cookie = cookiejar_to_string(re.cookies)
if sys.platform.startswith('win32'):
with open('uc_cookie.txt', 'w') as f:
f.write(uc_cookie)
else:
with open('/data/uc_cookie.txt', 'w') as f:
f.write(uc_cookie)
logging.info('扫码成功,UC Cookie 已写入文件!')
last_status = 1
break
elif re_data['status'] == 50004002:
logging.error('二维码无效或已过期!')
last_status = 2
break
elif re_data['status'] == 50004001:
logging.info('等待用户扫码...')
time.sleep(2)


@app.route("/")
def index():
return render_template('index.html')


@app.route('/image')
def serve_image():
return send_file(qrcode_dir, mimetype='image/png')


@app.route('/status')
def status():
if last_status == 1:
return jsonify({'status': 'success'})
elif last_status == 2:
return jsonify({'status': 'failure'})
else:
return jsonify({'status': 'unknown'})


@app.route('/shutdown_server', methods=['GET'])
def shutdown():
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
os._exit(0)


if __name__ == '__main__':
if os.path.isfile(qrcode_dir):
os.remove(qrcode_dir)
logging.info('二维码生成中...')
__t = int(time.time() * 1000)
data = {
'client_id': 381,
'v': 1.2,
'request_id': __t
}
re = requests.post(f'https://api.open.uc.cn/cas/ajax/getTokenForQrcodeLogin?__dt={random.randint(100, 999)}&__t={__t}', data=data)
if re.status_code == 200:
token = json.loads(re.content)['data']['members']['token']
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=5, border=4)
qr.add_data(f'https://su.uc.cn/1_n0ZCv?uc_param_str=dsdnfrpfbivesscpgimibtbmnijblauputogpintnwktprchmt&token={token}&client_id=381&uc_biz_str=S%3Acustom%7CC%3Atitlebar_fix')
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img.save(qrcode_dir)
logging.info('二维码生成完成!')
threading.Thread(target=poll_qrcode_status, args=(token,)).start()
app.run(host='0.0.0.0', port=34256)

0 comments on commit a5e7f76

Please sign in to comment.