Module: Wechat::Responder

Extended by:
ActiveSupport::Concern
Includes:
Cipher, ControllerApi
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

Methods included from ControllerApi

#wechat, #wechat_oauth2

Instance Method Details

#createObject



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/wechat/responder.rb', line 193

def create
  request_msg = Wechat::Message.from_hash(post_xml)
  response_msg = run_responder(request_msg)

  if response_msg.respond_to? :to_xml
    if Rails::VERSION::MAJOR >= 4
      render plain: process_response(response_msg)
    else
      render text: process_response(response_msg)
    end
  else
    head :ok, content_type: 'text/html'
  end

  response_msg.save_session if response_msg.is_a?(Wechat::Message) && Wechat.config.have_session_class

  ActiveSupport::Notifications.instrument 'wechat.responder.after_create', request: request_msg, response: response_msg
end

#showObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/wechat/responder.rb', line 176

def show
  if @we_corpid.present?
    echostr, _corp_id = unpack(decrypt(Base64.decode64(params[:echostr]), @we_encoding_aes_key))
    if Rails::VERSION::MAJOR >= 4
      render plain: echostr
    else
      render text: echostr
    end
  else
    if Rails::VERSION::MAJOR >= 4
      render plain: params[:echostr]
    else
      render text: params[:echostr]
    end
  end
end