1 Star 1 Fork 1

bulexu / wework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Wechat Work 「企业微信」

Wework is a ruby API wrapper for wechat work「企业微信」.

企业微信 API 文档

CircleCI Gem Version

Installation

Add this line to your application's Gemfile:

gem 'wework'

And then execute:

$ bundle

Or install it yourself as:

$ gem install wework

Usage

初始化

Wework.configure do |config|
  config.redis = Redis.new(host: ENV['REDIS_HOST'], port: ENV['REDIS_PORT'], db: ENV['REDIS_CACHE_DB'])   # redis
  config.http_timeout_options = {write: 15, read: 15, connect: 10}                                        # 请求超时
  config.expired_shift_seconds = 180                                                                      # access token 有效期偏移量 (时间有效期 - 偏移量)
end

第三方应用

1). 初始化套件接口 Wework::Api::Suite

$wework_suite = Wework::Api::Suite.new(
  corp_id: ENV['WEWORK_CORPID'],                            # 应用服务商 CorpID
  suite_id: ENV['WEWORK_SUITE_ID'],                         # SuiteID
  encoding_aes_key: ENV['WEWORK_SUITE_ENCODING_AES_KEY'],   # EncodingAESKey
  suite_token: ENV['WEWORK_SUITE_TOKEN'],                   # Token
  suite_secret: ENV['WEWORK_SUITE_SECRET']                  # Secret
)

2). 获取第三方应用接口 Wework::Api::Agent

agent_api = $wework_suite.corp(
              corp_id,                                      # 授权企业 CorpID
              permanent_code                                # 永久授权码
            ).agent(agent_id)

3). 第三方应用回调协议

获取加密数据

encrypt_str = if params[:xml].present?
                params[:xml]['Encrypt']
              else
                Hash.from_xml(request.raw_post)['xml']['Encrypt']
              end

#首次校验接口 encrpt_str = params[:echostr]

消息签名

$wework_suite.signature(timestamp, nonce, encrypt_str)

消息解密

$wework_suite.msg_decrypt(encrypt_data)

自建应用

初始化接口 Wework::Api::Agent

$agent_api = Wework::Api::Agent.new(
  corp_id: ENV['WEWORK_CORPID'],                            # 企业 CorpID
  agent_id: ENV['WEWORK_APPID'],                            # AgentId
  secret: ENV['DEMO_APP_SECRET']                            # Secret
)

通讯录同步

初始化接口 Wework::Api::Contact

$contact_api = Wework::Api::Contact.new(
  corp_id: ENV['WEWORK_CORPID'],                            # 企业 CorpID
  secret: ENV['DEMO_APP_SECRET']                            # 通讯录同步 Secret
)

应用服务商接口

初始化

$provider_api = Wework::Api::Provider.new(
  corp_id: ENV['WEWORK_PROVIDER_CORPID'],                     # 应用服务商 CorpID
  secret: ENV['WEWORK_PROVIDER_SECRET'],                      # Secret
  token: ENV['WEWORK_PROVIDER_TOKEN'],
  encoding_aes_key: ENV['WEWORK_PROVIDER_ENCODING_AES_KEY']
)

回调接口消息加解密参考「第三方应用回调协议」

小程序 encryptedData 解密

require "openssl"
CIPHER = 'AES-128-CBC'.freeze

cipher = OpenSSL::Cipher.new(CIPHER)
cipher.decrypt
cipher.key = Base64.decode64(session_key)
cipher.iv = Base64.decode64(iv)
encrypted = Base64.decode64(encryptedData)
data = cipher.update(encrypted) + cipher.final
values = JSON.parse data

已实现接口列表

Wework::Api::Methods::Agent

Wework::Api::Methods::User

Wework::Api::Methods::Tag

Wework::Api::Methods::Department

Wework::Api::Methods::Message

Wework::Api::Methods::Appchat

Wework::Api::Methods::Media

Wework::Api::Methods::Menu

Wework::Api::Methods::Approval

Wework::Api::Methods::Checkin

Wework::Api::Methods::Batch

Wework::Api::Methods::Provider

Wework::Api::Methods::Service

Contributing

  • Fork Wework on GitHub
  • Make your changes
  • Ensure all tests pass (bundle exec rake)
  • Send a pull request
  • If we like them we'll merge them
  • If we've accepted a patch, feel free to ask for commit access!

License

Copyright (c) 2018 MyColorway. See LICENSE.txt for further details.

The MIT License (MIT) Copyright (c) 2016 seandong Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Wework is ruby API wrapper for wechat work「企业微信」. 展开 收起
Ruby 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Ruby
1
https://gitee.com/bulexu/wework.git
git@gitee.com:bulexu/wework.git
bulexu
wework
wework
master

搜索帮助