Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python calls mongodb to send Wechat Enterprise account.

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Python2.x Note: in the data variable, agent_id is the target department for the newly created application id (which can be seen on the web page), or you can use touser,totag to specify a relatively simple call to the target account, which has been tested and can be used. # coding:utf-8import sysimport requestsimport jsonfrom pymongo import MongoClientreload (sys) sys.setdefaultencoding ('utf-8') class Weixin (object): def _ _ init__ (self, corp_id, corp_secret): self.token_url =' https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s'% (corp_id) Corp_secret) self.send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' def get_token (self): try: r = requests.get (self.token_url) Timeout=10) except Exception as e: print e sys.exit (1) if r.status_code = = requests.codes.ok: data = r.json () if data.get ('errcode'): print data [' errmsg'] sys.exit (1) return data ['access_token'] Else: print r.status_code sys.exit (1) def send (self Message): url = self.send_url + self.get_token () data = {"touser": "hequan2011", "msgtype": "text", "agentid": "0", "text": {"content": message} "safe": "0"} send_data = json.dumps (data,ensure_ascii=False) try: r = requests.post (url, send_data) except Exception E: print e sys.exit (1) if r.status_code = = requests.codes.ok: print r.json () else: print r.code sys.exit (1) corpid = 'xxxxxxxxxxx'corpsecret =' xxxxxxxxxxxxxxxxx'client = MongoClient ('mongodb://user:password@127.0.0.1: 27017 data') db = client.kucollection = db.biaoa = [] for data in collection.find (): a.append (data) l = a [0] g = lz = str (g ["name"]) Z1 = int (g ["jg"]) print zmsg = "1: {0}\ n 2: {1}\ n" .format (z Z1) w = Weixin (corpid,corpsecret) w.send (msg)

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report