我是靠谱客的博主 默默彩虹,这篇文章主要介绍python微信api_python调用企业微信API,现在分享给大家,希望可以做个参考。

#!/usr/bin/env python

# -*- coding:utf-8 -*-

# 2017-07-25 编写

import json

import sys

import urllib, urllib2

"""

CorpID 企业ID

Secret 应用密钥

"""

CorpID = ‘‘

Secret = ‘‘

touser = ‘@all‘

content = ‘‘

#获取access_token

def getToken(CorpID, Secret):

url = ‘https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s‘ % (CorpID, Secret)

req = urllib2.Request(url)

result = urllib2.urlopen(req)

access_token = json.loads(result.read())

return access_token[‘access_token‘]

#发送消息

def tonews(access_token, content):

url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + access_token

"""

touser 成员 @all 就是所有

toparty 部门ID @all 就是所有

msgtype 文本类型

agentid 企业应用ID

content 内容

safe 是否保密 0是不保密

"""

values = {

"touser" : touser,

"toparty" : ‘2‘,

"msgtype" : "text",

"agentid" : 1,

"text" : {

"content" : content

},

"safe" :"0"

}

send_data = json.dumps(values)

send_request = urllib2.Request(url, send_data)

response = json.loads(urllib2.urlopen(send_request).read())

if response[‘errcode‘] == 0:

print ‘发送消息成功‘

if __name__ == ‘__main__‘:

access_token = getToken(CorpID, Secret)

print "获取token成功"

content = ‘n‘.join(sys.argv[1:])

if not content:

content = "测试成功"

tonews(access_token, content)

[root@400ec7d4b418 /]# python wechat.py 456 678 //需要传递的数据

原文地址:http://xiaocuik.blog.51cto.com/12090846/1968648

最后

以上就是默默彩虹最近收集整理的关于python微信api_python调用企业微信API的全部内容,更多相关python微信api_python调用企业微信API内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部