From 62189748c219ec1c056019daa6e431b9b3795668 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Sun, 14 Jun 2020 14:28:40 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=A2=9E=E5=BC=BA=E5=8A=9F=E8=83=BD]=20?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=B6=E4=BB=B6=E4=BA=BA=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=EF=BC=8C=E6=94=AF=E6=8C=81=E5=8D=8E=E5=AF=8C?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/util_wechat.py | 42 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/vnpy/trader/util_wechat.py b/vnpy/trader/util_wechat.py index 35ce28d5..b39368e8 100644 --- a/vnpy/trader/util_wechat.py +++ b/vnpy/trader/util_wechat.py @@ -14,12 +14,14 @@ import requests import sys import traceback from datetime import datetime - +from functools import wraps +from vnpy.trader.utility import print_dict global wechat_lock wechat_lock = Lock() -# 这里可以设置UID -UID = 'UID_kZguGPBQPWn41Ni9FK4CgPts2K' +# 这里可以设置UIDS, 多个人可同时接收 +UIDS = ['UID_kZguGPBQPWn41Ni9FK4CgPts2Kj'] + APP_TOKEN = 'AT_aDuiQu41dmAQV2vUMXOaaTDrWyhKJN2z' @@ -66,26 +68,52 @@ class wechat_thread(Thread): print("wechat_thread sent successful!") -def send_wx_msg(content='', uids=[], app_token=''): +def send_wx_msg(*args, **kwargs): """ 发送微信Msg :param content: 发送内容 - :return: """ + content = kwargs.get('content', None) + if content is None: + if len(args) == 0: + return + content = args[0] if len(content) == 0: return + try: + # 如果存在华富资产的微信模块,则使用 + from vnpy.trader.util_huafu import sendWeChatMsg, WECHAT_URL,WECHAT_GROUP, WECHAT_LEVEL_INFO, WECHAT_MSG_TYPE_ALERT + target=kwargs.get('target','XXX') + sendWeChatMsg(content=content, + target=WECHAT_GROUP.get(target), + url=kwargs.get('url', WECHAT_URL), + level=kwargs.get('level', WECHAT_LEVEL_INFO), + msg_type=kwargs.get('msg_type', WECHAT_MSG_TYPE_ALERT)) + return + except Exception as ex: + pass + + # dict => str, none str => str + if not isinstance(content, str): + if isinstance(content, dict): + content = '{}'.format(print_dict(content)) + else: + content = str(content) + + uids = kwargs.get('uids', []) # 没有配置的话,使用缺省UID if len(uids) == 0: - uids.append(UID) + uids.extend(UIDS) + + app_token = kwargs.get('app_token') t = wechat_thread(uids=uids, content=content, app_token=app_token) t.daemon = False # t.run() t.start() - if __name__ == '__main__': text = u'微信测试标题!!!!\n第二行'