In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you how Python to achieve JD.com cloud wireless treasure message push function of the relevant knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.
Configuration file
It's written in the comments, so I don't bother to use the configuration file.
Code
# Jingdong Cloud wired Yubao push import requestsimport jsonimport timeimport hmacimport hashlibimport base64import urllib.parsefrom datetime import datetime# to send nail message 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×tamp=%s&sign=%s'% (token,timestamp) Sign) # your robot webhook address headers= {'Content-Type':' application/json'} f = requests.post (url, data=json.dumps (data), headers=headers) # get the secret signature def get_timestamp_and_sign_by_secret (secret): timestamp = str (round (time.time () * 1000)) secret_enc = secret.encode ('utf-8') string_to_sign =' {} {} '.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} # get the available integral 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} # get points details 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¤tPage=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# send def send_jd_router (wskey): dic=get_jd_detail (wskey) msg='# Jingdong Road Youbao Daily' msg+='# #% s'% (dic ['todayDate']) msg+= (' > Today got a total score of * *% dudes * The corresponding money is * *% .2f * * yuan'% (dic ['total_today_point'], float (dic [' total_today_point']) / 100) for item in dic ['items']: msg+= (' > equipment * *% slots *% (item ['mac'])) msg+= (' > > Today gets points of * *% slots *) The corresponding money is * *% .2f * * yuan'% (item ['todayPointIncome'], float (item [' todayPointIncome']) / 100) msg+= ('> cumulative total score is * *% slots *, corresponding to money *% .2f * yuan'% (dic ['total_all_point']) Float (dic ['total_all_point'])) dic=get_jd_total_avail_point (wskey) msg+= (' > currently available credits * *% slots *, corresponding money * .2fen * yuan'% (dic ['totalAvailPoint'], float (dic [' totalAvailPoint']) / 100) # token= "# secret="# data = {#" msgtype ":" markdown " # "markdown": {# "title": "JD.com Yunlubao Daily", # "text": msg #}, #} # sendinfo_ding (token,secret,data) # change server_send_wechat ('Jingdong Road Youbao Daily', msg) # Server paste sends Wechat 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) # change to the configuration file to get todowskey=''while True: now = datetime.now () print ("time the task executes:" + datetime.strftime (now) "% Y-%m-%d:%H:%M:%S") if now.hour==8 and now.minute==0: send_jd_router (wskey) time.sleep (60) are all the contents of the article "how Python implements the message push function of JD.com Cloud Wireless Bao" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.