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. Python+OpenCV 图像处理系列(4)—— 图像像素的读写、算术运算、逻辑运算及像素的统计
  2. DHCP之一 DHCP的部署安装
  3. 关于学习Python的一点学习总结(5->切片赋值->sort排序->列表操作)
  4. Windows2003使用WEB方式修改域用户密码
  5. [javaEE] JDBC快速入门
  6. 如何搭建一套完整的深度学习系统?
  7. android中menu菜单扩增_在Android中的工具栏中添加菜单
  8. 31.卷1(套接字联网API)---流
  9. Linux中文件权限(有图详细讲解)
  10. 计算机出现测试模式,win10系统右下角显示测试模式内部版本10601的详细步骤
  11. rgb转hsv (Verilog)
  12. Python绘制用于学术论文投稿的黑白图片
  13. HRNet-v1模型,用于人体形态检测
  14. selectpicker 动态加载数据
  15. scrollViewDidEndDragging和scrollViewDidEndDecelerating有什么区别呢
  16. linux scp 输入密码,scp 在脚本中使用输入密码的解决方法
  17. 对捕金猎人的买涨买跌交易感悟?(交易基础篇)
  18. hdu 1541 树状数组版)——咯咯
  19. 【职业女性着装全攻略】_职业女性应该怎样着装
  20. 支付宝小程序使用扩展组件安装

热门文章

  1. Service系统服务(二):补充应用技巧、软连接与硬连接、man手册、zip备份、vim效率操作、自定义yum软件仓库、发布及测试yum仓库、编译安装软件包...
  2. 工作五年以上的UI设计师都在干什么?
  3. 宝付谈疫情中支付行业风险与机遇
  4. js 找出多个数组中的最大数
  5. java设计模式之建造者模式(UML类图分析+代码详解)
  6. 13《将心注入》-豆瓣评分8.3
  7. 『算法』哨兵查找算法
  8. 怎样压缩pdf文件大小?pdf文件压缩方法
  9. 高通 android 传感器支持,高通:Android手机用户明年将用上刷脸功能
  10. 防范网络陷阱与计算机病毒教学设计,粤教版信息技术第二册上第6课防范网络陷阱与计算机病毒教学设计(1).doc...