module LanxinOpen::Platform
Attributes
host[RW]
port[RW]
skey[RW]
use_new_json[RW]
Public Instance Methods
content_utf8(content,source_charset="gbk")
click to toggle source
# 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_config()
click to toggle source
# File lib/lanxin_open/openplatform.rb, line 8 def dump_config puts "test_config #{host}, #{port}, #{use_new_json}" end
encode_resbody(body)
click to toggle source
# 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)
click to toggle source
# 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_port()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
new interface use UTF-8 charset
# 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)
click to toggle source
new interface use UTF-8 charset
query_type: 0:get struct node; 1: get user node; -1:get all node
# 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