In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces Python how to achieve Wechat push template message function related knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that after reading this Python how to achieve Wechat push template message function article will have a harvest, let's take a look.
The specific code is as follows:
#! / usr/bin/env python#-*- coding: utf-8-*-import httplibimport jsonimport MySQLdb# gets 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 from the database E:print "Mysql Error% d:% s"% (e.args [0], e.args [1]) # push message based on the interface if not access_token is None:conn = httplib.HTTPConnection ("api.weixin.qq.com:80") # Wechat interface link headers = {"Content-type": "application/json"} # application/x-www-form-urlencodedparams = ({'touser': "oEGZ4johnKOtayJbnEVeuaZr6zQ0", # user openid'template_id':' AtFuydv8k_15UGZuFntaBzJRCsHCkjNm1dcWD3A-11Y' # template message ID'url': 'https://www.jb51.net',# jump link "topcolor": "# 667F00", # color "data": {# template content "first": {"value": "Dear 710.so: your website https://www.jb51.net (192.168.1.1) has abnormal access", "color": "# 173177"} "keyword1": {"value": "access time 2015-04-05 15:30:59 visit IP 192.168.1.2", "color": "# 173177"}, "keyword2": {"value": "access link https://www.jb51.net"," color ":" # 173177 "}," remark ": {" value ":" access frequency 10ppm " "color": "# 173177"}) conn.request ("POST", "/ cgi-bin/message/template/send?access_token=" + access_token, json.JSONEncoder () .encode (params) Headers) # push message request response = conn.getresponse () data = response.read () # push return data if response.status = = 200:print 'success'print dataelse:print' fail'conn.close () this is the end of the article on "how Python implements the Wechat push template message function" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve Wechat push template message function by Python". If you want to learn more knowledge, you are welcome to follow 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.