修改微信个人信息获取实现
This commit is contained in:
parent
88e23dca80
commit
3130296e69
|
@ -20,37 +20,11 @@ module Mobile
|
|||
openid = session[:wechat_openid]
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
us = UsersService.new
|
||||
#login mail password
|
||||
|
||||
#根据openid生成一个用户名
|
||||
openid_length = openid.length
|
||||
login = openid[0..10]+openid[openid_length-3..openid_length-1]+Time.now.to_i.to_s
|
||||
userinfo = Wechat.api.user(openid)
|
||||
name = userinfo["nickname"]
|
||||
|
||||
access_token = session[:access_token]
|
||||
refresh_token = session[:refresh_token]
|
||||
|
||||
Rails.logger.info "session!!!!!!!!!"
|
||||
Rails.logger.info session
|
||||
|
||||
if access_token && refresh_token
|
||||
|
||||
#先刷新下access_token 已防止过期
|
||||
refreshinfo = Wechat.api.web_refresh_access_token(refresh_token)
|
||||
access_token = refreshinfo["access_token"]
|
||||
refresh_token = refreshinfo["refresh_token"]
|
||||
session[:access_token] = access_token
|
||||
session[:refresh_token] = refresh_token
|
||||
|
||||
#获取用户信息
|
||||
userinfo = Wechat.api.web_userinfo(access_token,openid)
|
||||
Rails.logger.info "userinfo!!!!!!!!!"
|
||||
Rails.logger.info userinfo
|
||||
name = userinfo["nickname"]
|
||||
else
|
||||
name = openid[0..3]+"***"+openid.last
|
||||
end
|
||||
|
||||
user = us.register ({:login=>login, :mail=>login+"@163.com",
|
||||
user = us.register ({:login=>openid, :mail=>login+"@163.com",
|
||||
:password=>"12345678", :password_confirmation=>"12345678",
|
||||
:should_confirmation_password => true})
|
||||
|
||||
|
|
5035
db/schema.rb
5035
db/schema.rb
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue