Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weixin_authorize
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
weixin_authorize
Commits
f2c296f9
Commit
f2c296f9
authored
Aug 31, 2015
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 qrcode_authorize_url接口实现网页二维码登录
parent
8e717992
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
lib/weixin_authorize.rb
+1
-0
lib/weixin_authorize/api/mass.rb
+1
-1
lib/weixin_authorize/api/oauth.rb
+15
-3
No files found.
lib/weixin_authorize.rb
View file @
f2c296f9
...
@@ -5,6 +5,7 @@ if defined? Yajl
...
@@ -5,6 +5,7 @@ if defined? Yajl
else
else
require
"json"
require
"json"
end
end
require
"erb"
require
"weixin_authorize/carrierwave/weixin_uploader"
require
"weixin_authorize/carrierwave/weixin_uploader"
require
"weixin_authorize/config"
require
"weixin_authorize/config"
...
...
lib/weixin_authorize/api/mass.rb
View file @
f2c296f9
...
@@ -55,7 +55,7 @@ module WeixinAuthorize
...
@@ -55,7 +55,7 @@ module WeixinAuthorize
def
generate_media
(
msg_type
,
media_info
,
option
)
def
generate_media
(
msg_type
,
media_info
,
option
)
msg_type
=
msg_type
.
to_s
msg_type
=
msg_type
.
to_s
if
not
MSG_TYPE
.
include?
(
msg_type
)
if
not
MSG_TYPE
.
include?
(
msg_type
)
raise
MediaTypeException
,
"
#{
msg_type
}
is a valid msg_type"
raise
MediaTypeException
,
"
#{
msg_type
}
is a
in
valid msg_type"
end
end
{
{
msg_type
=>
convert_media_info
(
msg_type
,
media_info
),
msg_type
=>
convert_media_info
(
msg_type
,
media_info
),
...
...
lib/weixin_authorize/api/oauth.rb
View file @
f2c296f9
...
@@ -3,6 +3,13 @@ module WeixinAuthorize
...
@@ -3,6 +3,13 @@ module WeixinAuthorize
module
Api
module
Api
module
Oauth
module
Oauth
# 网站应用微信登录授权URL
# 文档:http://t.cn/RyZVWEY
def
qrcode_authorize_url
(
uri
,
scope
=
"snsapi_login"
,
state
=
"web_wx_login"
)
uri
=
encode_url
(
redirect_uri
)
WeixinAuthorize
.
open_endpoint
(
"/connect/qrconnect?appid=
#{
app_id
}
&redirect_uri=
#{
uri
}
&response_type=code&scope=
#{
scope
}
&state=
#{
state
}
#wechat_redirect"
)
end
# 应用授权作用域: scope
# 应用授权作用域: scope
# snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid),
# snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid),
# snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息)
# snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息)
...
@@ -11,9 +18,8 @@ module WeixinAuthorize
...
@@ -11,9 +18,8 @@ module WeixinAuthorize
# 如果用户点击同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE。若用户禁止授权,则重定向后不会带上code参数,仅会带上state参数redirect_uri?state=STATE
# 如果用户点击同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE。若用户禁止授权,则重定向后不会带上code参数,仅会带上state参数redirect_uri?state=STATE
def
authorize_url
(
redirect_uri
,
scope
=
"snsapi_base"
,
state
=
"weixin"
)
def
authorize_url
(
redirect_uri
,
scope
=
"snsapi_base"
,
state
=
"weixin"
)
require
"erb"
uri
=
encode_url
(
redirect_uri
)
redirect_uri
=
ERB
::
Util
.
url_encode
(
redirect_uri
)
WeixinAuthorize
.
open_endpoint
(
"/connect/oauth2/authorize?appid=
#{
app_id
}
&redirect_uri=
#{
uri
}
&response_type=code&scope=
#{
scope
}
&state=
#{
state
}
#wechat_redirect"
)
WeixinAuthorize
.
open_endpoint
(
"/connect/oauth2/authorize?appid=
#{
app_id
}
&redirect_uri=
#{
redirect_uri
}
&response_type=code&scope=
#{
scope
}
&state=
#{
state
}
#wechat_redirect"
)
end
end
# 首先请注意,这里通过code换取的网页授权access_token,与基础支持中的access_token不同。公众号可通过下述接口来获取网页授权access_token。如果网页授权的作用域为snsapi_base,则本步骤中获取到网页授权access_token的同时,也获取到了openid,snsapi_base式的网页授权流程即到此为止。
# 首先请注意,这里通过code换取的网页授权access_token,与基础支持中的access_token不同。公众号可通过下述接口来获取网页授权access_token。如果网页授权的作用域为snsapi_base,则本步骤中获取到网页授权access_token的同时,也获取到了openid,snsapi_base式的网页授权流程即到此为止。
...
@@ -33,6 +39,12 @@ module WeixinAuthorize
...
@@ -33,6 +39,12 @@ module WeixinAuthorize
WeixinAuthorize
.
http_get_without_token
(
"/sns/userinfo?access_token=
#{
oauth_token
}
&openid=
#{
openid
}
&lang=
#{
lang
}
"
,
{},
"api"
)
WeixinAuthorize
.
http_get_without_token
(
"/sns/userinfo?access_token=
#{
oauth_token
}
&openid=
#{
openid
}
&lang=
#{
lang
}
"
,
{},
"api"
)
end
end
private
def
encode_url
(
uri
)
ERB
::
Util
.
url_encode
(
uri
)
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment