diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 2c5ab7754..63d476601 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -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", diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 19cce07e7..30e4cc1f9 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -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 diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 75ac7aba5..e1fa7dcc2 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -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 diff --git a/lib/wechat/lib/wechat/api.rb b/lib/wechat/lib/wechat/api.rb index 5cb457b9f..f1255939a 100644 --- a/lib/wechat/lib/wechat/api.rb +++ b/lib/wechat/lib/wechat/api.rb @@ -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 diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index f0d48dda9..19acf39c9 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -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);