haobo_sms 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/haobo_sms.rb +3 -0
- data/lib/haobo_sms/config.rb +24 -0
- data/lib/haobo_sms/sms.rb +97 -0
- data/lib/haobo_sms/util.rb +15 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adc878236e49d552021b152c92d1c995e63cc5f3
|
4
|
+
data.tar.gz: 01039f82a7e69eb276e59dc89726a6ebfab3f69e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 203d8795412591b37964a83033e06f69690176864768c6270170cc66a7c18ab2e9d3715cefa7bc81dcdff848f29fb44a4ead4e8e9be5cb1caad126393039e29b
|
7
|
+
data.tar.gz: f7d5e4ccf0462917761d078c57b160643c87e3e78a16884332267eb3d768a2b775329e1db1c339ca87bc3c7fb5336decd85f7478d2fa14bcfc9fdc1a044ecfab
|
data/lib/haobo_sms.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module HaoboSms
|
5
|
+
|
6
|
+
class Config
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def initialize()
|
10
|
+
configHash = YAML.load_file(Rails.root.to_s + '/config/sms.yml')
|
11
|
+
|
12
|
+
if configHash.nil?
|
13
|
+
raise "sms.yml为空"
|
14
|
+
end
|
15
|
+
|
16
|
+
configHash.each do |k, v|
|
17
|
+
Object.send :define_method, k do
|
18
|
+
v
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end # initialize .. end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module HaoboSms
|
7
|
+
|
8
|
+
# 这个类所有方法,
|
9
|
+
# 返回为空{},表示请求异常
|
10
|
+
class Sms
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
def initialize()
|
14
|
+
@config = HaoboSms::Config.instance
|
15
|
+
end
|
16
|
+
|
17
|
+
# 发送短信
|
18
|
+
# { rp: 0, id: }
|
19
|
+
def send_sms(phone, message)
|
20
|
+
# 将短信正文转换为gb18030并转换为16进制
|
21
|
+
content = (@config.pre_str + message).encode("gb18030").unpack("H*")
|
22
|
+
|
23
|
+
option = {}
|
24
|
+
option["un"] = @config.user_name
|
25
|
+
option["pw"] = @config.pass_word
|
26
|
+
option["da"] = phone
|
27
|
+
option["sm"] = content
|
28
|
+
option["dc"] = "15"
|
29
|
+
option["rd"] = "1"
|
30
|
+
|
31
|
+
uri = URI(@config.send_url)
|
32
|
+
uri.query = URI.encode_www_form(option)
|
33
|
+
res = Net::HTTP.get_response(uri)
|
34
|
+
|
35
|
+
if res.is_a? Net::HTTPSuccess
|
36
|
+
body = res.body
|
37
|
+
result = HaoboSms::Util.parse_query_str(body)
|
38
|
+
else
|
39
|
+
result = {}
|
40
|
+
end
|
41
|
+
|
42
|
+
return result.with_indifferent_access
|
43
|
+
end
|
44
|
+
|
45
|
+
# 查询剩余条数
|
46
|
+
# { op: "bi", bl: 33 }
|
47
|
+
def get_remain()
|
48
|
+
option = {}
|
49
|
+
|
50
|
+
option["un"] = @config.user_name
|
51
|
+
option["pw"] = @config.pass_word
|
52
|
+
|
53
|
+
uri = URI(@config.balance_url)
|
54
|
+
uri.query = URI.encode_www_form(option)
|
55
|
+
res = Net::HTTP.get_response(uri)
|
56
|
+
|
57
|
+
if res.is_a? Net::HTTPSuccess
|
58
|
+
body = res.body
|
59
|
+
result = HaoboSms::Util.parse_query_str(body)
|
60
|
+
else
|
61
|
+
result = {}
|
62
|
+
end
|
63
|
+
|
64
|
+
return result.with_indifferent_access
|
65
|
+
end
|
66
|
+
|
67
|
+
# 获取状态报告
|
68
|
+
# 可传参数fs: 请求长度
|
69
|
+
# 返回数组[ { id: , su: , rp: } ]
|
70
|
+
def get_report(option_hash = {})
|
71
|
+
option = option_hash.stringify_keys
|
72
|
+
|
73
|
+
option["un"] = @config.user_name
|
74
|
+
option["pw"] = @config.pass_word
|
75
|
+
|
76
|
+
uri = URI(@config.receive_url)
|
77
|
+
uri.query = URI.encode_www_form(option)
|
78
|
+
res = Net::HTTP.get_response(uri)
|
79
|
+
|
80
|
+
result = { rpts: [] }
|
81
|
+
if res.is_a? Net::HTTPSuccess
|
82
|
+
res.body.split("\r\n").each do |query_str|
|
83
|
+
hash = HaoboSms::Util.parse_query_str(query_str)
|
84
|
+
|
85
|
+
if hash["op"] == "dr"
|
86
|
+
result[:rpts] << hash
|
87
|
+
end
|
88
|
+
end
|
89
|
+
else
|
90
|
+
result = {}
|
91
|
+
end
|
92
|
+
|
93
|
+
return result.with_indifferent_access
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haobo_sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "袁帅"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: "昊博短信接口"
|
14
|
+
email: bysxrokr@qq.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/haobo_sms.rb
|
20
|
+
- lib/haobo_sms/config.rb
|
21
|
+
- lib/haobo_sms/sms.rb
|
22
|
+
- lib/haobo_sms/util.rb
|
23
|
+
homepage: http://rubygems.org/gems/haobo_sms
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.4.5
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: "昊博短信接口"
|
47
|
+
test_files: []
|