這個Library搭配http://www.twsms.com才可以使用喔!
有任何問題可以直接回這篇文章,或者寫信問我,我信箱是Gmail的,帳號跟我的這個部落格帳號一樣
我先說用法好了:
Updated:
TWSMS on Google Code Hosting: http://code.google.com/p/twsms/
SMSender on RubyForge: http://rubyforge.org/projects/smsender/
有任何問題可以直接回這篇文章,或者寫信問我,我信箱是Gmail的,帳號跟我的這個部落格帳號一樣
我先說用法好了:
require 'twsms'原始碼:
sms = TWSMS.new(username, password) # 帳號密碼
sms.sendSMS(mobile, message) # mobile: 目標手機號碼 message: 要傳的訊息
=begin晚點丟到Google Code Hosting上去...
== Information ==
=== Copyright: Apache 2.0
=== Author: CFC < zusocfc@gmail.com >
=== Prog. Name: TWSMS lib
=== Version: 0.1
== Introduction ==
TWSMS(Taiwan SMS)
TWSMS is a SMS sender, it must use with http://www.twsms.com.
There has no any library for the SMS system in Taiwan. So, I just coded this and release this version.
This version just support for sending SMS.
== Featured ==
== Using TWSMS ==
It just support for standalone class now.
require it before you use.
=== Using TWSMS by standalone class
require 'twsms'
sms = TWSMS.new('username', 'password')
sms.sendSMS('09xxxxxxxx', 'Hi, there! TWSMS library is so easy to use!')
sms.sendSMS('09xxxxxxxx', 'Send SMS with options',
:popup => 1,
:type => "now",
:mo => "Y")
=end
%w|uri cgi net/http|.each{|r| require r}
class TWSMS
def initialize(username, password)
@uname, @upwd = username, password
@options = {
:type => "now", # Sending type: now, vld
:popup => "",
:mo => "Y".upcase,
:vldtime => "86400",
:modate => "",
:dlvtime => "",
:wapurl => "",
:encoding => "big5"
}
@errors = {
-1.to_s.to_sym => "Send failed",
-2.to_s.to_sym => "Username or password is invalid",
-3.to_s.to_sym => "Popup tag error",
-4.to_s.to_sym => "Mo tag error",
-5.to_s.to_sym => "Encoding tag error",
-6.to_s.to_sym => "Mobile tag error",
-7.to_s.to_sym => "Message tag error",
-8.to_s.to_sym => "vldtime tag error",
-9.to_s.to_sym => "dlvtime tag error",
-10.to_s.to_sym => "You have no point",
-11.to_s.to_sym => "Your account has been blocked",
-12.to_s.to_sym => "Type tag error",
-13.to_s.to_sym => "You can't send SMS message by dlvtime tag if you use wap push",
-14.to_s.to_sym => "Source IP has no permission",
-99.to_s.to_sym => "System error!! Please contact the administrator, thanks!!"
}
@args = []
@url ||= "http://api.twsms.com/send_sms.php?"
@url += "username=" + @uname
@url += "&password=" + @upwd
end
def sendSMS(mobile, message, opt={})
@options[:mobile], @options[:message] = mobile, message
@options.merge!(opt).each{|k, v| @args << k.to_s + "=" + CGI::escape(v.to_s)}
@url += "&" + @args.join("&")
self.chk_val
chk_errors(Net::HTTP.get(URI.parse(@url)))
end
def chk_val
@options[:dlvtime] = "" unless @options[:type] == "dlv"
@options[:wapurl] = "" if @options[:type] != ("push" && "upush")
end
def chk_errors(resp)
resp = resp.split("=")[1]
if @errors.has_key?(resp.to_s.to_sym)
puts "==========", "Error!! Message: ", @errors[resp.to_s.to_sym]
else
puts "==========", "Message has been send! Your message id is: " + resp.to_s
end
end
protected :chk_val
end
Updated:
TWSMS on Google Code Hosting: http://code.google.com/p/twsms/
SMSender on RubyForge: http://rubyforge.org/projects/smsender/
文章標籤
全站熱搜

太可怕了,您這個blog留了mail後會被放在網頁上供人拜拜耶,早知道就不留了,能否請大大處理一下呢,謝謝! 網頁內容還直接出現mailto:xxx,這樣會被機器人搜集走的。
很抱歉,我立刻將您的第一篇留言移除
你好,我有在google code中發Ticket, 似乎比這篇的版本新了,在sendSMS時會檢查dlvtime (raise "dlvtime is invalid";exit) unless self.check_date("dlvtime") 然後因預設dlvtime是空白,結果一parse就發生錯誤了 為何新版的非檢查不可呢?dlvtime在twsms的文件中是寫預約時間, 當 type TAG 設定為 dlv 此設定值才會有效。 是否應寫成 (raise "dlvtime is invalid";exit) unless self.check_date("dlvtime") if @send_options[:type] == "dlv"呢? 今天是第一次用,很失望的都不能用呢!
請原諒我用您的名義重新發一篇你的問題,我將在這邊回答: 該段原始碼已經改為 (raise ArgumentError, "dlvtime is invalid";return false) unless self.check_date("dlvtime") if opt[:type] =~ /^dlv$/ 請看這邊 http://github.com/cfc/twsmsr/blob/fe7027c247108097eb35081bd830365731c57ab7/lib/twsmsr.rb