获取未关注修改

This commit is contained in:
yuanke 2016-08-14 09:50:43 +08:00
parent 8ab003d5ee
commit 4eec1f5d4e
1 changed files with 23 additions and 16 deletions

View File

@ -57,23 +57,30 @@ module Mobile
subscribe = 0 #默认未关注 subscribe = 0 #默认未关注
#-------------------获取用户是否关注此公众号----------------------------- #-------------------获取用户是否关注此公众号-----------------------------
access_token = session[:access_token] openid = session[:wechat_openid]
refresh_token = session[:refresh_token] raise "无法获取到openid,请在微信中打开本页面" unless openid
user_info = Wechat.api.user(openid)
Rails.logger.info "user_info!!!!!!!!!"
Rails.logger.info user_info
subscribe = user_info["subscribe"]
if access_token.present? && refresh_token.present? # access_token = session[:access_token]
refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) # refresh_token = session[:refresh_token]
#
access_token = refreshinfo["access_token"] # if access_token.present? && refresh_token.present?
refresh_token = refreshinfo["refresh_token"] # refreshinfo = Wechat.api.web_refresh_access_token(refresh_token)
session[:access_token] = access_token #
session[:refresh_token] = refresh_token # access_token = refreshinfo["access_token"]
# refresh_token = refreshinfo["refresh_token"]
#获取用户信息 # session[:access_token] = access_token
user_info = Wechat.api.web_user_info(access_token,openid) # session[:refresh_token] = refresh_token
Rails.logger.info "user_info!!!!!!!!!" #
Rails.logger.info user_info # #获取用户信息
subscribe = user_info["subscribe"] # user_info = Wechat.api.web_user_info(access_token,openid)
end # Rails.logger.info "user_info!!!!!!!!!"
# Rails.logger.info user_info
# subscribe = user_info["subscribe"]
# end
status = 0 status = 0
tip = 0 #0班级1项目 tip = 0 #0班级1项目