afgn_sms 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/afgn_sms.rb +92 -0
- metadata +66 -0
data/lib/afgn_sms.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
=begin
|
2
|
+
== Information ==
|
3
|
+
=== Copyright: WTF Public License
|
4
|
+
=== Author: Patrick Su < afgnsu@gmail.com >
|
5
|
+
=== Library Name: AfgnSms lib
|
6
|
+
=== Version: 0.1
|
7
|
+
=== Please read README file to get more information.
|
8
|
+
=end
|
9
|
+
|
10
|
+
%w|date uri cgi net/http open-uri|.each{|r| require r}
|
11
|
+
SEND_URL = "http://api.message.net.tw/send.php?"
|
12
|
+
QUERY_URL = "http://api.message.net.tw/query.php?"
|
13
|
+
|
14
|
+
class AfgnSms
|
15
|
+
def initialize(username, password)
|
16
|
+
@uname, @upwd = username, password
|
17
|
+
@send_options = {
|
18
|
+
:mtype => "G",
|
19
|
+
:encoding => "utf8"
|
20
|
+
}
|
21
|
+
|
22
|
+
@query_options = {
|
23
|
+
:columns => "mstat"
|
24
|
+
}
|
25
|
+
|
26
|
+
#米瑟奇『錯誤訊息代碼』
|
27
|
+
@@errors = {
|
28
|
+
0.to_s.to_sym => "待發送中",
|
29
|
+
1.to_s.to_sym => "已發送",
|
30
|
+
2.to_s.to_sym => "發送成功",
|
31
|
+
-1.to_s.to_sym => "登入失敗",
|
32
|
+
-2.to_s.to_sym => "點數不足",
|
33
|
+
-21.to_s.to_sym => "國際簡訊不支援長簡訊",
|
34
|
+
-30.to_s.to_sym => "socket開啟失敗",
|
35
|
+
-31.to_s.to_sym => "HTTP timeout",
|
36
|
+
-32.to_s.to_sym => "HTTP回覆失敗",
|
37
|
+
-35.to_s.to_sym => "系統商點數餘額不足",
|
38
|
+
-4.to_s.to_sym => "不合法來源IP",
|
39
|
+
-41.to_s.to_sym => "限定時間已到尚未送達",
|
40
|
+
-42.to_s.to_sym => "簡訊被刪除",
|
41
|
+
-43.to_s.to_sym => "簡訊無法送達",
|
42
|
+
-45.to_s.to_sym => "不明原因",
|
43
|
+
-46.to_s.to_sym => "簡訊被拒絕",
|
44
|
+
-47.to_s.to_sym => "不存在的訊息代號(SYNTAXE)",
|
45
|
+
-49.to_s.to_sym => "不明代碼",
|
46
|
+
'-4x'.to_sym => "系統傷回覆錯誤訊息",
|
47
|
+
-5.to_s.to_sym => "簡訊內容長度超過限制",
|
48
|
+
-51.to_s.to_sym => "無該簡訊序號",
|
49
|
+
-52.to_s.to_sym => "該簡訊已處理",
|
50
|
+
-53.to_s.to_sym => "未處理訊息刪除失敗",
|
51
|
+
-100.to_s.to_sym => "系統商傳遞代碼(未知)",
|
52
|
+
-99999.to_s.to_sym => "系統商傳遞代碼(未知)"
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def sendSMS(tel, msg, opt={})
|
57
|
+
args = []
|
58
|
+
@send_options[:tel], @send_options[:msg] = tel, msg
|
59
|
+
@send_options.merge!(opt).each{|k, v| args << k.to_s + "=" + CGI::escape(v.to_s)}
|
60
|
+
url = SEND_URL + "id=" + @uname + "&password=" + @upwd + "&" + args.join("&")
|
61
|
+
self.check_send_val
|
62
|
+
return self.check_send_resp(Net::HTTP.get(URI.parse(url)))
|
63
|
+
end
|
64
|
+
|
65
|
+
def querySMS()
|
66
|
+
url ||= QUERY_URL + "id=" + @uname + "&password=" + @upwd
|
67
|
+
url += "&columns=" + @query_options[:columns].to_s
|
68
|
+
return self.check_query_resp(Net::HTTP.get(URI.parse(url)))
|
69
|
+
end
|
70
|
+
|
71
|
+
def check_query_resp(resp)
|
72
|
+
resp = resp.split(" ").map{ |x| x.split("=") }
|
73
|
+
if resp[0][1] != '-1'
|
74
|
+
#回傳點數
|
75
|
+
return "點數剩餘:#{resp[1][1].to_s}"
|
76
|
+
else
|
77
|
+
return '米瑟奇的帳號密碼錯誤!'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def check_send_resp(resp)
|
82
|
+
resp = resp.split(" ").map{ |x| x.split("=") }
|
83
|
+
return @@errors[resp[0][1].to_s.to_sym]
|
84
|
+
end
|
85
|
+
|
86
|
+
def check_send_val()
|
87
|
+
@send_options[:tel].gsub(/-/, "")
|
88
|
+
return nil
|
89
|
+
end
|
90
|
+
|
91
|
+
protected :check_send_val, :check_send_resp, :check_query_resp
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: afgn_sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Patrick Su
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2016-03-04 00:00:00 +08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Send SMS with Message Media (http://www.message.com.tw)
|
22
|
+
email: afgnsu@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/afgn_sms.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://rubygems.org/gems/afgn_sms
|
33
|
+
licenses:
|
34
|
+
- WTF
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.6.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Send SMS with Message Media (http://www.message.com.tw)
|
65
|
+
test_files: []
|
66
|
+
|