-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxStart.py
211 lines (188 loc) · 8.15 KB
/
wxStart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/python
# -*- coding: utf-8 -*-
# import urllib2
from urllib import request, parse
import json
import time
import os
# from sosobtcUtil import SosobtcUtil
# from confUtil import ConfUtil
from fileReadUtil import FileReadUtil
appid = 'wx5d2607e7bf434326'
secrect = '6a005490e16bae05e256e06ebf3118db'
class WxStart():
def __init__(self):
self.appid = appid
self.secrect = secrect
# 获取accessToken
def getToken(self):
# 判断缓存
url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + self.appid + "&secret=" + self.secrect
# #print "getToken:url----->%s" % url
f = request.urlopen(url)
s = f.read()
# 读取json数据
j = json.loads(s)
j.keys()
if j.get("errcode", None):
#print (u"错误信息 >>> >>> %s" % j['errmsg']).encode('utf-8')
return
token = j['access_token']
return token
# 开始推送
def do_push(self, touser, template_id, url, data, topcolor):
if topcolor.strip() == '':
topcolor = "#7B68EE"
dict_arr = {'touser': touser, 'template_id': template_id,
'url': url, 'topcolor': topcolor, 'data': data}
json_template = json.dumps(dict_arr)
token = self.getToken()
if not token:
return
requst_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token
content = self.post_data(requst_url, json_template)
# 读取json数据
j = json.loads(content)
j.keys()
errcode = j['errcode']
errmsg = j['errmsg']
return errmsg
# 模拟post请求
def post_data(self, url, para_dct):
# para_data = para_dct
# f = urllib2.urlopen(url, para_data)
# content = f.read()
# return content
data = parse.urlencode(para_dct)
req = request.urlopen(url, data=data) # POST方法
# req = request.Request(url+params) # GET方法
page = req.read()
page = page.decode('utf-8')
print(page)
def sendSms(self, uname, send_str, color='#173177'):
#
dt = {
"data": {
"value": u"zec:云币网-海枫藤=3",
"color": u"#173177"
}
}
dt["data"]["value"] = send_str
dt["data"]["color"] = color
self.do_push(wx_no_info[uname], wx_data_template, '', dt, '')
return
# 微信号
wx_no_info = {'tq': 'oXRWit3M9MdVfN-bZWMTDmj967rg',
'wh': 'oXRWit0yPlhz3wvuGeANPpk3HPeY',
'zj': 'oXRWit3A7CsuaZzxcrTTmCqb7i_E',
'tt': 'oXRWit9hAtbxjXPoL1xsqkzN0NFg',
'lzj': 'oXRWitzuVn8IaniAHnBcsC9n9HAI',
'gpc': 'oXRWitytNLTHGOZ92pUgA_Jj8xLM',
'wm': 'oXRWit9ASFPGBZCfFwLTU2qZZJNc',
}
# 微信数据模板
wx_data_template = 'wJNUcKu8nELKYyIJmy-pqI3F3GZW9OXOsmcO85fWftk'
#
coins = ("zec", "eth", "etc", "etp", "btc", "bts","eos", "ven", "qtum")
# users = ("tq","zj","tt","lzj","gpc","wm")
users = ("tq","zj","tt",)
if __name__ == '__main__':
thi = WxStart()
thi.sendSms("tq", "123456")
# coins_info = SosobtcUtil(0.05, 0.05).getCoinInfo(coins)
# #print "\nzec----->%.2f---->%s" % (coins_info['zec']['soso_offv'], coins_info['zec']['notify_str'])
# #print "eth----->%.2f---->%s" % (coins_info['eth']['soso_offv'], coins_info['eth']['notify_str'])
# #print "etc----->%.2f---->%s" % (coins_info['etc']['soso_offv'], coins_info['etc']['notify_str'])
#
#
# conf_path = os.path.split(os.path.realpath(__file__))[0] + "/conf/"
# coufUtil = ConfUtil(conf_path)
# users_info = coufUtil.getUserConf(users, coins)
# # #print "---->%s" % (users_info['tq']['zec']['logic'])
#
# #差价预警
# for user in users:
# # 是否发送通知
# send_flag = 0
# # 发送通知内容
# send_str = u""
# for coin in coins:
# # #print "%s-------------->%s" % (coin, coins_info[coin]['notify_str'])
# #差价
# if users_info.has_key(user) and users_info[user].has_key(coin):
# # #print u"%s----%s---->%s %s " % (user, coin, users_info[user][coin]['max_off'], users_info[user][coin]['min_off'])
# if users_info[user][coin]['notify'] == '1':
# yunbi = float(coins_info[coin]['yunbi'])
# szzc = float(coins_info[coin]['szzc'])
# soso_offv = float(coins_info[coin]['soso_offv'])
# notify_str = coins_info[coin]['notify_str']
# # 差价
# max_off_str = users_info[user][coin]['max_off']
# min_off_str = users_info[user][coin]['min_off']
# max_off = 0.0
# min_off = 0.0
# if max_off_str != 'None' :
# max_off = float(max_off_str)
# if min_off_str != 'None' :
# min_off = float(min_off_str)
# # 市价
# max_val_str = users_info[user][coin]['max_val']
# min_val_str = users_info[user][coin]['min_val']
# max_val = 0.0
# min_val = 0.0
# if max_val_str != 'None' :
# max_val = float(max_val_str)
# if min_val_str != 'None' :
# min_val = float(min_val_str)
#
# # #print (u"%s差价:%s(soso_offv) | %s(notify_str) | %s(max_off) | %s(min_off)" % (coin, soso_offv, notify_str, max_off_str, min_off_str)).encode('utf-8')
# # #print (u"%s市价:%s(yunbi) | %s(szzc) | %s(max_val) | %s(min_val)" % (coin, yunbi, szzc, max_val_str, min_val_str)).encode('utf-8')
# # 差价
# if min_off_str != 'None' and soso_offv > min_off:
# send_flag = 1
# send_str = u"%s差价:%s > %s\r\n" % (send_str, notify_str, min_off_str)
# if max_off_str != 'None' and soso_offv < max_off:
# send_flag = 1
# send_str = u"%s差价:%s < %s\r\n" % (send_str, notify_str, max_off_str)
# #市价
# if min_val > 0 :
# if yunbi > min_val :
# send_flag = 1
# send_str = u"%s%s市价:yunbi:%s > %s\r\n" % (send_str, coin, str(yunbi), min_val_str)
# if szzc > min_val :
# send_flag = 1
# send_str = u"%s%s市价:szzc:%s > %s\r\n" % (send_str, coin, str(szzc), min_val_str)
#
# if max_val > 0 :
# if yunbi > 0 and yunbi < max_val :
# send_flag = 1
# send_str = u"%s%s市价:yunbi:%s < %s\r\n" % (send_str, coin, str(yunbi), max_val_str)
# if szzc > 0 and szzc < max_val :
# send_flag = 1
# send_str = u"%s%s市价:szzc:%s < %s\r\n" % (send_str, coin, str(szzc), max_val_str)
#
# #频率限制
# if send_flag == 1:
# if user != 'tq' :
# sms_count = coufUtil.getNotifyCount(user)
# if sms_count >= 2 :
# send_flag = 0
# #print (u"%s 频率限制----> %d 次/小时" % (user, sms_count)).encode('utf-8')
#
# # 微信通知
# # #print u"000---->%s " % send_flag
# if send_flag == 1:
# #print (u"满足价格要求,通知%s---->%s" % (user, send_str)).encode('utf-8')
# thi.sendSms(user, send_str)
# if not off :
# #print u"价格不符合要求,退出!"
# else :
# #价格符合通知要求,进一步判断是否要微信通知
# f = FileReadUtil("/Users/app/Documents/zcash/porter/last_wx_send_record.txt", 1000, 0.5*60*60)
# flag = f.needSms()
# f._file.close()
# #print "flag------->", flag
# if flag :
# #微信通知
# dt["data"]["value"]=off
# s.sendSms(dt)