资源简介
用Python实现域用户与企业微信通讯录同步,实现功能:
1、同步域组织架构到微信
2、同步域用户到微信

代码片段和文件信息
#用Python实现域用户与企业微信通讯录同步
#by 二粒米
#用平凡的心对待世界,人生会更加精彩
#人们常常以为毁掉自己的是别人或者疾病等外部因素,但一个人到了这个世上,毁掉自己的只有自己,除了那些被意外毁掉的人
import json
import requests
import pyodbc
import binascii
# 返回token
def getToken(corpidsecrect):
url = ‘https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=‘+corpid+‘&corpsecret=‘+secrect
r=requests.get(url)
data=json.loads(r.text)
if(data[‘errcode‘]==0):
token = data[‘access_token‘]
else:
token = ‘‘
return token
#返回 errcode 及 errmsg
def getDept(access_tokendepid):
url = ‘https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=‘+access_token+‘&id=‘+depid
r=requests.get(url)
data=json.loads(r.text)
if(data[‘errcode‘]==0):
return data[‘department‘]
else:
return ‘‘
def delDept(access_tokendepid):
url = ‘https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=‘+access_token+‘&id=‘+depid
r=requests.get(url)
data=json.loads(r.text)
return data
def getUser(access_tokenuserid):
url = ‘https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=‘+access_token+‘&userid=‘+userid
r=requests.get(url)
data=json.loads(r.text)
if(data[‘errcode‘]==0):
return data
else:
return ‘‘
def CreateUser(access_tokenusers):
url = ‘https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=‘+access_token
r = requests.post(url users)
data=json.loads(r.text)
return data
def UpdateUser(access_tokenusers):
url = ‘https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=‘+access_token
r = requests.post(url users)
data=json.loads(r.text)
return data
def DelUser(access_tokenusers):
url = ‘https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=‘+access_token+‘&userid=‘+users
r = requests.get(url)
data=json.loads(r.text)
return data
def CreateDept(access_tokendept):
url = ‘https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=‘+access_token
r = requests.post(url dept)
data=json.loads(r.text)
return data
# 读取 access_token
corpid=‘wwd3bdf86acdbd09eb‘
secrect = ‘fLzr4NJA-SepJM_Uf6JVJyUJw79FrzkJd99HULrZ3MY‘
access_token = getToken(corpidsecrect)
if(access_token==‘‘):
print(“没有特征码,退出“)
exit()
#采用sqlserver
conn=pyodbc.connect(r‘DRIVER={SQL Server};SERVER=127.0.0.1;DATAbase=wxDB;UID=test;PWD=Py123456‘)
cursor = conn.cursor()
#获取微信组织架构信息,并把信息格式化,形成t_wx_org 假设AD组织通过外部已经引入到t_ad_org
depart = getDept(access_token‘1‘) #depart 是一个list类型,由多个dict类型组成,
#先清除原来数据,以便把新数据加入
cursor.execute(“delete from t_wx_org“)
# 取得微信用户信息
i=1
for ls in depart:
data=json.loads(str(ls).replace(‘\‘‘‘\“‘))
v=“\‘“+str(data[‘id‘])+“\‘“+“\‘“+data[‘name‘]+“\‘\‘“+str(data[‘parentid‘])+“\‘“+“\‘“+str(data[‘order‘])+“\‘“
cursor.execute(“insert into t_wx_org(idnameparentidorderid) values(“+v+“)“)
conn.commit()
cursor.
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2802176 2018-11-26 16:19 wxDB_v0.19.bak
文件 497 2018-11-26 17:25 用Python实现域用户与企业微信通讯录同步.txt
文件 10437 2018-11-26 17:26 qywx_v0.19.py
- 上一篇:用python编写的VMD代码
- 下一篇:爬虫1.py
相关资源
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
评论
共有 条评论