import requests
import json
import datetime# 常量需自定义
ID =
SECRET =
SECRET1 =
AGENTID =
APPID = ############################# 获取token ###############################
def get_token(_secret):url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}".format(ID,_secret)headers = {'Content-Type': 'application/json'}body = {}response = requests.post(url, data = json.dumps(body), headers = headers)res = (dict(json.loads(response.text))).get("access_token")#print("token: "+res)return res############################# 获取部门列表 ###############################
def get_simplelist_all(_token,_department_id):url = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={}&id={}".format(_token,_department_id)headers = {'Content-Type': 'application/json'}body = {}response = requests.post(url, data = json.dumps(body), headers = headers)res = dict(json.loads(response.text))#print(res)return res############################# 获取子部门ID列表 ###############################
def get_simplelist(_token,_department_id):url = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token={}&id={}".format(_token,_department_id)headers = {'Content-Type': 'application/json'}body = {}response = requests.post(url, data = json.dumps(body), headers = headers)res = dict(json.loads(response.text))#print(res)return res.get("department_id")############################# 创建部门 ###############################
def create_department(_token,_name,_department_id):url = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token={}&id={}".format(_token,_department_id)headers = {'Content-Type': 'application/json'}body = {}response = requests.post(url, data = json.dumps(body), headers = headers)res = dict(json.loads(response.text))print(res)return res############################# 获取userid ###############################
def get_user_id(_token,_tele):url = "https://qyapi.weixin.qq.com/cgi-bin//user/getuserid?access_token={}".format(_token)headers = {'Content-Type': 'application/json'}body = {'mobile':_tele}response = requests.post(url, data = json.dumps(body), headers = headers)res = dict(json.loads(response.text))print(res)print(res.get("userid"))return res.get("userid")############################# 获取部门成员 ###############################
def get_department_users(_token,_id):url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token={}&department_id={}".format(_token,_id)headers = {'Content-Type': 'application/json'}body = {}response = requests.post(url, data = json.dumps(body), headers = headers)res = dict(json.loads(response.text)).get("userlist")#print(res)return res############################# 获取全部成员 ###############################
def get_all_user(_token):# 遍历部门 + 成员信息dList = get_simplelist(token,'')for d in dList:dId = d.get('id')dUsers = get_department_users(_token,dId)for u in dUsers:print(u)# 部门详情############################# 发送消息 ###############################
def send_msg(_token,_userid):url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}&debug=1".format(_token)headers = {'Content-Type': 'application/json'}body = { "touser" : _userid,"agentid" : AGENTID,"msgtype" : "miniprogram_notice","miniprogram_notice" : {"appid": APPID,"title": "营销员奖励通知","description":datetime.datetime.now().strftime("%Y年%m月%d日 %H:%M"),"content_item": [{"key": "购买人","value": "xxx"},{"key": "商品名","value": "xxxxx商品"},{"key": "预计奖励","value": "xxxx元"},]},"enable_id_trans": 0,"enable_duplicate_check": 0,"duplicate_check_interval": 1800
}response = requests.post(url, data = json.dumps(body), headers = headers)res = dict(json.loads(response.text))print(res)##############################################################################

