国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

Python 京東云無線寶消息推送功能

瀏覽:3日期:2022-06-19 08:45:47
配置文件

注釋里面有寫,懶得用配置文件了

代碼

# 京東云無線路由寶推送import requestsimport jsonimport timeimport hmacimport hashlibimport base64import urllib.parsefrom datetime import datetime# 發(fā)送釘釘消息def sendinfo_ding(token,secret,data): dic=get_timestamp_and_sign_by_secret(secret) timestamp=dic[’timestamp’] sign=dic[’sign’] url = ’https://oapi.dingtalk.com/robot/send?access_token=%s&timestamp=%s&sign=%s’ %(token,timestamp,sign) #你的機(jī)器人webhook地址 headers = {’Content-Type’: ’application/json’} f = requests.post(url, data=json.dumps(data), headers=headers)# 獲取密簽def get_timestamp_and_sign_by_secret(secret): timestamp = str(round(time.time() * 1000)) secret_enc = secret.encode(’utf-8’) string_to_sign = ’{}n{}’.format(timestamp, secret) string_to_sign_enc = string_to_sign.encode(’utf-8’) hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) return {'timestamp':timestamp,'sign':sign}# 獲取可用積分def get_jd_total_avail_point(wskey): url=’https://router-app-api.jdcloud.com/v1/regions/cn-north-1/pinTotalAvailPoint’ headers = {’Content-Type’: ’application/json’,’wskey’:wskey} rsp=requests.get(url,headers=headers) data=(json.loads(rsp.text)[’result’][’totalAvailPoint’]) return {’totalAvailPoint’:data}# 獲取積分詳情def get_jd_detail(wskey): url=’https://router-app-api.jdcloud.com/v1/regions/cn-north-1/todayPointDetail?sortField=today_point&sortDirection=DESC&pageSize=15&currentPage=1’ headers = {’Content-Type’: ’application/json’,’wskey’:wskey} rsp=requests.get(url,headers=headers) data=(json.loads(rsp.text)[’result’]) items=data[’pointInfos’] total_today_point=0 total_all_point=0 dic={} dic[’todayDate’]=data[’todayDate’] dic[’items’]=[] for item in items:mac=item[’mac’]today_point=item[’todayPointIncome’]all_point=item[’allPointIncome’]total_today_point+=int(today_point)total_all_point+=int(all_point)dic[’items’].append(item) dic[’total_today_point’]=total_today_point dic[’total_all_point’]=total_all_point return dic# 發(fā)送京東路由寶日?qǐng)?bào)def send_jd_router(wskey): dic=get_jd_detail(wskey) msg=’# 京東路由寶日?qǐng)?bào)n’ msg+=’## %s n’ %(dic[’todayDate’]) msg+=(’> 今日獲取總積分為**%d**分,對(duì)應(yīng)金錢為 **%.2f**元n’ %(dic[’total_today_point’],float(dic[’total_today_point’])/100)) for item in dic[’items’]:msg+=(’>> 設(shè)備**%s** n’ %(item[’mac’]))msg+=(’>>> 今日獲取積分為**%s**分,對(duì)應(yīng)金錢為 **%.2f**元 nn’ %(item[’todayPointIncome’],float(item[’todayPointIncome’])/100)) msg+=(’> 累計(jì)總積分為 **%s** 分,對(duì)應(yīng)金錢 **%.2f** 元 nn’ %(dic[’total_all_point’],float(dic[’total_all_point’])/100)) dic=get_jd_total_avail_point(wskey) msg+=(’> 目前可用積分為 **%s** 分,對(duì)應(yīng)金錢 **%.2f** 元’ %(dic[’totalAvailPoint’],float(dic[’totalAvailPoint’])/100)) # token='' # secret='' # data = { # 'msgtype': 'markdown', # 'markdown': { # 'title':'京東云路由寶日?qǐng)?bào)', # 'text': msg # }, # } # sendinfo_ding(token,secret,data)# 更改server醬發(fā)送 server_send_wechat(’京東路由寶日?qǐng)?bào)’,msg)#Server醬發(fā)送微信def server_send_wechat(text,desp=’’): # Server醬 Key key=’’ url=(’https://sc.ftqq.com/%s.send’ %key) params={’text’:text,’desp’:desp } requests.get(url,params)# 更改為配置文件獲取 todowskey=’’while True: now = datetime.now() print('任務(wù)執(zhí)行的時(shí)間為:'+datetime.strftime(now,'%Y-%m-%d:%H:%M:%S')) if now.hour==8 and now.minute==0:send_jd_router(wskey) time.sleep(60)

