Class: Wechat::PlatformsController

Inherits:
BaseController show all
Defined in:
app/controllers/wechat/platforms_controller.rb

Instance Method Summary collapse

Instance Method Details

#callbackObject



23
24
25
26
27
28
# File 'app/controllers/wechat/platforms_controller.rb', line 23

def callback
  @auth = @platform.auths.build
  @auth.auth_code = params[:auth_code]
  @auth.auth_code_expires_at = Time.current + params[:expires_in].to_i
  @auth.save
end

#messageObject

消息与事件接收URL: platforms/:id/callback/$APPID$



31
32
33
34
35
36
37
38
39
# File 'app/controllers/wechat/platforms_controller.rb', line 31

def message
  @receive = @platform.receives.build
  @receive.appid = params[:appid]
  r = Hash.from_xml(request.body.read)['xml']
  @receive.encrypt_data = r['Encrypt']
  @receive.save

  render plain: @receive.request.to_wechat
end

#notifyObject

授权事件接收URL: platforms/notice



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/wechat/platforms_controller.rb', line 7

def notify
  @ticket = Ticket.new(ticket_params)
  r = Hash.from_xml(request.raw_post)['xml']
  @ticket.appid = r['AppId']
  @ticket.ticket_data = r['Encrypt']

  if @ticket.save
    render plain: 'success'
  else
    head :no_content
  end
end

#showObject



20
21
# File 'app/controllers/wechat/platforms_controller.rb', line 20

def show
end