Module: EricWeixin::Snsapi
- Defined in:
- lib/eric_weixin/modules/snsapi.rb
Class Method Summary collapse
-
.get_snsapi_base_url(options) ⇒ Object
获取snsapi_base授权的完整链接.
-
.get_snsapi_userinfo_url(options) ⇒ Object
获取snsapi_userinfo授权的完整链接.
Class Method Details
.get_snsapi_base_url(options) ⇒ Object
获取snsapi_base授权的完整链接. 每次更新菜单调整链接都需要花时间把链接整理好,再URLEncode之类的,很烦有木不? 来这里吧,输入几个无脑参数,分分钟获取到全链接,方便、快速、搞得定。 善意提醒:别说这里有个坑,这个函数生成的链接,是需要配合本Gem的Controller、action来使用的。
参数说明
-
url #业务URL,即最终需要跳转到的url,域名中的主机名称可选,可以写 ‘www.baidu.com/xxx’, 也可以写 ‘/xxx’。 这个地址用于最后重定向。
-
app_id #公众账号app_id
-
schema_host 当前项目的域名(包含http://):如www.baidu.com
-
state 这个参数可以直接带到业务页面。
调用示例
EricWeixin::Snsapi.get_snsapi_base_url url:‘/eric_weixin/weixin/orders?a=1’, app_id: ‘wxaa334fd34be16fca’, schema_host: “www.uguoyuan.cn”
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/eric_weixin/modules/snsapi.rb', line 14 def self.get_snsapi_base_url require 'base64' p_zhongzhuan = [] p_zhongzhuan_host_path = "#{[:schema_host]}/eric_weixin/weixin/snsapi" p_zhongzhuan << ["weixin_app_id", [:app_id]] p_zhongzhuan << ["url", Base64.encode64([:url]).gsub(/\n/,'')] p_zhongzhuan = URI.encode_www_form p_zhongzhuan p_zhongzhuan = CGI::unescape p_zhongzhuan p_zhongzhuan_url = [p_zhongzhuan_host_path, p_zhongzhuan].join('?') p_host_and_path = 'https://open.weixin.qq.com/connect/oauth2/authorize' p = [] p << ['appid', [:app_id]] p << ['redirect_uri', CGI::escape(p_zhongzhuan_url)] p << ['response_type', 'code'] p << ['scope', 'snsapi_base'] p << ['state', "#{[:state]||'abc'}"] p = URI.encode_www_form p p = CGI::unescape p p_url = [p_host_and_path, "#{p}#wechat_redirect"].join '?' p_url end |
.get_snsapi_userinfo_url(options) ⇒ Object
获取snsapi_userinfo授权的完整链接. 每次更新菜单调整链接都需要花时间把链接整理好,再URLEncode之类的,很烦有木不? 来这里吧,输入几个无脑参数,分分钟获取到全链接,方便、快速、搞得定。 善意提醒:别说这里有个坑,这个函数生成的链接,是需要配合本Gem的Controller、action来使用的。
参数说明
-
url #业务URL,即最终需要跳转到的url,域名中的主机名称可选,可以写 ‘www.baidu.com/xxx’, 也可以写 ‘/xxx’。 这个地址用于最后重定向。
-
app_id #公众账号app_id
-
schema_host 当前项目的域名(包含http://):如www.baidu.com
-
state 这个参数可以直接带到业务页面。
调用示例
EricWeixin::Snsapi.get_snsapi_userinfo_url url:'/weixin/service1/ddd?a=1', app_id: 'wx51729870d9012531', schema_host: "http://lxq.mdcc.club"
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/eric_weixin/modules/snsapi.rb', line 50 def self.get_snsapi_userinfo_url require 'base64' p_zhongzhuan = [] p_zhongzhuan_host_path = "#{[:schema_host]}/eric_weixin/weixin/snsuserinfo" p_zhongzhuan << ["weixin_app_id", [:app_id]] p_zhongzhuan << ["url", Base64.encode64([:url]).gsub(/\n/,'')] p_zhongzhuan = URI.encode_www_form p_zhongzhuan p_zhongzhuan = CGI::unescape p_zhongzhuan p_zhongzhuan_url = [p_zhongzhuan_host_path, p_zhongzhuan].join('?') p_host_and_path = 'https://open.weixin.qq.com/connect/oauth2/authorize' p = [] p << ['appid', [:app_id]] p << ["redirect_uri", CGI::escape(p_zhongzhuan_url)] p << ['response_type', 'code'] p << ['scope', 'snsapi_userinfo'] p << ['state', "#{[:state]||'state'}"] p = URI.encode_www_form p p = CGI::unescape p p_url = [p_host_and_path, "#{p}#wechat_redirect"].join '?' p_url end |