lanxin_open 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDYyZmM5MjQzOTA2NGViZTQ4ZWRhOTcwMTY3NzJiZTAxNmEyZWMyYw==
5
+ data.tar.gz: !binary |-
6
+ ODM3NTRlM2FlNTg0YWZjMTQ2MmNkNWU2NjQ3OTUwMjlhYjliNGRmNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDg3MTZlY2ZlZjFmYzAxMGQ5NGQwZjkzMTNmZjcwNzBhMjFiYTNhM2MxYjhk
10
+ MjQyNjczNzg2M2Q0YmNjNWZlNjhmOTIyYjFhMWQ4ZWU4YTRkYmUyZmM0MTA2
11
+ YjhiZjk1YWZlZGI0ZDYxOTMyYjM0MDFhOGQ3YzdjZDQ3NTUwZmQ=
12
+ data.tar.gz: !binary |-
13
+ MTQ0ZmE5ZGQ1YjY0MzJmM2IzYzQxODA1OGU0MjEzYWU2NDkzMjE3YTcwN2Rk
14
+ OTBhMzBlY2Y1MTc0MTI3NDgzNTM0M2EyN2ZmOGQ1ODg2MWQ3NDBkZjliZDgz
15
+ MTM1ZDdiMzg3ZGRjM2Q2NDIzZjlhZWRkYTAyZWU3NzIyODdhNjM=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lanxin_open.gemspec
4
+ gemspec
5
+
6
+ gem "addressable"
7
+ gem "json"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 wangdean
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # LanxinOpen
2
+
3
+ Lanxin is Real-time communication application for enterprise internal communicate,with full client support,including Android, iOS, Windows,Mac,Web etc.The Openplatform give the thirdpart company provide service through Lanxin.More information please refer to http://lanxin.cn.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'lanxin_open'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install lanxin_open
18
+
19
+ ## Usage
20
+
21
+ configure the LanxinOpen while init,like following code;
22
+ ```
23
+ LanxinOpen.config do
24
+ host "https://open-dev.lanxin.cn" #"http://118.192.68.146"
25
+ port ""
26
+ use_new_json true
27
+ end
28
+ ```
29
+ then while you want to call the interface,call like this
30
+ ```
31
+ open = LanxinOpen.new
32
+ skey = open.fetch_skey("token","devkey")
33
+ puts "fetch skey: #{skey}"
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/[my-github-username]/lanxin_open/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lanxin_open/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lanxin_open"
8
+ spec.version = LanxinOpen::VERSION
9
+ spec.authors = ["wangdean"]
10
+ spec.email = ["bjkjdxwda@126.com","wangdean@comisys.net"]
11
+ spec.summary = %q{Lanxin Openplatform ruby sdk.}
12
+ spec.description = %q{Lanxin is Real-time communication application for enterprise internal communicate,with full client support,including Android, iOS, Windows,Mac,Web etc.The Openplatform give the thirdpart company provide service through Lanxin.More information please refer to http://lanxin.cn.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,3 @@
1
+ module LanxinOpen
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,321 @@
1
+ require "lanxin_open/version"
2
+ require 'uri'
3
+ require "json"
4
+ require 'addressable/uri'
5
+ require 'net/https'
6
+
7
+ module LanxinOpen
8
+ extend self
9
+
10
+ def self.parameter(*names)
11
+ names.each do |name|
12
+ attr_accessor name
13
+ # For each given symbol we generate accessor method that sets option's
14
+ # value being called with an argument, or returns option's current value
15
+ # when called without arguments
16
+ define_method name do |*values|
17
+ value = values.first
18
+ value ? self.send("#{name}=", value) : instance_variable_get("@#{name}")
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.config(&block)
24
+ instance_eval &block
25
+ end
26
+
27
+ def self.new
28
+ OpenPlatformV1.new
29
+ end
30
+
31
+ def self.dean_hash2xml(p_hash)
32
+ # return nil if (not p_hash) or p_hash.length <= 0
33
+ no_cdata_key = ["CreateTime","MsgId"]
34
+ line_break = "" #"\n"
35
+ xml_str = "<xml>#{line_break}"
36
+ p_hash.each do |k,v|
37
+ if no_cdata_key.include?(k)
38
+ xml_str += "<#{k}>#{v}</#{k}>#{line_break}"
39
+ else
40
+ xml_str += "<#{k}><![CDATA[#{v}]]></#{k}>#{line_break}"
41
+ end
42
+ end
43
+ xml_str += "</xml>"
44
+ end
45
+
46
+ def self.hash_to_xml(p_hash)
47
+ # return nil if (not p_hash) or p_hash.length <= 0
48
+ return dean_hash2xml(p_hash)
49
+ end
50
+
51
+ def self.parse_callback_xml(msgcontent)
52
+ begin
53
+ hash = Hash.from_xml(msgcontent)
54
+ xml_node = hash["xml"]
55
+ return xml_node
56
+ rescue
57
+ end
58
+ end
59
+
60
+ class NetUtil
61
+ def self.get_req(url)
62
+ return nil if not url
63
+ #Rails.logger.info("get_req request url:#{url}")
64
+ uri = URI(url)
65
+
66
+ https = Net::HTTP.new(uri.host, uri.port)
67
+ #just for now.FIXME
68
+ if uri.scheme == 'https'
69
+ https.use_ssl = true
70
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
71
+ end
72
+ response = https.get(uri.request_uri)
73
+ end
74
+
75
+ def self.dict2urlparam(params)
76
+ return if not params
77
+ uri = Addressable::URI.new
78
+ uri.query_values = params
79
+ uri.query
80
+ end
81
+
82
+ def self.force_encode(params,encoding_name)
83
+ params.each do |k,v|
84
+ if v.class == String #and v.encoding.name == "UTF-8"
85
+ begin
86
+ v_gbk = v.encode(encoding_name)
87
+ params[k] = v_gbk
88
+ rescue
89
+ end
90
+ end
91
+ end
92
+ return params
93
+ end
94
+
95
+ def self.post_req(url,params)
96
+ return if not url
97
+ uri = URI.parse(url)
98
+
99
+ need_uri_encode = false
100
+ if need_uri_encode
101
+ params.each do |k,v|
102
+ params[k] = URI.encode(v)
103
+ end
104
+ end
105
+
106
+ https = Net::HTTP.new(uri.host,uri.port)
107
+ if uri.scheme == 'https'
108
+ https.use_ssl = true
109
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
110
+ end
111
+ req = Net::HTTP::Post.new(uri.path)
112
+ req.set_form_data(params)
113
+ response = https.request(req)
114
+ end
115
+ end
116
+
117
+ module Platform
118
+ attr_accessor :skey
119
+
120
+ def dump_config
121
+ puts "test_config #{LanxinOpen.host}, #{LanxinOpen.port}, #{LanxinOpen.use_new_json}"
122
+ end
123
+
124
+ def host_with_port
125
+ "#{LanxinOpen.host}:#{LanxinOpen.port}"
126
+ end
127
+
128
+ def lx_url(path)
129
+ unless path.start_with?("/")
130
+ path = "/" + path
131
+ end
132
+ "#{host_with_port}#{path}"
133
+ end
134
+
135
+ def content_utf8(content,source_charset="gbk")
136
+ return content unless source_charset
137
+ begin
138
+ # converter = Iconv.new 'UTF-8//IGNORE', source_charset
139
+ converter = Iconv.new 'UTF-8', source_charset
140
+ utf8_str = converter.iconv content
141
+ rescue Exception => e
142
+ return content
143
+ end
144
+ end
145
+
146
+ def encode_resbody(body)
147
+ source_charsets = ["gbk","gb2312"]
148
+ i = 0
149
+ begin
150
+ gbk = body.encode("utf-8", source_charsets[i])
151
+ return gbk
152
+ rescue Exception => e
153
+ if i < source_charsets.length
154
+ i +=1
155
+ retry
156
+ end
157
+ end
158
+ gbk = content_utf8(body,"gbk")
159
+ return gbk
160
+ end
161
+
162
+ def fetch_skey(token,devkey)
163
+ req_url = lx_url("/opc/ishow")
164
+ params = {
165
+ "p_id" => "131",
166
+ "t_id" => "18",
167
+ "d_id" => "1",
168
+ "url" => "/logintoskey.html",
169
+ "token" => token,
170
+ "devkey" => devkey
171
+ }
172
+ # body = encode_resbody(NetUtil.post_req(req_url,params).body)
173
+ begin
174
+ body = encode_resbody(NetUtil.post_req(req_url,params).body)
175
+ ret = JSON.parse(body.to_s)
176
+ if ret["state"] == "OK"
177
+ @skey= ret["sessionKey"]
178
+ end
179
+ rescue
180
+ end
181
+ end
182
+
183
+ #new interface use UTF-8 charset
184
+ def member_get(org_id,open_id)
185
+ req_url = lx_url("cgi-bin/member/get")
186
+ params = {
187
+ "access_token" => skey,
188
+ "orgId" => org_id,
189
+ "mobile" => open_id,
190
+ }
191
+ body = NetUtil.post_req(req_url,params).body
192
+ end
193
+
194
+ #new interface use UTF-8 charset
195
+ # query_type:
196
+ # 0:get struct node; 1: get user node; -1:get all node
197
+ def org_get(org_id,struct_id,query_type)
198
+ req_url = lx_url("cgi-bin/org/struct/parent/get")
199
+ params = {
200
+ "access_token" => skey,
201
+ "orgId" => org_id,
202
+ "structId" => struct_id,
203
+ "orgStructType" => query_type
204
+ }
205
+ body = NetUtil.post_req(req_url,params).body
206
+ end
207
+
208
+ end
209
+
210
+ class OpenPlatformV1
211
+ include Platform
212
+
213
+ def kehu_msg(fieldvalue,from_user)
214
+ req_url = lx_url("/opc/ishow")
215
+ params = {
216
+ "p_id" => "131",
217
+ "t_id" => "5",
218
+ "d_id" => "0",
219
+ "url" => "/customermessage/${docid}.shtml",
220
+ "skey" => skey,
221
+ "_fieldvalue_msgcontent" => fieldvalue.to_json
222
+ }
223
+ body = encode_resbody(NetUtil.post_req(req_url,params).body)
224
+ end
225
+
226
+ def send_text_msg(txt_msg,open_id,from_user)
227
+ text_json = {"content" => txt_msg}
228
+ base_json = {
229
+ "ToUserName" => open_id,
230
+ "FromUserName" => from_user,
231
+ "msgtype" => "text",
232
+ "text" => text_json.to_json
233
+ }
234
+ base_json["text"] = text_json if LanxinOpen.use_new_json
235
+ body = kehu_msg(base_json,from_user)
236
+ end
237
+
238
+ def send_link_msg(url,open_id,from_user)
239
+ base_json = {
240
+ "ToUserName" => open_id,
241
+ "FromUserName" => from_user,
242
+ "msgtype" => "link",
243
+ "url" => url
244
+ }
245
+ body = kehu_msg(base_json,from_user)
246
+ return body
247
+ end
248
+
249
+ def send_pictext_msg(url,open_id,title,from_user)
250
+ news_json = {"url" => url}
251
+ base_json = {
252
+ "ToUserName" => open_id,
253
+ "FromUserName" => from_user,
254
+ "msgtype" => "news",
255
+ "title" => title,
256
+ "news" => news_json
257
+ }
258
+ # base_json["news"] = news_json if LanxinOpen.use_new_json
259
+ body = kehu_msg(base_json,from_user)
260
+ return body
261
+ end
262
+
263
+ def send_mail_msg(url,open_id,title,from_user)
264
+ news_json = {"url" => url}
265
+ base_json = {
266
+ "ToUserName" => open_id,
267
+ "FromUserName" => from_user,
268
+ "msgtype" => "mail",
269
+ "news" => news_json,
270
+ "title" => title
271
+ }
272
+ body = kehu_msg(base_json,from_user)
273
+ end
274
+
275
+ def create_menu(menu_json)
276
+ params = {
277
+ "p_id" => 131,
278
+ "t_id" => 15,
279
+ "d_id" => 1,
280
+ "url" => "/insert_menu.shtml",
281
+ "menucontent" => menu_json.to_json,
282
+ "skey" => skey
283
+ }
284
+ req_url = lx_url("/opc/ishow")
285
+ body = encode_resbody(NetUtil.post_req(req_url,params).body)
286
+ end
287
+
288
+ def show_menu(publicno)
289
+ params = {
290
+ "p_id" => 131,
291
+ "t_id" => 16,
292
+ "d_id" => 1,
293
+ "url" => "/query_menu.shtml",
294
+ "publicno" => publicno
295
+ }
296
+ req_url = lx_url("/opc/ishow")
297
+ body = encode_resbody(NetUtil.post_req(req_url,params).body)
298
+ end
299
+
300
+ def del_menu
301
+ req_url = lx_url("/opc/ishow")
302
+ params = {
303
+ "p_id" => 131,
304
+ "t_id" => 17,
305
+ "d_id" => 1,
306
+ "url" => "/delmenu.shtml",
307
+ "skey" => skey
308
+ }
309
+ body = encode_resbody(NetUtil.post_req(req_url,params).body)
310
+ end
311
+
312
+ end
313
+
314
+ end
315
+
316
+ LanxinOpen.config do
317
+ parameter :host, :port
318
+ parameter :use_new_json
319
+ end
320
+
321
+
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lanxin_open
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - wangdean
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Lanxin is Real-time communication application for enterprise internal
42
+ communicate,with full client support,including Android, iOS, Windows,Mac,Web etc.The
43
+ Openplatform give the thirdpart company provide service through Lanxin.More information
44
+ please refer to http://lanxin.cn.
45
+ email:
46
+ - bjkjdxwda@126.com
47
+ - wangdean@comisys.net
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - lanxin_open.gemspec
58
+ - lib/lanxin_open.rb
59
+ - lib/lanxin_open/version.rb
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.1.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Lanxin Openplatform ruby sdk.
84
+ test_files: []