Commit 7d9d62e4c92cd9c354d1aee68b4a9a15c68e43b7

Authored by lanrion
1 parent 623b779c
Exists in master

添加第三方应用套件API使用说明

Showing 1 changed file with 58 additions and 0 deletions   Show diff stats
README.md
... ... @@ -142,3 +142,61 @@ group_client.media.get_media_by_id(media_id)
142 142 如果你觉得我的gem对你有帮助,欢迎打赏支持,:smile:
143 143  
144 144 ![](https://raw.githubusercontent.com/lanrion/my_config/master/imagex/donation_me.png)
  145 +
  146 +## 第三方应用
  147 +
  148 +这里特别注意:保留 suite_access_token的cache是直接利用了 Rails.cache,请务必在Rails框架下使用此gem。
  149 +
  150 +### api 使用介绍
  151 +
  152 +```ruby
  153 +suite_api = QyWechatApi::Suite.service(suite_id, suite_secret, suite_ticket)
  154 +
  155 +# 获取预授权码
  156 +suite_api.get_pre_auth_code(appid=[])
  157 +
  158 +# 获取企业号的永久授权码
  159 +suite_api.get_permanent_code(auth_code)
  160 +
  161 +# 获取企业号的授权信息
  162 +suite_api.get_auth_info(auth_corpid, code)
  163 +
  164 +# 获取企业号应用
  165 +suite_api.get_agent(auth_corpid, code, agent_id)
  166 +
  167 +# 设置授权方的企业应用的选项设置信息
  168 +suite_api.set_agent(auth_corpid, permanent_code, agent_info)
  169 +
  170 +# 调用企业接口所需的access_token
  171 +suite_api.get_crop_token(auth_corpid, permanent_code)
  172 +```
  173 +
  174 +### 应用套件的回调通知处理
  175 +
  176 +Wiki: http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%9B%9E%E8%B0%83%E5%8D%8F%E8%AE%AE
  177 +
  178 +```ruby
  179 +class QyServicesController < ApplicationController
  180 + skip_before_filter :verify_authenticity_token, only: :receive_ticket
  181 +
  182 + # TODO: 需要创建表: suites
  183 + def receive_ticket
  184 + param_xml = request.body.read
  185 + aes_key = "NJgquXf6vnYlGpD5APBqlndAq7Nx8fToiEz5Wbaka47"
  186 + aes_key = Base64.decode64("#{aes_key}=")
  187 + hash = MultiXml.parse(param_xml)['xml']
  188 + @body_xml = OpenStruct.new(hash)
  189 + suite_id = "tj86cd0f5b8f7ce20d"
  190 + content = QyWechat::Prpcrypt.decrypt(aes_key, @body_xml.Encrypt, suite_id)[0]
  191 + hash = MultiXml.parse(content)["xml"]
  192 + Rails.logger.info hash
  193 + render text: "success"
  194 + # {"SuiteId"=>"tj86cd0f5b8f7ce20d",
  195 + # "SuiteTicket"=>"Pb5M0PEQFZSNondlK1K_atu2EoobY9piMcQCdE3URiCG3aTwX5WBTQaSsqCzaD-0",
  196 + # "InfoType"=>"suite_ticket",
  197 + # "TimeStamp"=>"1426988061"}
  198 + end
  199 +end
  200 +```
  201 +
  202 +>>>>>>> 添加第三方应用套件API使用说明
... ...