微信增加解除绑定功能

This commit is contained in:
yuanke 2016-09-05 11:02:34 +08:00
parent 92ae8865f0
commit 10017d2c69
4 changed files with 33 additions and 3 deletions

View File

@ -167,6 +167,27 @@ class WechatsController < ActionController::Base
end
end
on :click, with: 'UNBIND' do |request, key|
uw = user_binded?(request[:FromUserName])
unless uw
request.reply.text "您还未绑定帐号"
else
#解除绑定
us = UsersService.new
us.wechat_unbind uw
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"
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '重新绑定提醒',
content: "尊敬的用户,您已解除绑定。\n解除时间:#{format_time(Time.now)}\n点击进入重新绑定!"} }
request.reply.news(news) do |article, n, index| # article is return object
url = tmpurl
article.item title: "#{n[:title]}",
description: n[:content],
url: url
end
end
end
def join_class_request(request)
openid = request[:FromUserName]
wl = WechatLog.where("openid = '#{openid}' and request_raw like '%\"Event\":\"click\"%'").order('id desc').first

View File

@ -319,8 +319,9 @@ class UsersService
my_jours_arr
end
def wechat_unbind uw
uw.user_id = nil
uw.delete
end
end

View File

@ -30,3 +30,7 @@ button:
type: "click"
name: "联系我们"
key: "FEEDBACK"
-
type: "click"
name: "解除绑定"
key: "UNBIND"

View File

@ -30,3 +30,7 @@ button:
type: "click"
name: "联系我们"
key: "FEEDBACK"
-
type: "click"
name: "解除绑定"
key: "UNBIND"