diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 6e6cf1c63..41653faf9 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -107,6 +107,7 @@ class WechatsController < ActionController::Base end on :event, with: 'unsubscribe' do |request| + unBind(request) request.reply.success # user can not receive this message end @@ -274,12 +275,17 @@ class WechatsController < ActionController::Base end end + def unBind(request) + uw = user_binded?(request[:FromUserName]) + uw.try(:subscribe!) + end + def sendBind(request) tmpurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=login&connect_redirect=1#wechat_redirect" logger.info "tmpurl!!!!!!!!!!!!!!" logger.info tmpurl news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "欢迎使用Trustie创新实践服务平台! -在这里您可以随时了解您的课程和项目动态,随时点赞和回复。 +在这里您可以随时了解您的课程和项目动态,随时点赞和回复。交作业、代码提交等更多功能,请前往 www.trustie.net 我们将会与微信不断结合,为您提供更有价值的服务。 您还未绑定确实的用户,请先绑定,谢谢!" } } diff --git a/app/models/user_wechat.rb b/app/models/user_wechat.rb index c63411ab3..71221a3d1 100644 --- a/app/models/user_wechat.rb +++ b/app/models/user_wechat.rb @@ -24,4 +24,9 @@ class UserWechat < ActiveRecord::Base BlogComment.where(author_id: old_user).update_all(author_id: u.id) UserActivity.where(user_id: old_user).update_all(user_id: u.id) end + + + def unsubscribe! + self.delete + end end