Module: LanxinOpen::Platform

Included in:
OpenPlatformV1
Defined in:
lib/lanxin_open/openplatform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/lanxin_open/openplatform.rb', line 6

def host
  @host
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/lanxin_open/openplatform.rb', line 6

def port
  @port
end

#skeyObject

Returns the value of attribute skey.



5
6
7
# File 'lib/lanxin_open/openplatform.rb', line 5

def skey
  @skey
end

#use_new_jsonObject

Returns the value of attribute use_new_json.



6
7
8
# File 'lib/lanxin_open/openplatform.rb', line 6

def use_new_json
  @use_new_json
end

Instance Method Details

#content_utf8(content, source_charset = "gbk") ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/lanxin_open/openplatform.rb', line 27

def content_utf8(content,source_charset="gbk")
  return content unless source_charset
  begin
    # converter = Iconv.new 'UTF-8//IGNORE', source_charset
    converter = Iconv.new 'UTF-8', source_charset
    utf8_str = converter.iconv content
  rescue Exception => e
    return content
  end
end

#dump_configObject



8
9
10
# File 'lib/lanxin_open/openplatform.rb', line 8

def dump_config
  puts "test_config #{host}, #{port}, #{use_new_json}"
end

#encode_resbody(body) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lanxin_open/openplatform.rb', line 38

def encode_resbody(body)
  source_charsets = ["gbk","gb2312"]
  i = 0
  begin
    gbk = body.encode("utf-8", source_charsets[i])
    return gbk
  rescue Exception => e
    if i < source_charsets.length
      i +=1
      retry
    end
  end
  gbk = content_utf8(body,"gbk")
end

#fetch_skey(token, devkey) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/lanxin_open/openplatform.rb', line 53

def fetch_skey(token,devkey)
  req_url = lx_url("/opc/ishow")
  params = {
    "p_id"   => "131",
    "t_id"   => "18", 
    "d_id"   => "1",
    "url"    => "/logintoskey.html", 
    "token"  => token,
    "devkey" => devkey
  }
  # body = encode_resbody(NetUtil.post_req(req_url,params).body)
  begin
    body = encode_resbody(NetUtil.post_req(req_url,params).body)
    puts body
    ret = JSON.parse(body.to_s)
    if ret["state"] == "OK"
      @skey= ret["sessionKey"]
    end
  rescue
  end
end

#host_with_portObject



12
13
14
15
16
17
18
# File 'lib/lanxin_open/openplatform.rb', line 12

def host_with_port
  if port and port.length > 0
    "#{host}:#{port}"
  else
    host
  end
end

#lx_url(path) ⇒ Object



20
21
22
23
24
25
# File 'lib/lanxin_open/openplatform.rb', line 20

def lx_url(path)
  unless path.start_with?("/")
    path = "/" + path
  end
  "#{host_with_port}#{path}"
end

#member_get(org_id, open_id) ⇒ Object

new interface use UTF-8 charset



76
77
78
79
80
81
82
83
84
# File 'lib/lanxin_open/openplatform.rb', line 76

def member_get(org_id,open_id)
  req_url = lx_url("cgi-bin/member/get")
  params = {
    "access_token" => skey,
    "orgId" => org_id,
    "mobile" => open_id,
  }
  body = NetUtil.post_req(req_url,params).body
end

#org_get(org_id, struct_id, query_type) ⇒ Object

new interface use UTF-8 charset query_type:

0:get struct node;  1: get user node;  -1:get all node


89
90
91
92
93
94
95
96
97
98
# File 'lib/lanxin_open/openplatform.rb', line 89

def org_get(org_id,struct_id,query_type)
  req_url = lx_url("cgi-bin/org/struct/parent/get")
  params = {
    "access_token" => skey,
    "orgId" => org_id,
    "structId" => struct_id,
    "orgStructType" => query_type
  }
  body = NetUtil.post_req(req_url,params).body
end