Sha256: a3fc2aeaaa3882d51936ba3abd22518f70dc39f577a28f9db72886fc6dfa9237

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require "entinfo/version"
require 'entinfo/configuration'
require 'net/http'
require 'digest'
require 'iconv'
require 'time'

module Entinfo
  extend self
  #config
  attr_writer :config

  def config
    @config ||= Configuration.new
  end

  def configure
    yield(config)
  end

  #send sms
  URL = "http://sdk2.entinfo.cn:8061/mdsmssend.ashx"

  def pwd
    Digest::MD5.hexdigest(@config.sn + @config.pwd).upcase
  end

  def send_sms(phone, content)
    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

  #recieve sms
 def receive_sms messages
   messages = Iconv.conv('utf-8', 'gb2312', messages)
   arr = messages.split(';').collect {|x| x.split(',')}
   results = []
   arr.each do |m|
     message = Hash.new
     message[:from] = m[2]
     message[:content] = m[3]
     message[:time] = Time.parse m[4]
     results << message
   end
   results
 end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
entinfo-0.1.6 lib/entinfo.rb