python3发微信脚本
企业微信发微信脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#GuoYabin import requests,json,sys,imp
imp.reload(sys) class WeChat(object): def __init__(self):
self.url='https://qyapi.weixin.qq.com/cgi-bin/gettoken'
self.corpid = '你的企业微信corpid'
self.corpsecret = '你的企业微信corpsecret ' def auth(self):
params={'corpid':self.corpid,'corpsecret':self.corpsecret}
try:
rs=requests.get(self.url,params=params)
return(rs.json()['access_token'])
rs.close()
except:
print('get access_token error!') def getToken(self):
try:
file=open('token.txt','r')
token=file.read()
file.close()
except:
token=self.auth()
file=open('token.txt','w')
file.write(token)
file.close()
return(token) def message(self,touser,message):
data=json.dumps({
'touser':touser,
'toparty':'2',
'msgtype':'text',
'agentid':'1',
'text':{
'content':message},
'safe':'0'
},ensure_ascii=True)
return(data) def send(self,touser,message):
try:
url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='+self.getToken()
res=requests.post(url,data=self.message(touser,message))
print(res.json())
res.close()
except:
print('send error!') if __name__ == '__main__':
weixin=WeChat()
weixin.send(sys.argv[1],sys.argv[3])
python3发微信脚本的更多相关文章
- python3发邮件脚本
官方文档中建议保存token,且token是每2小时更新一次. 所以token先保存在本地token.txt文件夹中,设定计划任务每1小时删除一下token.txt.虽然造成了浪费,对于发消息不多的人 ...
- python2发微信脚本
#!/usr/bin/env python # -*- coding: utf-8 -*- import urllib,urllib2,json import sys reload(sys) sys. ...
- SQL Server定时自动抓取耗时SQL并归档数据发邮件脚本分享
SQL Server定时自动抓取耗时SQL并归档数据发邮件脚本分享 第一步建库和建表 USE [master] GO CREATE DATABASE [MonitorElapsedHighSQL] G ...
- 【福利将至】iPhone用户可用Siri发微信了
北京时间6月14日,苹果WWDC16开发者大会召开.继2015年3月份春季发布会和9月份的秋季新品发布会,苹果和腾讯联手Apple Watch版微信和微信3DTouch功能之后,双方在今年的WWDC上 ...
- Python3 itchat微信获取好友、公众号、群聊的基础信息
Python3 itchat微信获取好友.公众号.群聊的基础信息 一.简介 安装 itchat pip install itchat 使用个人微信的过程当中主要有三种账号需要获取,分别为: 好友 公众 ...
- 小程序发微信红包后端Nodejs实现
前提条件 1.有一个微信开放平台 https://open.weixin.qq.com/ 2.有一个微信公众平台 https://mp.weixin.qq.com 并且开通微信支付 3.有一个微信小 ...
- python爬虫彩票案例,并自动发微信
import requests from bs4 import BeautifulSoup import itchat import time,datetime all = [{1, 2, 3, 7, ...
- 用Node+wechaty写一个爬虫脚本每天定时给女(男)朋友发微信暖心话
wechatBot 微信每日说,每日自动发送微信消息给你心爱的人 项目介绍 灵感来源 在掘金看到了一篇<用Node + EJS写一个爬虫脚本每天定时女朋友发一封暖心邮件>后, 在评论区偶然 ...
- Python3.5 执行发邮件脚本失败【惑】==>【搞定】
Python发邮件的代码如下: 只需要填写好加粗字体,即可正常使用. from exchangelib import DELEGATE, Account, Credentials, Message, ...
随机推荐
- Web开发之Servlet
当一个请求到达服务端,服务器怎么处理? 当一个请求到达服务端时,由服务端的引擎来进行分析.它根据工程名找到工程, 然后拿到URL的资源地址和web.XML文件的所有的进行对比,和哪一个对比上就找到了具 ...
- MRCTF2020 你传你🐎呢
MRCTF2020 你传你 .htaccess mime检测 1.先尝试上传了一个文件,发现.jpg后缀的可以上传成功,但是用蚁剑连接时返回空数据 2.重新先上传一个.htaccess文件,让需要被上 ...
- 【刷题-LeetCode】238. Product of Array Except Self
Product of Array Except Self Given an array nums of n integers where n > 1, return an array outpu ...
- 【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- VictoriaMetrics:使用vmctl来实现vm-storage向victoria-metrics-prod(单机版)迁移数据
前一篇提到了,vm-storage的备份数据,无法被victoria-metrics-prod(单机版)读取. 继续翻文档发现vmctl可以实现这个效果: 1.启动vm-restore恢复数据 vmr ...
- android ndk下没有pthread_yield,好在std::this_thread::yield()可以达到同样的效果
一个多线程的算法中,发现线程利用率只有47%左右,大量的处理时间因为usleep(500)而导致线程睡眠: 性能始终上不去. 把usleep(500)修改为std::this_thread::yiel ...
- 返回值Student处理过程
- Python的开发环境
Python的开发环境 在 Python 开发环境中我们能看到很多工具,如 pip .conda .poetry . virtualenv . venv . pyenv 等等.他们是什么,都有什么作用 ...
- python浮点数计算--5
#!/usr/bin/python #coding=utf-8 i=1.0 j=3 print(i*j) print(i+j) print(i**j) 备注:无论是哪种运算,只要有操作数是浮点数,py ...
- gcc 11.2 在线升级
环境:centos 7 1.准备开发环境 $ yum groupinstall "Development Tools" $ yum install glibc-static lib ...