知識(shí)點(diǎn)擴(kuò)展:Python編程之微信推送模板消息功能示例

本文實(shí)例講述了Python微信推送模板消息功能。分享給大家供大家參考,具體如下:

具體代碼如下:

#!/usr/bin/env python#-*- coding: utf-8 -*-import httplibimport jsonimport MySQLdb#從數(shù)據(jù)庫中獲取access_tokenaccess_token=''try:conn=MySQLdb.connect(host=’192.168.1.1’,user=’root’,passwd=’root’,db=’db_weixin’,port=3306)cur=conn.cursor()cur.execute(’select access_token from weixin_public’)result=cur.fetchone()#print result#print result[0]access_token=result[0]cur.close()conn.close()except MySQLdb.Error,e:print 'Mysql Error %d: %s' % (e.args[0], e.args[1])#根據(jù)接口推送消息if not access_token is None:conn = httplib.HTTPConnection('api.weixin.qq.com:80')#微信接口鏈接headers = {'Content-type':'application/json'} #application/x-www-form-urlencodedparams = ({’touser’ : 'oEGZ4johnKOtayJbnEVeuaZr6zQ0',#用戶openid’template_id’ : ’AtFuydv8k_15UGZuFntaBzJRCsHCkjNm1dcWD3A-11Y’,#模板消息ID’url’ : ’https://www.jb51.net’,#跳轉(zhuǎn)鏈接'topcolor' : '#667F00',#顏色'data' : {#模板內(nèi)容'first' : {'value' : '尊敬的710.so : 您的網(wǎng)站https://www.jb51.net (192.168.1.1) 有異常訪問', 'color' : '#173177'},'keyword1' : {'value' : '訪問時(shí)間 2015-04-05 15:30:59 訪問IP 192.168.1.2', 'color' : '#173177'},'keyword2' : {'value' : '訪問鏈接 https://www.jb51.net', 'color' : '#173177'},'remark' : {'value' : '訪問頻率 10/s', 'color' : '#173177'}}})conn.request('POST', '/cgi-bin/message/template/send?access_token='+access_token, json.JSONEncoder().encode(params), headers)#推送消息請(qǐng)求response = conn.getresponse()data = response.read()#推送返回?cái)?shù)據(jù)if response.status == 200:print ’success’print dataelse:print ’fail’conn.close()

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

以上就是Python 京東云無線寶消息推送的詳細(xì)內(nèi)容,更多關(guān)于Python 京東云無線寶推送的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: 京東 Python
相關(guān)文章:
主站蜘蛛池模板: 欧美成人极品怡红院tv | 一区二区三区亚洲视频 | 成人午夜在线视频 | 日本免费特黄aa毛片 | 草草视频手机在线观看视频 | 欧美人成在线观看ccc36 | 亚洲欧美日韩在线播放 | 精品久久国产 | 国产成人免费在线观看 | 成年人免费软件 | 综合激情网站 | 国产伦精品一区二区三区免费 | 国产成人综合日韩精品无 | 九九99re在线视频精品免费 | 亚洲一区二区三区四区在线 | 久久国产精品免费视频 | 高清韩国a级特黄毛片 | 鸥美性生交xxxxx久久久 | 免费国产成人午夜在线观看 | 亚洲欧美日韩国产 | 免费一看一级毛片全播放 | 国产精品三级手机在线观看 | 欧美在线视频精品 | 美女黄色在线看 | 一区二区三区成人 | 国产一区二区三区日韩欧美 | 国产va免费精品高清在线观看 | 在线看片a| 久久亚洲不卡一区二区 | 男人使劲躁女人视频小v | 成人久久视频 | 久久久青草 | 国产成人久久精品区一区二区 | 日本视频在线免费观看 | 亚洲欧美国产中文 | 久久国产精品久久精品国产 | 亚洲免费一区 | 国产com| 午夜黄色毛片 | 完全免费在线视频 | 久久 精品 一区二区 |