Class: WeChat::Bot::HTTP::MimeType::JS

Inherits:
HTTP::MimeType::Adapter
  • Object
show all
Defined in:
lib/wechat/bot/http/adapter/js.rb

Overview

Javascript 代码解析 用于解析微信 API 返回的部分 JS 代码, 提示:不可逆转

Instance Method Summary collapse

Instance Method Details

#decode(str) ⇒ Hash

转换 JS 代码为 Hash

Returns:

  • (Hash)


19
20
21
22
23
24
25
26
# File 'lib/wechat/bot/http/adapter/js.rb', line 19

def decode(str)
  str.split("window.").each_with_object({}) do |item, obj|
    key, value = item.split(/\s*=\s*/, 2)
    next unless key || value
    key = key.split(".")[-1]
    obj[key] = eval(value)
  end
end

#encode(_) ⇒ Object

Encodes object to js



12
13
14
# File 'lib/wechat/bot/http/adapter/js.rb', line 12

def encode(_)
  "" # NO NEED encode
end