dianxin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +7 -0
- data/README +1 -0
- data/Rakefile +4 -0
- data/dianxin.gemspec +24 -0
- data/lib/dianxin.rb +14 -0
- data/lib/dianxin/base.rb +55 -0
- data/lib/dianxin/version.rb +3 -0
- data/test.rb +6 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2011 Scott Ballantyne, Zhang Zheng
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
you can look at test.rb for an example of how to use the lib. I would like to write some docs for this soon.
|
data/Rakefile
ADDED
data/dianxin.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dianxin/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dianxin"
|
7
|
+
s.version = Dianxin::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Scott Ballantyne", "Zhang Zheng"]
|
10
|
+
s.email = ["ussballantyne@gmail.com", "simsicon@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{gem to send text messages with china telecom}
|
13
|
+
s.description = %q{gem to integrate with sichuan china telecom}
|
14
|
+
|
15
|
+
s.rubyforge_project = "dianxin"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.add_dependency('rest-client', '>= 1.6.6')
|
22
|
+
s.add_dependency('yajl-ruby', '>= 0.8.3')
|
23
|
+
|
24
|
+
end
|
data/lib/dianxin.rb
ADDED
data/lib/dianxin/base.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Dianxin
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def initialize(apid, key, product_id)
|
5
|
+
@apid = apid
|
6
|
+
@key = key
|
7
|
+
@product_id = product_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def sms(number, message)
|
11
|
+
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
12
|
+
|
13
|
+
params = {}
|
14
|
+
params['params'] = {}
|
15
|
+
params['params']['TimeStamp'] = timestamp
|
16
|
+
params['params']['APID'] = @apid
|
17
|
+
params['params']['Key'] = encrypt(timestamp+@apid, @key);
|
18
|
+
params['params']['Num'] = number.to_s
|
19
|
+
params['params']['Msg'] = message
|
20
|
+
params['params']['IsReport'] = '0'
|
21
|
+
params['params']['StatusReportUrl'] = 'http://114.80.110.16'
|
22
|
+
params['params']['ProductID'] = @product_id
|
23
|
+
params['params']['IsUse'] = '0'
|
24
|
+
params['serviceId'] = '00001020101130';
|
25
|
+
params['params']['Parm1'] = "12"
|
26
|
+
params['params']['Parm2'] = @product_id
|
27
|
+
params['params']['Parm3'] = "56"
|
28
|
+
|
29
|
+
response = RestClient.post "http://125.64.11.43:8080/udt-see/StartServiceServlet", encode_json(params), :content_type => :json, :accept => :json
|
30
|
+
decoded_response = decode_json(response.to_s)
|
31
|
+
puts decoded_response.inspect
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def encrypt(message, key)
|
37
|
+
key = Base64.decode64(key)
|
38
|
+
cipher = OpenSSL::Cipher::Cipher.new("des-ede3")
|
39
|
+
cipher.encrypt
|
40
|
+
cipher.key = key
|
41
|
+
ciphertext = cipher.update(message) + cipher.final
|
42
|
+
Base64.encode64(ciphertext).gsub(/\n/, '')
|
43
|
+
end
|
44
|
+
|
45
|
+
def encode_json(params)
|
46
|
+
Yajl::Encoder.encode(params)
|
47
|
+
end
|
48
|
+
|
49
|
+
def decode_json(response)
|
50
|
+
parser = Yajl::Parser.new
|
51
|
+
hash = parser.parse(response)
|
52
|
+
hash
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dianxin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Scott Ballantyne
|
14
|
+
- Zhang Zheng
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-08-30 00:00:00 +08:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rest-client
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 6
|
34
|
+
- 6
|
35
|
+
version: 1.6.6
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: yajl-ruby
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 57
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
- 8
|
50
|
+
- 3
|
51
|
+
version: 0.8.3
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
description: gem to integrate with sichuan china telecom
|
55
|
+
email:
|
56
|
+
- ussballantyne@gmail.com
|
57
|
+
- simsicon@gmail.com
|
58
|
+
executables: []
|
59
|
+
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files: []
|
63
|
+
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README
|
69
|
+
- Rakefile
|
70
|
+
- dianxin.gemspec
|
71
|
+
- lib/dianxin.rb
|
72
|
+
- lib/dianxin/base.rb
|
73
|
+
- lib/dianxin/version.rb
|
74
|
+
- test.rb
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: ""
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project: dianxin
|
105
|
+
rubygems_version: 1.3.7
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: gem to send text messages with china telecom
|
109
|
+
test_files: []
|
110
|
+
|