【python】企微代码 通讯录交互相关推荐

  1. echarts python源码_基于Echarts的微代码开发平台SmartChart, 免费开源使用

    A platform that Connect Data to Echarts. 简介 SmartChart基于Echarts/Django的微代码开发平台,适用于任何WEB项目 简单, 敏捷, 高效 ...

  2. centos部署python flask_python 微服务框架之nameko实践

    大纲: 1.本篇关键技术点及其释义 2.实际需求和目标 3.可行的三大解决方案 4.微服务与传统服务的差别 5.代码大纲:安装依赖及nameko五个完整的代码示例 6.附录:docker的在线安装方式 ...

  3. 自动更新发送Excel文件到邮件企微

    AutoSendMsg 文章目录 AutoSendMsg 1. 总概 2. 邮件(Mail) 2.1 项目结构 2.2 生成邮箱第三方客户端密码 2.3 设置说明 2.4 直接运行 3. 企微机器人( ...

  4. Swift - 访问通讯录联系人(使用系统提供的通讯录交互界面)

    1,通讯录访问介绍 通讯录(或叫地址簿,电话簿)是一个数据库,里面储存了联系人的相关信息.要实现访问通讯录有如下两种方式: (1)AddressBook.framework框架 : 没有界面,通过代码 ...

  5. 10 种机器学习算法的要点(附 Python 和 R 代码)(转载)

    10 种机器学习算法的要点(附 Python 和 R 代码)(转载) from:https://zhuanlan.zhihu.com/p/25273698 前言 谷歌董事长施密特曾说过:虽然谷歌的无人 ...

  6. Python基础之简单用户交互

    Python基础之简单用户交互 一.要求及目的 二.代码内容 三.学习总结 一.要求及目的 要求设计一个简单的计算程序 二.代码内容 # 简单计算 a = input("please inp ...

  7. 机器学习算法一览(附python和R代码)

     机器学习算法一览(附python和R代码) 来源:数据观 时间:2016-04-19 15:20:43 作者:大数据文摘 "谷歌的无人车和机器人得到了很多关注,但我们真正的未来却在于能 ...

  8. 机器学习系列(9)_机器学习算法一览(附Python和R代码)

    转载自:http://blog.csdn.net/longxinchen_ml/article/details/51192086 – 谷歌的无人车和机器人得到了很多关注,但我们真正的未来却在于能够使电 ...

  9. python rpc微服务框架_grpc的微服务探索实践

    对于微服务的实践,一般都是基于Java和Golang的,博主最近研究了下基于Python的微服务实践,现在通过一个简单的服务来分析Python技术栈的微服务实践 技术栈:Python3 + grpc ...

最新文章

  1. 解决JavaWeb项目代码报错
  2. Hdu 2089-不要62 数位dp
  3. 10-RabbitMQ-整合SpringBoot
  4. c++前置声明的一点总结
  5. 在delphi中嵌入脚本语言--(译)RemObjects Pascal Script使用说明(1)(译)
  6. jQuery基础集锦——插件开发
  7. 微分方程建模——以传染病模型为例
  8. 深度卷积神经网络(CNN)特征层的可视化
  9. Java测试框架系列:Mockito 详解:第二部分:创建存根
  10. 乐山计算机学校学籍管理,乐山计算机学校学生管理系统设计与实现
  11. css 全屏显示一张图片_css 如何让图片全屏的问题
  12. 如何还原MySQL备份文件.xb
  13. 中石油、长安、奥动新能源合作打造换电站;玛氏箭牌与阿里巴巴合作同城零售 | 美通企业日报...
  14. ubuntu 下正确安装android手机驱动
  15. 【从0到1搭建LoRa物联网】3、国产LoRa终端ASR6505软硬件
  16. nginx服务,杀不死nginx进程
  17. 七参数坐标参数解算(MATLAB)
  18. No module named '_sqlite3'
  19. 省常中模拟 Test1 Day1
  20. gwr模型用什么做_为什么我的 CV 模型不好用?没想到原因竟如此简单……

热门文章

  1. pythonturtle复制图像_Python图标副本(turtle),python,复制,Turtle
  2. 招聘网站的【JD】字样的含义
  3. XGBoost, LightGBM
  4. 基于java的服装商城平台SSM框架
  5. 闲聊vue版本差异和开发中不太容易注意的点(基础篇)
  6. 移动端插件-Swiper图片切换、轮播
  7. Flutter实现电影展示App
  8. 最大k乘积问题--动态规划
  9. 电磁流量计在复杂工业管道中的选型与安装
  10. 如何使用M33D1一体式在线氨氮传感器