Class: Wechat::WechatsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/wechat/wechats_controller.rb', line 16

def create
  r = Hash.from_xml(request.raw_post).fetch('xml', {})
  @receive = @app.receives.build
  if r['Encrypt']
    @receive.encrypt_data = r['Encrypt']
  else
    @receive.message_hash = r
  end
  @receive.save

  render plain: @receive.request.to_wechat
end

#showObject



7
8
9
10
11
12
13
14
# File 'app/controllers/wechat/wechats_controller.rb', line 7

def show
  if @app.is_a?(WorkApp)
    echostr, _corp_id = Cipher.unpack(Cipher.decrypt(Base64.decode64(params[:echostr]), @app.encoding_aes_key))
    render plain: echostr
  else
    render plain: params[:echostr]
  end
end