Module: Wechat::Responder

Extended by:
ActiveSupport::Concern
Includes:
Cipher
Defined in:
lib/wechat/responder.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from Cipher

Cipher::BLOCK_SIZE, Cipher::CIPHER

Instance Method Summary collapse

Methods included from Cipher

#decrypt, #encrypt, #pack, #unpack

Instance Method Details

#createObject



101
102
103
104
105
106
107
108
109
110
# File 'lib/wechat/responder.rb', line 101

def create
  request = Wechat::Message.from_hash(post_xml)
  response = run_responder(request)

  if response.respond_to? :to_xml
    render xml: process_response(response)
  else
    render nothing: true, status: 200, content_type: 'text/html'
  end
end

#showObject



92
93
94
95
96
97
98
99
# File 'lib/wechat/responder.rb', line 92

def show
  if self.class.corpid.present?
    echostr, _corp_id = unpack(decrypt(Base64.decode64(params[:echostr]), self.class.encoding_aes_key))
    render text: echostr
  else
    render text: params[:echostr]
  end
end

#wechatObject



88
89
90
# File 'lib/wechat/responder.rb', line 88

def wechat
  self.class.wechat # Make sure user can continue access wechat at instance level similar to class level
end