china_sms 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/china_sms.rb +7 -0
- data/lib/china_sms/service/chanyoo.rb +3 -0
- data/lib/china_sms/service/emay.rb +33 -0
- data/lib/china_sms/service/smsbao.rb +3 -0
- data/lib/china_sms/service/tui3.rb +3 -0
- data/lib/china_sms/version.rb +1 -1
- data/spec/china_sms_spec.rb +7 -0
- data/spec/service/chanyoo_spec.rb +7 -0
- data/spec/service/emay_spec.rb +27 -0
- data/spec/service/smsbao_spec.rb +5 -0
- data/spec/service/tui3_spec.rb +9 -0
- data/spec/spec_helper.rb +3 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97e1d464107001de01cf62059455990cea08a5b6
|
4
|
+
data.tar.gz: 3b9f52a9340f4e972e89bff6645d08e9591a35fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a99f5f6d51fc05ba0aeaf07c9f3aae9d3d0eb20895eb01d694ed75c62dcc9a6932071bdab82d9e846564e4ae507efb7e59050e6e41957276bfa6018cd2a0d0f
|
7
|
+
data.tar.gz: 4f17931a90aeac83e78e108a1bb323dc9f5ccd3fe5245de265afb6043bc47dc4ef47d3ab6542f9246c352bc48c21cb37bae9940483c647211fb97a191d820d8a
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
* [推立方](http://tui3.com/) 专注于注册校验码等实时应用,需要[配置内容格式和签名](http://www.tui3.com/Members/smsconfigv2/),会自动在短信加上签名后缀。短信计数:移动/联通每条短信的最大长度为64字符,电信每条最大长度60字符(半角、全角各算一个)。超过该长度后,短信后面自动增加分页信息(x/y),此时,每条短信最大长度需要再减3(不超过10页)
|
10
10
|
* [短信宝](http://www.smsbao.com/)
|
11
11
|
* [畅友网络](http://www.chanyoo.cn/) 群发短信需要半小时左右的时间审核,星期五等繁忙时段会有几个小时的延时,不适合发送注册校验码等实时短信,单次最多发送500个号码
|
12
|
+
* [亿美软通](http://www.emay.cn/)
|
12
13
|
|
13
14
|
非常感谢 [推立方](http://tui3.com/) 为 [19屋活动平台](http://19wu.com) 提供短信赞助。
|
14
15
|
|
@@ -29,11 +30,19 @@
|
|
29
30
|
## 使用
|
30
31
|
|
31
32
|
```ruby
|
32
|
-
# 支持 :tui3, :smsbao, chanyoo 短信接口
|
33
|
+
# 支持 :tui3, :smsbao, chanyoo, emay 短信接口
|
33
34
|
ChinaSMS.use :tui3, username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD'
|
34
35
|
ChinaSMS.to '13912345678', '[Test]China SMS gem has been released.'
|
35
36
|
```
|
36
37
|
|
38
|
+
## 贡献
|
39
|
+
|
40
|
+
```bash
|
41
|
+
git clone git@github.com:saberma/china_sms.git
|
42
|
+
cd china_sms
|
43
|
+
bundle console # 请不要使用 irb,可能会有依赖问题
|
44
|
+
```
|
45
|
+
|
37
46
|
## 安全性
|
38
47
|
|
39
48
|
在安全性方面,很多接口都是使用用户登录明文密码,推立方 和 短信宝 要好一些。
|
data/lib/china_sms.rb
CHANGED
@@ -7,9 +7,11 @@ end
|
|
7
7
|
|
8
8
|
module ChinaSMS
|
9
9
|
extend self
|
10
|
+
|
10
11
|
def username
|
11
12
|
@username
|
12
13
|
end
|
14
|
+
|
13
15
|
def password
|
14
16
|
@password
|
15
17
|
end
|
@@ -24,7 +26,12 @@ module ChinaSMS
|
|
24
26
|
@service.to receiver, content, username: @username, password: @password if @service
|
25
27
|
end
|
26
28
|
|
29
|
+
def get
|
30
|
+
@service.get username: @username, password: @password if @service
|
31
|
+
end
|
32
|
+
|
27
33
|
def clear
|
28
34
|
@service = @username = @password = nil
|
29
35
|
end
|
36
|
+
|
30
37
|
end
|
@@ -3,7 +3,9 @@ module ChinaSMS
|
|
3
3
|
module Service
|
4
4
|
module Chanyoo
|
5
5
|
extend self
|
6
|
+
|
6
7
|
URL = "http://api.chanyoo.cn/utf8/interface/send_sms.aspx"
|
8
|
+
|
7
9
|
def to(phone, content, options)
|
8
10
|
phones = Array(phone).join(',')
|
9
11
|
res = Net::HTTP.post_form(URI.parse(URL), username: options[:username], password: options[:password], receiver: phones, content: content)
|
@@ -19,6 +21,7 @@ module ChinaSMS
|
|
19
21
|
message: message.force_encoding("UTF-8")
|
20
22
|
}
|
21
23
|
end
|
24
|
+
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ChinaSMS
|
3
|
+
module Service
|
4
|
+
module Emay
|
5
|
+
extend self
|
6
|
+
|
7
|
+
SEND_URL = "http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action"
|
8
|
+
GET_URL = "http://sdkhttp.eucp.b2m.cn/sdkproxy/getmo.action"
|
9
|
+
|
10
|
+
def to(phone, content, options)
|
11
|
+
phones = Array(phone).join(',')
|
12
|
+
res = Net::HTTP.post_form(URI.parse(SEND_URL), cdkey: options[:username], password: options[:password], phone: phones, message: content)
|
13
|
+
result res.body
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(options)
|
17
|
+
# res = Net::HTTP.post_form(URI.parse(GET_URL), cdkey: options[:username], password: options[:password])
|
18
|
+
url = GET_URL + "?cdkey=#{options[:username]}&password=#{options[:password]}"
|
19
|
+
res = Net::HTTP.get(URI.parse(url))
|
20
|
+
res.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def result(body)
|
24
|
+
code = body.match(/.+error>(.+)\<\/error/)[1]
|
25
|
+
{
|
26
|
+
success: (code.to_i >= 0),
|
27
|
+
code: code
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -3,7 +3,9 @@ module ChinaSMS
|
|
3
3
|
module Service
|
4
4
|
module Smsbao
|
5
5
|
extend self
|
6
|
+
|
6
7
|
URL = "http://api.smsbao.com/sms"
|
8
|
+
|
7
9
|
MESSAGES = {
|
8
10
|
'0' => '短信发送成功',
|
9
11
|
'30' => '密码错误',
|
@@ -28,6 +30,7 @@ module ChinaSMS
|
|
28
30
|
message: MESSAGES[code]
|
29
31
|
}
|
30
32
|
end
|
33
|
+
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
@@ -5,7 +5,9 @@ module ChinaSMS
|
|
5
5
|
module Service
|
6
6
|
module Tui3 # http://tui3.com/
|
7
7
|
extend self
|
8
|
+
|
8
9
|
URL = "http://tui3.com/api/send/"
|
10
|
+
|
9
11
|
def to(phone, content, options)
|
10
12
|
phones = Array(phone).join(',')
|
11
13
|
res = Net::HTTP.post_form(URI.parse(URL), k: options[:password], t: phones, c: content, p: 1, r: 'json')
|
@@ -21,6 +23,7 @@ module ChinaSMS
|
|
21
23
|
message: body['err_msg']
|
22
24
|
}
|
23
25
|
end
|
26
|
+
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
data/lib/china_sms/version.rb
CHANGED
data/spec/china_sms_spec.rb
CHANGED
@@ -7,12 +7,15 @@ describe "ChinaSMS" do
|
|
7
7
|
let(:password) { '666666' }
|
8
8
|
let(:phone) { '13928452841' }
|
9
9
|
let(:content) { '活动通知:深圳 Rubyist 活动时间变更到明天下午 7:00,请留意。' }
|
10
|
+
|
10
11
|
context 'with service' do
|
11
12
|
before { ChinaSMS.use service, username: username, password: password }
|
13
|
+
|
12
14
|
describe "#use" do
|
13
15
|
subject { ChinaSMS }
|
14
16
|
its(:username) { should eql "saberma"}
|
15
17
|
end
|
18
|
+
|
16
19
|
describe "#to" do
|
17
20
|
subject { ChinaSMS.to(phone, content) }
|
18
21
|
before { ChinaSMS::Service::Tui3.stub(:to).with(phone, content, username: username, password: password).and_return(success: true, code: 0) }
|
@@ -20,12 +23,16 @@ describe "ChinaSMS" do
|
|
20
23
|
its([:code]) { should eql 0 }
|
21
24
|
end
|
22
25
|
end
|
26
|
+
|
23
27
|
context 'without service' do
|
24
28
|
before { ChinaSMS.clear }
|
29
|
+
|
25
30
|
describe '#to' do
|
26
31
|
it 'should be ignore' do
|
27
32
|
ChinaSMS.to(phone, content)
|
28
33
|
end
|
29
34
|
end
|
35
|
+
|
30
36
|
end
|
37
|
+
|
31
38
|
end
|
@@ -2,19 +2,23 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe "Chanyoo" do
|
5
|
+
|
5
6
|
describe "#to" do
|
6
7
|
let(:username) { 'saberma' }
|
7
8
|
let(:password) { '666666' }
|
8
9
|
let(:url) { "http://api.chanyoo.cn/utf8/interface/send_sms.aspx" }
|
9
10
|
let(:content) { '【畅友短信测试】深圳 Rubyist 活动时间变更到周六下午 3:00,请留意。【19屋】' }
|
10
11
|
subject { ChinaSMS::Service::Chanyoo.to phone, content, username: username, password: password }
|
12
|
+
|
11
13
|
describe 'single phone' do
|
12
14
|
let(:phone) { '13928452841' }
|
15
|
+
|
13
16
|
before do
|
14
17
|
stub_request(:post, url).
|
15
18
|
with(body: {username: username, password: password, receiver: phone, content: content}).
|
16
19
|
to_return(body: '<?xml version="1.0" encoding="utf-8" ?><response><result>50</result><message>短信发送成功</message></response>')
|
17
20
|
end
|
21
|
+
|
18
22
|
its([:success]) { should eql true }
|
19
23
|
its([:code]) { should eql '50' }
|
20
24
|
its([:message]) { should eql "短信发送成功" }
|
@@ -22,14 +26,17 @@ describe "Chanyoo" do
|
|
22
26
|
|
23
27
|
describe 'multiple phones' do
|
24
28
|
let(:phone) { ['13928452841', '13590142385'] }
|
29
|
+
|
25
30
|
before do
|
26
31
|
stub_request(:post, url).
|
27
32
|
with(body: {username: username, password: password, receiver: phone.join(','), content: content}).
|
28
33
|
to_return(body: '<?xml version="1.0" encoding="utf-8" ?><response><result>50</result><message>短信发送成功</message></response>')
|
29
34
|
end
|
35
|
+
|
30
36
|
its([:success]) { should eql true }
|
31
37
|
its([:code]) { should eql '50' }
|
32
38
|
its([:message]) { should eql "短信发送成功" }
|
33
39
|
end
|
40
|
+
|
34
41
|
end
|
35
42
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Emay" do
|
5
|
+
|
6
|
+
describe "#to" do
|
7
|
+
let(:username) { 'YOUR_CDKEY' }
|
8
|
+
let(:password) { 'YOUR_PASSWORD' }
|
9
|
+
let(:url) { "http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action" }
|
10
|
+
let(:content) { '测试内容' }
|
11
|
+
subject { ChinaSMS::Service::Emay.to phone, content, username: username, password: password }
|
12
|
+
|
13
|
+
describe 'single phone' do
|
14
|
+
let(:phone) { '13552241639' }
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_request(:post, url).
|
18
|
+
with(body: {cdkey: username, password: password, phone: phone, message: content}).
|
19
|
+
to_return(body: '<?xml version="1.0" encoding="UTF-8" ?><error>0</error><message></message></response>')
|
20
|
+
end
|
21
|
+
|
22
|
+
its([:success]) { should eql true }
|
23
|
+
its([:code]) { should eql '0' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/service/smsbao_spec.rb
CHANGED
@@ -8,13 +8,16 @@ describe "Smsbao" do
|
|
8
8
|
let(:url) { "http://api.smsbao.com/sms" }
|
9
9
|
let(:content) { '【短信宝测试】深圳 Rubyist 活动时间变更到明天下午 7:00,请留意。【19屋】' }
|
10
10
|
subject { ChinaSMS::Service::Smsbao.to phone, content, username: username, password: password }
|
11
|
+
|
11
12
|
describe 'single phone' do
|
12
13
|
let(:phone) { '13928452841' }
|
14
|
+
|
13
15
|
before do
|
14
16
|
stub_request(:post, url).
|
15
17
|
with(body: {u: username, p: Digest::MD5.hexdigest(password), m: phone, c: content}).
|
16
18
|
to_return(body: '0')
|
17
19
|
end
|
20
|
+
|
18
21
|
its([:success]) { should eql true }
|
19
22
|
its([:code]) { should eql '0' }
|
20
23
|
its([:message]) { should eql "短信发送成功" }
|
@@ -22,11 +25,13 @@ describe "Smsbao" do
|
|
22
25
|
|
23
26
|
describe 'multiple phones' do
|
24
27
|
let(:phone) { ['13928452841', '13590142385'] }
|
28
|
+
|
25
29
|
before do
|
26
30
|
stub_request(:post, url).
|
27
31
|
with(body: {u: username, p: Digest::MD5.hexdigest(password), m: phone.join(','), c: content}).
|
28
32
|
to_return(body: '0')
|
29
33
|
end
|
34
|
+
|
30
35
|
its([:success]) { should eql true }
|
31
36
|
its([:code]) { should eql '0' }
|
32
37
|
its([:message]) { should eql "短信发送成功" }
|
data/spec/service/tui3_spec.rb
CHANGED
@@ -7,13 +7,16 @@ describe "Tui3" do
|
|
7
7
|
let(:url) { "http://tui3.com/api/send/" }
|
8
8
|
let(:content) { '推立方测试:深圳 Rubyist 活动时间变更到明天下午 7:00,请留意。' }
|
9
9
|
subject { ChinaSMS::Service::Tui3.to phone, content, password: password }
|
10
|
+
|
10
11
|
describe 'single phone' do
|
11
12
|
let(:phone) { '13928452841' }
|
13
|
+
|
12
14
|
before do
|
13
15
|
stub_request(:post, url).
|
14
16
|
with(body: {k: password, t: phone, c: content, p: '1', r: 'json'}).
|
15
17
|
to_return(body: '{"err_code":0,"err_msg":"操作成功!","server_time":"2013-07-01 21:42:37"}' )
|
16
18
|
end
|
19
|
+
|
17
20
|
its([:success]) { should eql true }
|
18
21
|
its([:code]) { should eql 0 }
|
19
22
|
its([:message]) { should eql "操作成功!" }
|
@@ -21,25 +24,31 @@ describe "Tui3" do
|
|
21
24
|
|
22
25
|
describe 'multiple phones' do
|
23
26
|
let(:phone) { ['13928452841', '13590142385'] }
|
27
|
+
|
24
28
|
before do
|
25
29
|
stub_request(:post, url).
|
26
30
|
with(body: {k: password, t: phone.join(','), c: content, p: '1', r: 'json'}).
|
27
31
|
to_return(body: '{"err_code":0,"err_msg":"操作成功!","server_time":"2013-07-01 21:42:37"}' )
|
28
32
|
end
|
33
|
+
|
29
34
|
its([:success]) { should eql true }
|
30
35
|
its([:code]) { should eql 0 }
|
31
36
|
its([:message]) { should eql "操作成功!" }
|
32
37
|
end
|
38
|
+
|
33
39
|
context 'invalid key' do
|
34
40
|
let(:phone) { '13928452841' }
|
35
41
|
let(:password) { '666666' }
|
42
|
+
|
36
43
|
before do
|
37
44
|
stub_request(:post, url).
|
38
45
|
with(body: {k: password, t: phone, c: content, p: '1', r: 'json'}).
|
39
46
|
to_return(body: 'invalid parameters' )
|
40
47
|
end
|
48
|
+
|
41
49
|
its([:success]) { should eql false }
|
42
50
|
its([:message]) { should eql "非法apikey:#{password}" }
|
43
51
|
end
|
52
|
+
|
44
53
|
end
|
45
54
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: china_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- saberma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,11 +82,13 @@ files:
|
|
82
82
|
- china_sms.gemspec
|
83
83
|
- lib/china_sms.rb
|
84
84
|
- lib/china_sms/service/chanyoo.rb
|
85
|
+
- lib/china_sms/service/emay.rb
|
85
86
|
- lib/china_sms/service/smsbao.rb
|
86
87
|
- lib/china_sms/service/tui3.rb
|
87
88
|
- lib/china_sms/version.rb
|
88
89
|
- spec/china_sms_spec.rb
|
89
90
|
- spec/service/chanyoo_spec.rb
|
91
|
+
- spec/service/emay_spec.rb
|
90
92
|
- spec/service/smsbao_spec.rb
|
91
93
|
- spec/service/tui3_spec.rb
|
92
94
|
- spec/spec_helper.rb
|
@@ -110,13 +112,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
112
|
version: '0'
|
111
113
|
requirements: []
|
112
114
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.0.
|
115
|
+
rubygems_version: 2.0.6
|
114
116
|
signing_key:
|
115
117
|
specification_version: 4
|
116
118
|
summary: a gem for chinese people to send sms
|
117
119
|
test_files:
|
118
120
|
- spec/china_sms_spec.rb
|
119
121
|
- spec/service/chanyoo_spec.rb
|
122
|
+
- spec/service/emay_spec.rb
|
120
123
|
- spec/service/smsbao_spec.rb
|
121
124
|
- spec/service/tui3_spec.rb
|
122
125
|
- spec/spec_helper.rb
|