[增强功能] 微信收件人支持多个,支持华富微信插件
This commit is contained in:
parent
f159b61057
commit
62189748c2
@ -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第二行'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user