python微信自动群发脚本_python 微信批量发送消息脚本

python微信自动群发脚本_python 微信批量发送消息脚本通过python利用微信公众号,批量发送消息但是,因为免费的,一天一个用户,只能发90条消息。。。可以用于zabbix啊,。等监控#!/usr/bin/envpython#-*-coding:utf-8-*-importurllib2importsysimportsimplejsonasjsonreload(sys)sys.setdefaultencoding(“utf-8…

大家好,又见面了,我是你们的朋友全栈君。

通过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)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/135969.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号