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 "发送成功"