Module: Entinfo
- Extended by:
- Entinfo
- Included in:
- Entinfo
- Defined in:
- lib/entinfo.rb,
lib/entinfo/version.rb,
lib/entinfo/configuration.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- URL =
send sms
"http://sdk2.entinfo.cn:8061/mdsmssend.ashx"
- VERSION =
"0.1.7"
Instance Attribute Summary collapse
Instance Method Summary collapse
- #configure {|config| ... } ⇒ Object
- #pwd ⇒ Object
-
#receive_sms(messages) ⇒ Object
recieve sms.
- #send_sms(phone, content) ⇒ Object
Instance Attribute Details
#config ⇒ Object
13 14 15 |
# File 'lib/entinfo.rb', line 13 def config @config ||= Configuration.new end |
Instance Method Details
#configure {|config| ... } ⇒ Object
17 18 19 |
# File 'lib/entinfo.rb', line 17 def configure yield(config) end |
#pwd ⇒ Object
24 25 26 |
# File 'lib/entinfo.rb', line 24 def pwd Digest::MD5.hexdigest(@config.sn + @config.pwd).upcase end |
#receive_sms(messages) ⇒ Object
recieve sms
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/entinfo.rb', line 43 def receive_sms = Iconv.conv('utf-8', 'gb2312', ) arr = .split(';').collect { |x| x.split(',') } results = [] arr.each do |m| = Hash.new [:from] = m[2] [:content] = m[3] [:time] = Time.parse m[4] results << end results end |
#send_sms(phone, content) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/entinfo.rb', line 28 def send_sms(phone, content) unless /^1\d{10}$/ =~ phone.to_s puts "invalid phone:#{phone}" return {error: 'phone valid'} end result = Net::HTTP.post_form(URI.parse("#{URL}"), sn: @config.sn, pwd: self.pwd, mobile: phone, content: content) if result.body.match '^\d{18}$' {success: result.body} else {error: result.body} end end |