python微信自动群发脚本_python 微信批量发送消息脚本
大家好,又见面了,我是你们的朋友全栈君。
但是,因为免费的,一天一个用户,只能发90条消息。。。
可以用于zabbix啊,。等监控
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import sys
import simplejson as json
reload(sys)
sys.setdefaultencoding( “utf-8” )
class weChat:
def __init__(self, url, Corpid, Secret):
url = ‘%s/cgi-bin/gettoken?corpid=%s&corpsecret=%s’ % (url, Corpid, Secret)
res = self.url_req(url)
self.token = res[‘access_token’]
print self.token
def url_req(self, url, method=’get’, data={}):
if method == ‘get’:
req = urllib2.Request(url)
res = json.loads(urllib2.urlopen(req).read())
elif method == ‘post’:
req = urllib2.Request(url, data)
res = json.loads(urllib2.urlopen(req).read())
else:
print ‘error request method…exit’
sys.exit()
return res
def send_message(self, userlist, content, agentid=0):
self.userlist = userlist
self.content = content
url = ‘https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s’ % self.token
data = {
“touser”: “”,
“toparty”: “”,
“totag”: “2”,
“msgtype”: “text”,
“agentid”: “1”,
“text”: {
“content”: “”
},
“safe”: “0”
}
data[‘touser’] = (‘|’).join(userlist)
data[‘agentid’] = agentid
data[‘text’][‘content’] = content
print data
data = json.dumps(data, ensure_ascii=False)
res = self.url_req(url, method=’post’, data=data)
if res[‘errmsg’] == ‘ok’:
print ‘send sucessed!!!’
else:
print ‘send failed!!’
print res
if __name__ == ‘__main__’:
userlist = [‘zhangmingyang888′,’augafox’,’wopost’] #用户列表
content = [u’世界你好’] #消息
content = ‘\n’.join(content)
Corpid = ‘wxaf10ef009f47e’
Secret = ‘KhKHccubGob66d40EWmi_GSwSL1aA-CdY8_66kNeSXl9tD3u8kZ91tBG6h6lsghQ’
url = ‘https://qyapi.weixin.qq.com’
wechat = weChat(url, Corpid, Secret)
wechat.send_message(userlist, content)
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/135969.html原文链接:https://javaforall.cn
相关文章
- 用Python写一个百度POST实时推送工具
- python skitlearn_Python sklearn
- 2021年国庆你的朋友去哪浪了?让Python告诉你!
- 用Python画一棵带音乐的雪夜圣诞树
- 如何查看python源码_python判断路径是否存在
- python ZipFile: output zip file,ByteIO
- python操作excel
- Python进阶39-drf框架(一)
- Python 模板渲染库 yaml 和 jinja2 的实战经验分享
- 最强最炫的Python数据可视化神器,没有之一!
- 【水水水文章】用 Python 发邮件
- 20张高清数据分析(Python)全知识地图,强烈建议收藏
- Python进阶41-drf框架(三)
- 2022春节贺岁档电影开分,水门桥不理想,四海崩了!用Python一探究竟
- maven找不到包但是确实引入了_idea写python好吗
- python break和continue
- Anaconda 查看、创建、管理和使用python环境
- 心情不好的时候,用 Python 画棵樱花树送给自己吧「建议收藏」
- Python 树表查找_千树万树梨花开,忽如一夜春风来(二叉排序树、平衡二叉树)
- 记一次python清洗疫情历史数据