From 7c81271693857b83ae79f9a84f7e9c72646f3be7 Mon Sep 17 00:00:00 2001 From: Eric Guo Date: Thu, 17 Dec 2015 23:09:09 +0800 Subject: [PATCH] New command line to generate OAuth2 URL. --- README.md | 2 ++ bin/wechat | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 72328c15..216379ca 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,7 @@ Wechat commands: wechat menu # 当前菜单 wechat menu_create [MENU_YAML_PATH] # 创建菜单 wechat menu_delete # 删除菜单 + wechat oauth2_url [REDIRECT_URI] # 生成OAuth2.0验证URL wechat qrcode_create_limit_scene [SCENE_ID_OR_STR] # 请求永久二维码 wechat qrcode_create_scene [SCENE_ID, EXPIRE_SECONDS] # 请求临时二维码 wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码 @@ -241,6 +242,7 @@ Wechat commands: wechat menu_create [MENU_YAML_PATH] # 创建菜单 wechat menu_delete # 删除菜单 wechat message_send [OPENID, TEXT_MESSAGE] # 发送文字消息 + wechat oauth2_url [REDIRECT_URI] # 生成OAuth2.0验证URL wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码 wechat tag [TAG_ID] # 获取标签成员 wechat tag_add_department [TAG_ID, PARTY_IDS] # 增加标签部门 diff --git a/bin/wechat b/bin/wechat index 1e86a0e2..1b9e68c7 100755 --- a/bin/wechat +++ b/bin/wechat @@ -13,6 +13,7 @@ require 'active_support/json' require 'fileutils' require 'yaml' require 'wechat/api_loader' +require 'cgi' class App < Thor package_name 'Wechat' @@ -284,6 +285,13 @@ class App < Thor puts wechat_api.user(open_id) end + desc 'oauth2_url [REDIRECT_URI]', '生成OAuth2.0验证URL' + def oauth2_url(redirect_uri) + redirect_uri = CGI.escape(redirect_uri) + appid = Wechat.config.corpid || Wechat.config.appid + puts "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{appid}&redirect_uri=#{redirect_uri}&response_type=code&scope=snsapi_base#wechat_redirect" + end + desc 'user_update_remark [OPEN_ID, REMARK]', '设置备注名' def user_update_remark(openid, remark) puts wechat_api.user_update_remark(openid, remark)