diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 84cf2ef93..eda51ec0d 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -54,6 +54,27 @@ module Mobile authenticate! + subscribe = 0 #默认未关注 + + #-------------------获取用户是否关注此公众号----------------------------- + access_token = session[:access_token] + refresh_token = session[:refresh_token] + + if access_token.present? && refresh_token.present? + 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 + + #获取用户信息 + user_info = Wechat.api.web_user_info(access_token,openid) + Rails.logger.info "user_info!!!!!!!!!" + Rails.logger.info user_info + subscribe = user_info["subscribe"] + end + status = 0 tip = 0 #0班级1项目 type = params[:type] @@ -207,6 +228,7 @@ module Mobile present :result, result present :status, status present :tip, tip + present :subscribe,subscribe end end end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 4950d7041..96cec7b39 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -70,6 +70,7 @@ module Mobile raise user.errors.full_messages.first if user.new_record? if uw && !user.real? + user.update_attributes(:lastname=>uw.user[:lastname]) uw.migrate_user(user) else UserWechat.create!( diff --git a/lib/wechat/lib/wechat/api.rb b/lib/wechat/lib/wechat/api.rb index f267f8b69..a7883ffe3 100644 --- a/lib/wechat/lib/wechat/api.rb +++ b/lib/wechat/lib/wechat/api.rb @@ -139,5 +139,9 @@ module Wechat get 'userinfo', params: { access_token: web_access_token, openid: openid, lang: lang }, base: OAUTH2_USERINFO end + def web_user_info(web_access_token, openid, lang = 'zh_CN') + get 'user/info', params: { access_token: web_access_token, openid: openid, lang: lang }, base: API_BASE + end + end end diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index 229c08a63..e6ffcf76c 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -142,7 +142,7 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc data.disabled = false; if(typeof cb === 'function'){ - cb(); + cb(response.data.subscribe); } //保证内外回复数一致 @@ -301,9 +301,16 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc loadData(args.id,0,0); args.scope.addReply = function(data){ console.log(data.comment); - addCommonReply(args.id, args.replyType, data,args, function(){ + addCommonReply(args.id, args.replyType, data,args, function(subscribe){ args.scope.formData = {comment: ''}; - loadData(args.id,0,0); + if(subscribe == 0){ + $location.path("/login_tip"); + return; + } + else{ + loadData(args.id,0,0); + } + if(typeof args.replyCallback === 'function'){ args.replyCallback(); }