分享内容时改为用户信息授权方式

This commit is contained in:
yuanke 2016-08-12 10:40:36 +08:00
parent 64eacc2d5e
commit 5c42cdb39c
5 changed files with 23 additions and 4 deletions

View File

@ -26,7 +26,14 @@ module Mobile
login = openid[0..10]+openid[openid_length-3..openid_length-1]
name = openid[0..3]+"***"+openid.last
access_token = session[:access_token]
if access_token
userinfo = wechat.web_userinfo(access_token,openid)
name = userinfo[:nickname]
else
name = openid[0..3]+"***"+openid.last
end
user = us.register ({:login=>login, :mail=>login+"@163.com",
:password=>"12345678", :password_confirmation=>"12345678",

View File

@ -67,7 +67,6 @@ module Mobile
user[:password] = params[:password]
user[:password_confirmation] = params[:password]
user[:should_confirmation_password] = true
user[:lastname]=""
user.save!
else
us = UsersService.new

View File

@ -445,6 +445,10 @@ class WechatsController < ActionController::Base
unless openid
if code
openid = wechat.web_access_token(code)["openid"]
access_token = wechat.web_access_token(code)["access_token"]
if access_token
session[:access_token] = access_token
end
end
end

View File

@ -120,5 +120,14 @@ module Wechat
}
get 'access_token', params: params, base: OAUTH2_BASE
end
def web_userinfo(access_token,openid)
params = {
access_token: access_token,
openid: openid,
lang: "zh_CN"
}
get 'user_info', params: params, base: OAUTH2_BASE
end
end
end

View File

@ -268,12 +268,12 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc
var urlName = response.data.type_name + "_discussion";
link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid +
"&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+response.data.data.act_id+
"&response_type=code&scope=snsapi_base&state="+urlName+"&connect_redirect=1#wechat_redirect";
"&response_type=code&scope=snsapi_userinfo&state="+urlName+"&connect_redirect=1#wechat_redirect";
}
else{
link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid +
"&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+response.data.data.act_id+
"&response_type=code&scope=snsapi_base&state="+args.urlName+"&connect_redirect=1#wechat_redirect";
"&response_type=code&scope=snsapi_userinfo&state="+args.urlName+"&connect_redirect=1#wechat_redirect";
}
console.log("link= "+link);