python调用企业微信接口

更新时间:2023-05-16 09:09:38 阅读: 评论:0

python调⽤企业微信接⼝python调⽤企业微信接⼝实现关联添加⽤户
# --*-- coding: utf-8 --*--
import json
import urllib2
coreID =
cret =
apicret =
agent_id =
获取token:
def getToken(coreID, apicret):
url = 'qyapi./cgi-bin/gettoken?corpid=%s&corpcret=%s' % (coreID, apicret)    req = urllib2.Request(url)
result = urllib2.urlopen(req)
access_token = json.ad())
#print access_token['access_token']
return access_token['access_token']
添加⽤户:
def AddWechartUr(urid, name, mobile, email, groupid):
token = getToken(coreID, apicret)
url = 'qyapi./cgi-bin/ur/create?access_token=%s' % token
values = {
梦见鱼
"urid": urid,
"name": name,
"mobile": mobile,文明城市手抄报内容
"email": email,
"department": groupid,
}
add_ur = json.dumps(values)里约时间
request = urllib2.Request(url, add_ur)话剧独白
respon = json.loads(urllib2.urlopen(request).read())
#print respon
if respon['errcode'] == 0:
return "添加成功"
return respon['errmsg']
发送告警:
def SendMsg(msg, tour, toparty):
舒适的英文#这⾥以text为例,tour和toparty不可同时为空
token = getToken(coreID, cret)
msgtype = "text"工作个人简历表格
url = 'qyapi./cgi-bin/message/nd?access_token=%s' % token    values = {
"tour": tour,
"toparty": toparty,
"msgtype": msgtype,
"agentid": agent_id,
"text": {官字开头的成语
"content": msg
}
}
nd = json.dumps(values)
request = urllib2.Request(url, nd)
respon = json.loads(urllib2.urlopen(request).read())
if respon['errcode'] != 0:
return respon['errmsg']
return "发送成功"

本文发布于:2023-05-16 09:09:38,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/903131.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:实现   微信   文明城市   成语
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图