更新二维码生成
This commit is contained in:
parent
a003d4c0a0
commit
91f77a6957
29
.gitlab-ci.yml
Normal file
29
.gitlab-ci.yml
Normal file
@ -0,0 +1,29 @@
|
||||
stages:
|
||||
- clear
|
||||
- build
|
||||
- deploy
|
||||
|
||||
clear:
|
||||
stage: clear
|
||||
tags:
|
||||
- dockerbase
|
||||
script:
|
||||
- docker stop qrcode
|
||||
- docker rm qrcode
|
||||
allow_failure: true
|
||||
|
||||
|
||||
build:
|
||||
stage: build
|
||||
tags:
|
||||
- dockerbase
|
||||
script:
|
||||
- ls -a
|
||||
- docker build -t lacus/qrcode .
|
||||
|
||||
deploy:
|
||||
stage: deploy
|
||||
tags:
|
||||
- dockerbase
|
||||
script:
|
||||
- docker run -t -d --name qrcode -v /root/yingbo/qrcode/data:/app/data -p 5002:80 lacus/qrcode
|
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM python:3.7-alpine
|
||||
COPY requirements.txt /app/requirements.txt
|
||||
WORKDIR /app
|
||||
RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl
|
||||
RUN apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev
|
||||
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
COPY . .
|
||||
CMD sh go.sh && python
|
2
go.sh
2
go.sh
@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
echo start
|
||||
gunicorn qrcode:app -c gunicorn.conf.py
|
||||
gunicorn main:app -c gunicorn.conf.py
|
0
lib/__init__.py
Normal file
0
lib/__init__.py
Normal file
@ -1,9 +1,11 @@
|
||||
from db import findUser, delCode, insertCode
|
||||
from login import getOpenid
|
||||
from utils import checkData
|
||||
import re
|
||||
import json
|
||||
import os
|
||||
import qrcode
|
||||
from db import findUser, delCode, insertCode
|
||||
from login import getOpenid
|
||||
from utils import checkData
|
||||
from io import BytesIO
|
||||
|
||||
# 当前文件地址
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
@ -82,3 +84,26 @@ def addQR(request):
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
def genQR(text):
|
||||
# 空内容拦截
|
||||
if not text:
|
||||
return False
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_H,
|
||||
box_size=10,
|
||||
border=2
|
||||
)
|
||||
# 传入数据
|
||||
qr.add_data(text)
|
||||
|
||||
qr.make(fit=True)
|
||||
# 生成二维码
|
||||
im = qr.make_image()
|
||||
img = BytesIO()
|
||||
# 将图片放图片流里面
|
||||
im.save(img, format='PNG')
|
||||
# 返回图片流
|
||||
img = img.getvalue()
|
||||
return img
|
@ -3,7 +3,7 @@ from bson import ObjectId, json_util
|
||||
|
||||
# 获取数据集
|
||||
def col(arg: str = None):
|
||||
conn = MongoClient('mongodb://qrcode:mR6rN4pI0rU6@mongo:27017/qrcode')
|
||||
conn = MongoClient('mongodb://qrcode:mR6rN4pI0rU6@39.96.28.83:27017/qrcode')
|
||||
return conn.qrcode[arg]
|
||||
|
||||
# 查找该用户所有信息
|
||||
|
15
lib/utils.py
15
lib/utils.py
@ -23,7 +23,6 @@ def checkData(data):
|
||||
hrefCount = 0
|
||||
usernameCount = 0
|
||||
openIdCount = 0
|
||||
timeoutCount = 0
|
||||
|
||||
# 可能的参数
|
||||
# wxp://f2f0e4PCkhToyNDT-zfA-Nn6zoAgPKvK9HUl
|
||||
@ -141,17 +140,7 @@ def checkData(data):
|
||||
else:
|
||||
node = ''
|
||||
|
||||
# 过期时间验证
|
||||
timeout = str(data['timeout'])
|
||||
if(not isKong(timeout)):
|
||||
if len(timeout) == 13:
|
||||
timeoutCount = 1
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
if hrefCount >= 2 and usernameCount and openIdCount and timeoutCount:
|
||||
return {'username': username, 'node': node, 'wxcode': wxcode, 'alcode': alcode, 'qqcode': qqcode, 'openId': openId, 'timeout': timeout, 'create_time': int(time.time()), 'id': randomId()}
|
||||
if hrefCount >= 2 and usernameCount and openIdCount:
|
||||
return {'username': username, 'node': node, 'wxcode': wxcode, 'alcode': alcode, 'qqcode': qqcode, 'openId': openId, 'create_time': int(time.time()), 'id': randomId()}
|
||||
else:
|
||||
return False
|
0
logs/acess.log
Normal file
0
logs/acess.log
Normal file
0
logs/error.log
Normal file
0
logs/error.log
Normal file
@ -1,16 +1,11 @@
|
||||
# 将lib里边的文件加到路由中
|
||||
import sys
|
||||
sys.path.append('./lib')
|
||||
|
||||
import os
|
||||
from flask import Flask, escape, url_for, request, render_template, redirect, abort, send_from_directory
|
||||
from allFunction import manageLogin, flash, delQR, addQR
|
||||
from flask_qrcode import QRcode
|
||||
from flask import Flask, escape, url_for, request, render_template, redirect, abort, send_from_directory, Response
|
||||
from allFunction import flash, delQR, addQR, genQR, manageLogin
|
||||
|
||||
app = Flask(__name__)
|
||||
QRcode(app)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
||||
# 用户小程序登录
|
||||
@app.route('/login',methods=['POST'])
|
||||
@ -51,8 +46,11 @@ def addQRCode():
|
||||
# 生成二维码
|
||||
@app.route('/generate',methods=['GET'])
|
||||
def generate():
|
||||
text = request.args.get("text")
|
||||
return qrcode(text)
|
||||
res = genQR(request.args.get("text"))
|
||||
if(res):
|
||||
return Response(res, mimetype='image/png')
|
||||
else:
|
||||
abort(400)
|
||||
|
||||
# 控制小程序是否显示“最佳案例”
|
||||
@app.route('/config', methods=['post'])
|
||||
@ -83,4 +81,7 @@ def page_not_found(e):
|
||||
|
||||
@app.errorhandler(410)
|
||||
def page_not_found(e):
|
||||
return render_template('410.html'), 500
|
||||
return render_template('410.html'), 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", debug=True, port="80")
|
Before Width: | Height: | Size: 368 KiB After Width: | Height: | Size: 368 KiB |
@ -77,11 +77,6 @@
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
// 判断时间
|
||||
var timeout = parseInt(data.timeout)
|
||||
timeout = new Date(timeout)
|
||||
var now = new Date()
|
||||
if (timeout - now <= 0) window.location.replace("https://qr.lacus.site/qr/410.html");
|
||||
// 换背景
|
||||
ele('bg').src = bgs[Math.floor(Math.random() * bgs.length)]
|
||||
setting.id = data._id.$oid
|
||||
|
15
requirements.txt
Normal file
15
requirements.txt
Normal file
@ -0,0 +1,15 @@
|
||||
certifi==2020.12.5
|
||||
chardet==4.0.0
|
||||
click==7.1.2
|
||||
Flask==1.1.2
|
||||
idna==2.10
|
||||
itsdangerous==1.1.0
|
||||
Jinja2==2.11.2
|
||||
MarkupSafe==1.1.1
|
||||
Pillow==8.1.0
|
||||
pymongo==3.11.2
|
||||
qrcode==6.1
|
||||
requests==2.25.1
|
||||
six==1.15.0
|
||||
urllib3==1.26.2
|
||||
Werkzeug==1.0.1
|
Loading…
x
Reference in New Issue
Block a user