一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python 京東云無線寶消息推送功能

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

2021-11-08 10:40Alex_Mercer Python

這篇文章主要介紹了Python 京東云無線寶消息推送功能,發送釘釘消息獲取可用積分,詳細配置文件通過實例代碼給大家講解的很詳細,代碼+注釋講解的很詳細,需要的朋友可以參考下

配置文件

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

代碼

?
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
# 京東云無線路由寶推送
import requests
import json
import time
import hmac
import hashlib
import base64
import urllib.parse
from datetime import datetime
# 發送釘釘消息
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)  #你的機器人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
# 發送京東路由寶日報
def send_jd_router(wskey):
    dic=get_jd_detail(wskey)
    msg='# 京東路由寶日報\n'
    msg+='## %s \n' %(dic['todayDate'])
    msg+=('> 今日獲取總積分為**%d**分,對應金錢為 **%.2f**元\n' %(dic['total_today_point'],float(dic['total_today_point'])/100))
    for item in dic['items']:
        msg+=('>> 設備**%s** \n' %(item['mac']))
        msg+=('>>> 今日獲取積分為**%s**分,對應金錢為 **%.2f**元 \n\n' %(item['todayPointIncome'],float(item['todayPointIncome'])/100))
    msg+=('> 累計總積分為 **%s** 分,對應金錢 **%.2f** 元 \n\n' %(dic['total_all_point'],float(dic['total_all_point'])/100))
    dic=get_jd_total_avail_point(wskey)
    msg+=('> 目前可用積分為 **%s** 分,對應金錢 **%.2f** 元' %(dic['totalAvailPoint'],float(dic['totalAvailPoint'])/100))
 
    # token=""
    # secret=""
    # data = {
    #     "msgtype": "markdown",
    #     "markdown": {
    #         "title":"京東云路由寶日報",
    #         "text": msg
    #         },
    # }
    # sendinfo_ding(token,secret,data)
    
    # 更改server醬發送
    server_send_wechat('京東路由寶日報',msg)
 
#Server醬發送微信
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)
 
# 更改為配置文件獲取 todo
wskey=''
while True:
    now = datetime.now()
    print("任務執行的時間為:"+datetime.strftime(now,"%Y-%m-%d:%H:%M:%S"))
    if now.hour==8 and now.minute==0:
        send_jd_router(wskey)
    time.sleep(60)

知識點擴展:Python編程之微信推送模板消息功能示例

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

具體代碼如下:

?
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
#!/usr/bin/env python
 
#-*- coding: utf-8 -*-
 
import httplib
 
import json
 
import MySQLdb
 
#從數據庫中獲取access_token
 
access_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])
 
#根據接口推送消息
 
if not access_token is None:
 
conn = httplib.HTTPConnection("api.weixin.qq.com:80")#微信接口鏈接
 
headers = {"Content-type":"application/json"} #application/x-www-form-urlencoded
 
params = ({'touser' : "oEGZ4johnKOtayJbnEVeuaZr6zQ0",#用戶openid
 
'template_id' : 'AtFuydv8k_15UGZuFntaBzJRCsHCkjNm1dcWD3A-11Y',#模板消息ID
 
'url' : 'http://m.ythuaji.com.cn',#跳轉鏈接
 
"topcolor" : "#667F00",#顏色
 
"data" : {#模板內容
 
"first" : {"value" : "尊敬的710.so : 您的網站http://m.ythuaji.com.cn (192.168.1.1) 有異常訪問", "color" : "#173177"},
 
"keyword1" : {"value" : "訪問時間 2015-04-05 15:30:59 訪問IP 192.168.1.2", "color" : "#173177"},
 
"keyword2" : {"value" : "訪問鏈接 http://m.ythuaji.com.cn", "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)#推送消息請求
 
response = conn.getresponse()
 
data = response.read()#推送返回數據
 
if response.status == 200:
 
print 'success'
 
print data
 
else:
 
print 'fail'
 
conn.close()

希望本文所述對大家Python程序設計有所幫助。

以上就是Python 京東云無線寶消息推送的詳細內容,更多關于Python 京東云無線寶推送的資料請關注服務器之家其它相關文章!

原文鏈接:https://www.cnblogs.com/Alex-Mercer/p/14429647.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 操儿子 | 韩国甜性涩爱免费观看 | 青草视频在线观看免费网站 | 精品小视频在线 | 欧美18~20性hd | 男人叼女人的痛爽视频免费 | 99这里只有精品视频 | 欧美精品久久一区二区三区 | 久久黄视频 | 火影忍者羞羞 | 大杳蕉在线影院在线播放 | 女性全身裸露无遮挡 | 国产福利兔女郎在线观看 | 国产高清国内精品福利 | 古代色翁荡熄 | 日韩 国产 欧美 精品 在线 | 国产手机在线αⅴ片无码观看 | 大胆人gogo888体艺术在线 | 亚拍一区 | 国产亚洲女人久久久久久 | 我要色色网 | 国产资源免费 | 性姿势女人嗷嗷叫图片 | jk制服白丝超短裙流白浆 | 久久精品国产亚洲AV热无遮挡 | 男人资源站 | 国产欧美日韩亚洲精品区2345 | 成年人在线视频免费观看 | 四虎影院在线免费 | 天天做日日做天天添天天欢公交车 | 国产成人亚洲综合a∨婷婷 国产成人亚洲精品乱码在线观看 | 午夜福利08550 | xnxx动漫| 九九九精品视频 | 亚洲入口 | 日韩欧美a| 美女靠逼免费网站 | 91久久偷偷做嫩草影院电 | 99久久久久国产精品免费 | 亚洲AV久久久久久久无码 | 欧美午夜精品久久久久久黑人 |