Skip to content

Commit

Permalink
Move oauth2_url to Wechat instead of only command line
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed Dec 18, 2015
1 parent 7c81271 commit 27dc8e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions bin/wechat
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,8 @@ class App < Thor

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"
puts oauth2_url(redirect_uri, appid)
end

desc 'user_update_remark [OPEN_ID, REMARK]', '设置备注名'
Expand Down
6 changes: 6 additions & 0 deletions lib/wechat/corp_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'wechat/client'
require 'wechat/access_token'
require 'wechat/corp_jsapi_ticket'
require 'cgi'

module Wechat
class CorpAccessToken < AccessToken
Expand Down Expand Up @@ -41,6 +42,11 @@ def getuserinfo(code)
get 'user/getuserinfo', params: { code: code }
end

def oauth2_url(redirect_uri, appid)
redirect_uri = CGI.escape(redirect_uri)
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{appid}&redirect_uri=#{redirect_uri}&response_type=code&scope=snsapi_base#wechat_redirect"
end

def convert_to_openid(userid)
post 'user/convert_to_openid', JSON.generate(userid: userid, agentid: agentid)
end
Expand Down

0 comments on commit 27dc8e9

Please sign in to comment.