从rails app发送短信的HTTP请求

时间:2013-09-04 18:33:03

标签: ruby-on-rails ruby kannel

我正在写短信发送功能,但它似乎没有发送短信 看到这个代码的任何想法为什么?

def self.send_sms(to, from, message)

username = "uname"
password = "pword"
id = rand(36**8).to_s(36)
dlr_url = URI::escape('http://www.skylinesms.com/messages/delivery?id=#{id}&type=%d')
send_url = 'http://localhost:13013/cgi-bin/sendsms?username=#{username}&password=#{password}&to=#{to}&from=#{from}&text=#{message}&dlr-url=#{dlr_url}&dlr-mask=3'
url = URI.parse(URI.encode(send_url))            
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|  http.request(req)   }
return res.body

end

1 个答案:

答案 0 :(得分:0)

我不确定,但我是这么认为的

def self.send_sms(to, from, message)
    .....
    Net::HTTP.start(url.host, url.port) { |http| http.get(req.request_uri).body }
  end