企业微信人员日程推送接口(python版)
企业在使用企业微信中,有时想批量推送员工日程信息。这里写了个接口工具分享给大家,供交流学习。
主入口程序:
# -*- coding: utf-8 -*-
import time as time
import pymysql as mdb
import getdbconn as dbconn
import renyrw
def Main_sendmsg_toUser():
conn=dbconn.dbconn()
cur = conn.cursor(mdb.cursors.DictCursor)
sql_getmsg="select *from wxmsg_rwb where status<>'Y' "
sql_up="update wxmsg_rwb set status='Y' where id=%s"
cur.execute(sql_getmsg)
rs=cur.fetchall()
for r in rs:
id=('%s' %r['id'])
touser=('%s' %r['username'])
msg=('%s' %r['msg'])
msgtitle=('%s' %r['msgtitle'])
url=('%s' %r['url'])
urltxt=('%s' %r['urltxt'])
renyrw.Api_upload_renyrw('1',touser,msg)
params=(id)
cur.execute(sql_up,params)
conn.commit()
cur.close()
conn.close()
if __name__ == '__main__':
Main_sendmsg_toUser()
-----------
发送方法,renyrw.py
# -*- coding: utf-8 -*-
import time as time
import requests
import json
import urllib.request as rq
#from appcomm import appcomm
##调用企业微信api 给员工发消息. touser --userid即通讯录员工账号,corpid--企业微信id,corpsecret--应用的密匙,每个应用的不一样;
def get_access_token(cmpid):
#corpid,apikey_txl,apikey_dk,apikey_rch=appcomm.getapiinfo(cmpid)
corpid=' '
apikey_rch=' '
url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s' % (corpid,apikey_rch) #
#url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s' % ('wwcffccbc9b870f383','jZjHJeX-af1EcPLW3h8bMgrLXG9Y0TNkPwC7EWP_CgI') #
req = rq.Request(url)
result = rq.urlopen(req)
access_token = json.loads(result.read())
#print(access_token["access_token"])
return access_token["access_token"]
def Api_upload_renyrw(cmpid,userid,text):
#print(getUser(bm))
time_s=time.strftime('%Y-%m-%d',time.localtime(time.time()))+" 08:00:00"
time_e=time.strftime('%Y-%m-%d',time.localtime(time.time()))+" 23:00:00"
#time_s="2020-06-18 00:00:00"
#time_e="2020-06-18 23:00:00"
uix_stime = time.mktime(time.strptime(time_s, "%Y-%m-%d %H:%M:%S"))
uix_etime = time.mktime(time.strptime(time_e, "%Y-%m-%d %H:%M:%S"))
#print("3.把字符串转成时间戳形式:", time.mktime(time.strptime(time_s, "%Y-%m-%d %H:%M:%S")))
#print(time_s)
#print(time_e)
#print(uix_stime)
#print(uix_etime)
data={
"schedule": {
"organizer": userid,
"start_time": uix_stime,
"end_time": uix_etime,
"attendees": [
{
"userid": userid
}
],
"summary": text,
"description": "日程信息",
"reminders": {
"is_remind": 1,
"remind_before_event_secs": 3600,
"is_repeat": 0,
"repeat_type": 7
},
"location": "",
"cal_id": ""
}
}
print(data)
json_template=json.dumps(data,ensure_ascii=False)
access_token=get_access_token(cmpid)
print("access_token--",access_token)
#access_token='J3bOu0egcg0VWVQHd7IlbkpN_uZjrfD3EK32aw9qFwTzctTC2vikpwzJhd5jgDJAzBgVqOtZlHmS3MT1_PMk6ww-eeipv_04W2CGnT5sK43slQUNoZfMeE-5pyvFf2FBLad3berUuzb-3ysAKWchiQTXh9dGD13fEEmGxtxT9FwYKxRY_s-kVQurWHuckNNGnntkmCdpangWKwenw4Y6sw'
url="https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/add?access_token="+access_token
#https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/add?access_token=ACCESS_TOKEN
try:
respone=requests.post(url,data=json_template.encode('UTF-8'), timeout=50)
#拿到返回值
errcode=respone.json().get("errcode")
print("返回:--",respone.json())
if(errcode==0):
print("成功")
else:
print("失败")
except Exception as e:
print("异常----",e)
-----
数据库连接方法 getdbconn.py
import pymysql as mdb
def dbconn():
host='192.168.0.100'
user='user'
password='12345'
database='db1'
conn=mdb.connect(host,user,password,database)
return conn
-----日程信息接口数据表结构 mysql版
/*
Navicat MySQL Data Transfer
Source Server :
Source Server Version : 50717
Source Host :
Source Database :
Target Server Type : MYSQL
Target Server Version : 50717
File Encoding : 65001
Date: 2020-08-19 10:13:16
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for wxmsg_rwb
-- ----------------------------
DROP TABLE IF EXISTS `wxmsg_rwb`;
CREATE TABLE `wxmsg_rwb` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(500) DEFAULT NULL,
`msg` varchar(2000) DEFAULT NULL,
`status` char(10) DEFAULT NULL,
`msgtitle` varchar(200) DEFAULT NULL,
`url` varchar(400) DEFAULT NULL,
`ontime` varchar(40) DEFAULT NULL,
`urltxt` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20861 DEFAULT CHARSET=utf8;
-----使用方法,对接企业内部系统如ERP等,把日程相关数据写入表wxmsg_rwb中,定时执行接口程序即可推送日程信息到人员企业微信,如下形式展示:

企业微信人员日程推送接口(python版)的更多相关文章
- ios远程推送和python版push server相关笔记
今天研究了下ios的远程推送,网上的相关教程很多,做了一遍下来记录一下遇到的问题和注意事项(转载请注明) 1.证书及乱七八糟的配置 公钥:app id管理那儿的“Development Push SS ...
- 前后端分离djangorestframework—— 接入微信模板消息推送
微信 什么是微信也不多说,跟前面的支付宝一样的 微信支付 微信支付也有个沙箱环境,沙箱环境官方文档 由文档中那句很显眼的话所得,即使是测试环境也需要真实的商户号,所以这个就没法想支付宝那样用沙箱账号来 ...
- $Django 支付宝支付,微信服务号推送消息 (测试需要把应用程序部署到服务器上)
一 支付宝支付 大概 支付宝支付 正式环境:需要用营业执照去申请商户号,appid 测试环境:沙箱环境:https://openhome.alipay.com/platform/appDaily.ht ...
- java开发微信模板消息推送
发布时间:2018-12-12 技术:springboot+maven 概述 该demo主要涉及微信模板消息推送功能, 详细 代码下载:http://www.demodashi.com/dem ...
- 【原创分享·微信支付】C# MVC 微信支付之微信模板消息推送
微信支付之微信模板消息推送 今天我要跟大家分享的是“模板消息”的推送,这玩意呢,你说用途嘛,那还是真真的牛逼呐.原因在哪?就是因为它是依赖微信生存的呀,所以他能不 ...
- C# MVC 微信支付之微信模板消息推送
微信支付之微信模板消息推送 今天我要跟大家分享的是"模板消息"的推送,这玩意呢,你说用途嘛,那还是真真的牛逼呐.原因在哪?就是因为它是依赖微信 ...
- .NET之微信消息模板推送
最近在项目中使用到了微信消息模板推送的功能,也就是将对应的消息推送到对应的用户微信上去,前提是你必须要有一个微信公众号并且是付费了的才会有这个功能,还有就是要推送的用户必须是的关注了你的微信公众号的. ...
- 如何使用Postman调试HMS Core推送接口?
HMS Core推送服务支持开发者使用HTTPS协议接入Push服务端.Postman是一款接口测试工具,它可以模拟用户发起的各类HTTP请求,将请求数据发送至服务端,获取对应的响应结果.Postma ...
- 关于调用三方平台接口与推送接口的总结<二>(2020.7.27)
前言:本篇博客是接着上篇总结写的,想了解怎么对接第三方平台接口的同学可以看我上一篇博客,地址是 https://www.cnblogs.com/alanturingson/p/13377500.ht ...
随机推荐
- Invalid RNPermission 'ios.permission.xxx'. should be one of: ( )
原因可能是配置配置问题, 我碰到的是Android上完美运行,iOS报错,原因是前期用的Android开发,iOS的配置项没有配完整 按照官方配置一遍 https://github.com/react ...
- web自动化 -- 切换 iframe
先看源码 switch_to_frame() frame() 具体用法
- 水题----B - Badge CodeForces - 1020B
In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. A ...
- spring学习(一)spring简介
Spring简介: Spring 框架是 Java 应用最广的框架,它的成功来源于理念,而不是技术本身,它的理念包括 IoC (Inversion of Control,控制反转) 和 AOP(Asp ...
- 细说JavaScript 导出 上万条Excel数据
首先这是个鸡肋的方法 合理的做法是 后端直接生成 前端给个链接就行了 (先说原因与过程最后上代码) 1. 先说说为什么会出现这个需求吧. : 在写运维网站时 自己粗略的看了一下bootstarp-ta ...
- ES数据库 常用 java api
一.获取类api get API允许根据其id从索引中获取类型化的JSON文档. 以下示例从名为twitter的索引中获取一个JSON文档,该索引名为tweet,id值为1: GetResponse ...
- LQB2013A05前缀判断
上一道题,,,把if条件写错了,,,,找了半天的bug我都快哭了, 好了好了 看见这种填空题,先理解题意 然后把代码copy下来,把空格注释掉,然后运行到编译没有错. 再理一下它的思路 // // C ...
- Python异常及异常处理
Python异常及异常处理: 当程序运行时,发生的错误称为异常 例: 0 不能作为除数:ZeroDivisionError 变量未定义:NameError 不同类型进行相加:TypeError 异常处 ...
- 将形如 5D, 30s 的字符串转为秒
import sys def convert_to_seconds(time_str): # write code here if 's' in time_str: return float(time ...
- Python os.link() 方法
概述 os.link() 方法用于创建硬链接,名为参数 dst,指向参数 src.高佣联盟 www.cgewang.com 该方法对于创建一个已存在文件的拷贝是非常有用的. 只支持在 Unix, Wi ...