婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Python 京東云無線寶消息推送功能

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

熱門標簽:沈陽人工外呼系統價格 外呼系統哪些好辦 如何申請400電話費用 沈陽防封電銷卡品牌 武漢外呼系統平臺 沈陽外呼系統呼叫系統 江西省地圖標注 池州外呼調研線路 富錦商家地圖標注

配置文件

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

代碼

# 京東云無線路由寶推送
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=%stimestamp=%ssign=%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_pointsortDirection=DESCpageSize=15currentPage=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微信推送模板消息功能。分享給大家供大家參考,具體如下:

具體代碼如下:

#!/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' : 'https://www.jb51.net',#跳轉鏈接

"topcolor" : "#667F00",#顏色

"data" : {#模板內容

"first" : {"value" : "尊敬的710.so : 您的網站https://www.jb51.net (192.168.1.1) 有異常訪問", "color" : "#173177"},

"keyword1" : {"value" : "訪問時間 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)#推送消息請求

response = conn.getresponse()

data = response.read()#推送返回數據

if response.status == 200:

print 'success'

print data

else:

print 'fail'

conn.close()

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

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

您可能感興趣的文章:
  • python使用Word2Vec進行情感分析解析
  • Python實現購物評論文本情感分析操作【基于中文文本挖掘庫snownlp】
  • python snownlp情感分析簡易demo(分享)
  • python基于scrapy爬取京東筆記本電腦數據并進行簡單處理和分析
  • python pyppeteer 破解京東滑塊功能的代碼
  • Python實現京東搶秒殺功能
  • Python之京東商品秒殺的實現示例
  • python 爬蟲爬取京東ps4售賣情況
  • Python基于BeautifulSoup爬取京東商品信息
  • 使用 Python 在京東上搶口罩的思路詳解
  • 利用python Selenium實現自動登陸京東簽到領金幣功能
  • 基于Python+Appium實現京東雙十一自動領金幣功能
  • python 爬取京東指定商品評論并進行情感分析

標簽:黑龍江 呂梁 潛江 阿里 銅川 常德 通遼 株洲

巨人網絡通訊聲明:本文標題《Python 京東云無線寶消息推送功能》,本文關鍵詞  Python,京東,云,無線,寶,消息,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Python 京東云無線寶消息推送功能》相關的同類信息!
  • 本頁收集關于Python 京東云無線寶消息推送功能的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 南安市| 宝坻区| 德钦县| 分宜县| 临澧县| 浦北县| 南京市| 尚志市| 泗洪县| 固始县| 海原县| 泌阳县| 沙洋县| 佛教| 岚皋县| 泸溪县| 寻甸| 乾安县| 河源市| 论坛| 普洱| 巴楚县| 类乌齐县| 蒙山县| 华亭县| 饶阳县| 渭南市| 华坪县| 玉门市| 霍山县| 开原市| 比如县| 寿阳县| 绥阳县| 环江| 晋城| 翁牛特旗| 临澧县| 麻阳| 揭阳市| 许昌县|