Sha256: c7bde4ad4e1aa3baf0cf89d6e1abb4723b2422cfbf4e1fdab7f428eee78c270b

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module SkioSmsClient
  class SmsSender
    delegate :app_name, :send_key, :send_server, to: :configuration

    def self.send_sms(phone, message, message_type)
      sms_sender = SmsSender.new
      agent = Mechanize.new
      agent.user_agent_alias = 'Mac Safari'
      page = agent.post(sms_sender.send_server, get_send_params(sms_sender.app_name, sms_sender.send_key, phone, message, message_type))
      htmlStr = page.body.to_s
      html_doc = Nokogiri::HTML(htmlStr)
      JSON.parse(html_doc)
    end

    private
    def configuration
      SkioSmsClient.configuration
    end

    def self.get_send_params(app_name, send_key, phone, message, message_type=nil)
      message_type ||= 'notice'
      timestamp = Time.now.strftime('%Y%m%d%H%M%S')
      sign = Digest::MD5.hexdigest("#{send_key}#{timestamp}")
      {
          :phone => "#{phone}",
          :content => "#{message}",
          :sign => sign,
          :app_name => app_name,
          :timestamp => timestamp,
          :message_type => message_type
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skio_sms_client-0.1.0 lib/skio_sms_client/sms_sender.rb