Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
修正http二维码服务器需要刷新的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pandolia committed May 2, 2017
1 parent 3559502 commit 0466ca9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ GUI 模式是默认的模式,只适用于个人电脑。邮箱模式可以适

#### 服务器模式的配置( httpServerIP 和 httpServerPort )

如果需要使用服务器模式,可以配置 httpServerIP 和 httpServerPort 项,一般来说应该设置为公网 ip 。服务器模式开启后,可以通过 http://httpServerIP:httpServerPort/qqbot/qrcode 来访问二维码图片。
如果需要使用服务器模式,可以配置 httpServerIP 和 httpServerPort 项,一般来说应该设置为公网 ip 。服务器模式开启后,可以通过 http://{httpServerIP}:{httpServerPort}/{pngid} 来访问二维码图片。

当邮箱模式和服务器模式同时开启时,发邮件时不会发送真正的图片,只会将图片地址发到邮箱中去,而且只发送一次,二维码过期时刷新一下邮件就可以了。如果只开启邮箱模式,则发邮件时会发送真正的图片,当二维码过期时,需要将邮件设置为已读(用手机 QQ 打开邮件后该邮件就是已读了),之后才会发送最新的二维码图片。

Expand Down
3 changes: 3 additions & 0 deletions changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2017-05-02 qqbot v2.2.6
1) 修正 http 二维码服务器需要刷新的 bug ,二维码的 url 地址改为: http://{httpServerIP}:{httpServerPort}/{pngid} 。感谢 @huangzk 反馈

2017-04-27 qqbot v2.2.5
1) http-api 返回成员列表的 json 中增加成员的 ctype 属性。
2) 执行 list 命令时,采用 prettytable 打印成员列表。感谢网友 chx 提供帮助。
Expand Down
6 changes: 3 additions & 3 deletions qqbot/qconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if p not in sys.path:
sys.path.insert(0, p)

version = 'v2.2.5'
version = 'v2.2.6'

sampleConfStr = '''{
Expand Down Expand Up @@ -133,15 +133,15 @@
QTerm本地控制台服务:
-p TERMSERVERPORT, --termServerPort TERMSERVERPORT
更改QTerm控制台的监听端口到 TERMSERVERPORT 。
默认的监听端口是 8189 (TCP)。
默认的监听端口是 8188 (TCP)。
HTTP二维码查看服务器设置:
(请阅读说明文件以了解此HTTP服务器的详细信息。)
-ip HTTPSERVERIP, --httpServerIP HTTPSERVERIP
指定HTTP服务要监听在哪个IP地址上。
如需在所有网络接口上监听,请指定 "0.0.0.0" 。
-hp HTTPSERVERPORT, --httpServerPort HTTPSERVERPORT
指定HTTP服务要监听在哪个端口上。
默认的监听端口是 8189 (TCP)
邮件(IMAP)发送二维码设置:
(请阅读说明文件以了解如何通过邮件发送二维码,)
Expand Down
2 changes: 1 addition & 1 deletion qqbot/qrcodemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, conf):
conf.httpServerPort,
os.path.dirname(self.qrcodePath)
)
self.qrcodeURL = self.qrcodeServer.qrcodeURL
self.qrcodeURL = self.qrcodeServer.QrcodeURL(qrcodeId)
else:
self.qrcodeServer = None

Expand Down
41 changes: 24 additions & 17 deletions qqbot/qrcodeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,42 @@ def __init__(self, ip, port, tmpDir):
self.ip = ip
self.port = int(port)
self.tmpDir = os.path.abspath(tmpDir)
self.qrcodeURL = 'http://%s:%s/qqbot/qrcode' % (ip, port)

self.qrcodeURL = 'http://%s:%s/' % (ip, port)
StartDaemonThread(self.run)
time.sleep(0.5)
INFO('二维码 HTTP 服务器已在子线程中开启')

def QrcodeURL(self, qrcodeId):
return self.qrcodeURL + qrcodeId

def run(self):
# no-flask-info
logging.getLogger('werkzeug').setLevel(logging.ERROR)

app = flask.Flask(__name__)
app.route('/qqbot/qrcode')(self.route_qrcode)
app.route('/<qrcodeId>')(self.route_qrcode)
app.run(host=self.ip, port=self.port, debug=False)

def route_qrcode(self):
last, lastfile = 0, ''
for f in os.listdir(self.tmpDir):
if f.endswith('.png'):
p = os.path.join(self.tmpDir, f)
cur = os.path.getmtime(p)
if cur > last:
last = cur
lastfile = p

if lastfile:

def route_qrcode(self, qrcodeId):
lastfile = os.path.join(self.tmpDir, qrcodeId+'.png')
if os.path.exists(lastfile):
return flask.send_file(lastfile, mimetype='image/png')
else:
flask.abort(404)

# def route_qrcode(self):
# last, lastfile = 0, ''
# for f in os.listdir(self.tmpDir):
# if f.endswith('.png'):
# p = os.path.join(self.tmpDir, f)
# cur = os.path.getmtime(p)
# if cur > last:
# last = cur
# lastfile = p
#
# if lastfile:
# return flask.send_file(lastfile, mimetype='image/png')
# else:
# flask.abort(404)

if __name__ == '__main__':
QrcodeServer('127.0.0.1', 8189, '.')
while True:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

version = '2.2.5'
version = '2.2.6'

setup(
name = 'qqbot',
Expand Down

0 comments on commit 0466ca9

Please sign in to comment.