From 8c8c5d379061bac8ca6d4f50ecfa232c6237c0bb Mon Sep 17 00:00:00 2001 From: msincenselee Date: Wed, 8 Apr 2020 17:08:22 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=A2=9E=E5=BC=BA]=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=8A=A8=E6=80=81app=5Ftoken,=E5=92=8C=E5=A4=9A=E4=BA=BA?= =?UTF-8?q?=E6=8E=A5=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/util_wechat.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/vnpy/trader/util_wechat.py b/vnpy/trader/util_wechat.py index 402974fd..35ce28d5 100644 --- a/vnpy/trader/util_wechat.py +++ b/vnpy/trader/util_wechat.py @@ -19,8 +19,8 @@ global wechat_lock wechat_lock = Lock() # 这里可以设置UID -UID = 'UID_kZguGPBQPWn41Ni9FK4CgPts2Kj' -APP_TOKEN = 'AT_aDuiQu41dmAQV2vUMXOaaTDrWyhKJN2' +UID = 'UID_kZguGPBQPWn41Ni9FK4CgPts2K' +APP_TOKEN = 'AT_aDuiQu41dmAQV2vUMXOaaTDrWyhKJN2z' class wechat_thread(Thread): @@ -28,28 +28,29 @@ class wechat_thread(Thread): 采用线程方式,不阻塞 """ - def __init__(self, uid: str, content: str, topic_ids: list = [], url: str = ''): + def __init__(self, uids: list, content: str, topic_ids: list = [], url: str = '', app_token=''): # text:消息标题,最长为256,必填。 # desp:消息内容,最长64Kb,可空,支持MarkDown。 super(wechat_thread, self).__init__(name="wechat_thread") self.request_url = "http://wxpusher.zjiecode.com/api/send/message" - self.uid = uid + self.uids = uids self.content = content self.topic_ids = topic_ids self.url = url self.lock = wechat_lock + self.app_token = app_token if len(app_token) > 0 else APP_TOKEN def run(self): if self.content is None or len(self.content) == 0: return params = {} - params['appToken'] = APP_TOKEN + params['appToken'] = self.app_token params['content'] = self.content params['contentType'] = 1 params['topicIds'] = self.topic_ids - params['uids'] = [self.uid] + params['uids'] = self.uids params['url'] = self.url # 发送请求 @@ -65,7 +66,7 @@ class wechat_thread(Thread): print("wechat_thread sent successful!") -def send_wx_msg(content=''): +def send_wx_msg(content='', uids=[], app_token=''): """ 发送微信Msg :param content: 发送内容 @@ -75,7 +76,11 @@ def send_wx_msg(content=''): if len(content) == 0: return - t = wechat_thread(uid=UID, content=content) + # 没有配置的话,使用缺省UID + if len(uids) == 0: + uids.append(UID) + + t = wechat_thread(uids=uids, content=content, app_token=app_token) t.daemon = False # t.run() t.start()