Giter VIP home page Giter VIP logo

weworkapi_python's Introduction

About

weworkapi_python 是为了简化开发者对企业微信API接口的使用而设计的,API调用库系列之python版本    
本库仅做示范用,并不保证完全无bug;
作者会不定期更新本库,但不保证与官方API接口文档同步,因此一切以官方文档为准。

更多来自个人开发者的其它语言的库推荐:
python : https://github.com/sbzhu/weworkapi_python [email protected](企业微信团队)
ruby : https://github.com/mycolorway/wework MyColorway(个人开发者)
php : https://github.com/sbzhu/weworkapi_php [email protected](企业微信团队)
golang : https://github.com/sbzhu/weworkapi_golang [email protected](企业微信团队)
golang : https://github.com/doubliekill/EnterpriseWechatSDK [email protected](个人开发者)

Director

├── api // API 接口
│   ├── examples // API接口的测试用例
│   ├── README.md
│   └── src // API接口的关键逻辑
├── conf.py
├── README.md

Usage

将本项目下载到你的目录,既可直接引用相关文件   详细使用方法参考examples路径下的测试用例

关于token的缓存

token是需要缓存的,不能每次调用都去获取token,否则会中频率限制
在本库的设计里,token是以类里的一个变量缓存的
比如api/src/CorpApi.py 里的access_token变量
在类的生命周期里,这个accessToken都是存在的, 当且仅当发现token过期,CorpAPI类会自动刷新token
刷新机制在 api/src/AbstractApi.py
所以,使用时,只需要全局实例化一个CorpAPI类,不要析构它,就可一直用它调函数,不用关心 token

api = CorpAPI(corpid, corpsecret);
api.dosomething()
api.dosomething()
api.dosomething()
....

当然,如果要更严格的做的话,建议自行修改,全局缓存token,比如存redis、存文件等,失效周期设置为2小时。

Contact us

[email protected]

weworkapi_python's People

Contributors

hfq-xiaochun avatar playay avatar sbzhu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

weworkapi_python's Issues

签名验证问题

if not signature == sMsgSignature:
我这个一直不相等,是为什么呢

设置自动回复消息时,出bug

image
此处只对用户不传入time时候做了生成操作,并将其转为字符串。若用户传入的time是数字类型,则不会转为字符串,进而导致程序出错。

使用 python requests 上传文件名包含中文问题

使用 requests 可以成功上传英文文件名的文件,但不能上传文件名包含中文的情况。
能否给出使用 requests 上传文件名包含中文的示例?

我目前的做法:
f = open(u'测试.txt', 'rb')
url = '''https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=file''' % ac_token
files = {'file': ('测试.txt', f)}
r = requests.post(url, files=files)

返回的是
{u'errcode': 44001, u'errmsg': u'empty media data, hint: [ ], more info at https://open.work.weixin.qq.com/devtool/query?e=44001'}

看起来是 requests 将 Content-Disposition 部分写为了:
Content-Disposition: form-data; name="file"; filename*=utf-8''%E6%B5%8B%E8%AF%95.txt

使用 API 测试页面 可以成功上传中文文件名的文件,看到的 Request Payload 为:
Content-Disposition: form-data; name="media"; filename="测试.txt"

PKCS7Encoder补位问题

PKCS7Encoder类中,amount_to_pad == 0不会发生

代码如下:
amount_to_pad = self.block_size - (text_length % self.block_size)
if amount_to_pad == 0:
amount_to_pad = self.block_size

40001 error

执行的时候报:40001 invalid credential, hint: [1597733128_47_64fcadb1b2caaa453d570b16348fd1ae]...

【corpwechat-bot】企业微信的python封装接口,开箱即用,一行代码实现消息推送

你好,本人在官方API的基础上封装并开发了一个简单的企业微信消息推送的库:corpwechat-bot,通过该库能够更加方便的实现开箱即用的消息推送方式:
具体效果可以查看QuickStart,
目前,基本上已经完成了官方大部分的消息推送,每个消息推送都可以通过一行代码实现,希望能被官方收录:)

应用消息

  • 文本消息: 最普通的消息,文字内容,最长不超过2048个字节
  • 图片消息:发送一张图片,可选jpg,png,大小不超过2MB,目前仅支持通过图片路径发送
  • 语音消息:发送一条语音,大小不超过2MB,时长不超过60s,必须是.amr格式
  • 视频消息:发送一段视频,大小不超过10MB,必须是.mp4格式
  • 普通文件:其他类型的文件,大小不超过20MB(不小于5字节)
  • markdown消息:传输markdown类型消息
  • 图文消息:图片文字形式,带有跳转链接,适合做推广
  • mpnews图文消息:有专属页面的图文消息,支持html标签内容
  • 文本卡片消息:以卡片形式呈现的文本,包含跳转链接
  • 任务卡片消息:应用与用户交互的卡片,需要配置回调

群聊机器人消息

  • 文本消息:普通文字消息,最长不超过2048个字节
  • 图片消息:图片大小不超过2M
  • 图文消息:图片文字形式,带有跳转链接,适合打广告
  • 文件消息:发送单个文件到群聊,大小在5B~20MB之间

WXBizMsgCrypt3

image

sortlist内同时包含str和int类型会报错的。
image
timestamp可以转成str类型就可以了。

weworkapi 4 python3

你好,官方提供的python api代码是python2的,为了适应我们的需要,我基于这个源码修改成了python3的,可以么

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.