china_sms 0.0.5 → 0.0.6
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 +11 -2
- data/china_sms.gemspec +3 -1
- data/lib/china_sms.rb +17 -11
- data/lib/china_sms/service/emay.rb +3 -5
- data/lib/china_sms/service/smsbao.rb +13 -0
- data/lib/china_sms/service/yunpian.rb +54 -0
- data/lib/china_sms/version.rb +1 -1
- data/spec/service/smsbao_spec.rb +22 -2
- data/spec/service/yunpian_spec.rb +74 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17e5ab2da8313d489fd637a216018f23eeb48110
|
4
|
+
data.tar.gz: eab26a7375d7cd5cc2d3c1fcd3f366f8c790760e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58907bb3cdbba273d491cf358faaedc0915681948510afdb411147cb5f680bfe83a1ff330bc2a53c2cca2ad98a50e4613cb274bba19b2217b1e84ca85636b90b
|
7
|
+
data.tar.gz: 386027184fd3f393239292976ce2932a7e7c4b0199e7db226de1747ceae812b8e9f2d0fea57ff81623becc332b92c98a2eaa1d8a06db2e25801a9051214c15a3
|
data/README.md
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
所有短信平台都禁止发送私人短信,并要求在短信内容末尾加上签名后缀,如【19屋】
|
8
8
|
|
9
9
|
* [推立方](http://tui3.com/) 专注于注册校验码等实时应用,需要[配置内容格式和签名](http://www.tui3.com/Members/smsconfigv2/),会自动在短信加上签名后缀。短信计数:移动/联通每条短信的最大长度为64字符,电信每条最大长度60字符(半角、全角各算一个)。超过该长度后,短信后面自动增加分页信息(x/y),此时,每条短信最大长度需要再减3(不超过10页)
|
10
|
+
* [云片网](http://www.yunpian.com/) 专注于帮助企业与客户更好的沟通, 提供短信服务, 功能强大, 可以配置多种[模板](http://www.yunpian.com/api/tpl.html), 实时性高, 定制型强, 价格优惠.
|
10
11
|
* [短信宝](http://www.smsbao.com/)
|
11
12
|
* [畅友网络](http://www.chanyoo.cn/) 群发短信需要半小时左右的时间审核,星期五等繁忙时段会有几个小时的延时,不适合发送注册校验码等实时短信,单次最多发送500个号码
|
12
13
|
* [亿美软通](http://www.emay.cn/)
|
@@ -30,9 +31,17 @@
|
|
30
31
|
## 使用
|
31
32
|
|
32
33
|
```ruby
|
33
|
-
# 支持 :tui3, :smsbao, chanyoo, emay 短信接口
|
34
|
+
# 支持 :tui3, :yunpian, :smsbao, :chanyoo, :emay 短信接口
|
34
35
|
ChinaSMS.use :tui3, username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD'
|
35
36
|
ChinaSMS.to '13912345678', '[Test]China SMS gem has been released.'
|
37
|
+
|
38
|
+
# :yunpian 的参数有
|
39
|
+
# :company 默认是 `云片网`
|
40
|
+
# :tpl_id 默认是 2
|
41
|
+
|
42
|
+
ChinaSMS.use :yunpian, password: 'YOUR_API_KEY'
|
43
|
+
ChinaSMS.to '13912345678', '[Test]China SMS gem has been released.', company: '19Wu'
|
44
|
+
|
36
45
|
```
|
37
46
|
|
38
47
|
## 贡献
|
@@ -47,5 +56,5 @@ bundle console # 请不要使用 irb,可能会有依赖问题
|
|
47
56
|
|
48
57
|
在安全性方面,很多接口都是使用用户登录明文密码,推立方 和 短信宝 要好一些。
|
49
58
|
|
50
|
-
*
|
59
|
+
* **推立方**,**云片网**,不使用登录密码,而是由系统自动生成一长串 API_KEY,专用于接口调用
|
51
60
|
* **短信宝**,使用登录密码,但在调用时要先转成 MD5
|
data/china_sms.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
# coding: utf-8
|
2
4
|
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
@@ -18,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
18
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
21
|
spec.require_paths = ["lib"]
|
20
22
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.2"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
spec.add_development_dependency "rspec"
|
24
26
|
spec.add_development_dependency "webmock"
|
data/lib/china_sms.rb
CHANGED
@@ -8,30 +8,36 @@ end
|
|
8
8
|
module ChinaSMS
|
9
9
|
extend self
|
10
10
|
|
11
|
-
|
12
|
-
@username
|
13
|
-
end
|
14
|
-
|
15
|
-
def password
|
16
|
-
@password
|
17
|
-
end
|
11
|
+
attr_reader :username, :password
|
18
12
|
|
19
13
|
def use(service, options)
|
20
14
|
@service = ChinaSMS::Service.const_get("#{service.to_s.capitalize}")
|
15
|
+
@service.const_set("URL", options[:base_uri]) if options[:base_uri]
|
21
16
|
@username = options[:username]
|
22
17
|
@password = options[:password]
|
23
18
|
end
|
24
19
|
|
25
|
-
def to(receiver, content)
|
26
|
-
|
20
|
+
def to(receiver, content, options = {})
|
21
|
+
options = default_options.merge options
|
22
|
+
@service.to receiver, content.strip, options if @service
|
27
23
|
end
|
28
24
|
|
29
|
-
def get
|
30
|
-
|
25
|
+
def get(options = {})
|
26
|
+
options = default_options.merge options
|
27
|
+
@service.get options if @service
|
31
28
|
end
|
32
29
|
|
33
30
|
def clear
|
34
31
|
@service = @username = @password = nil
|
35
32
|
end
|
36
33
|
|
34
|
+
private
|
35
|
+
|
36
|
+
def default_options
|
37
|
+
{
|
38
|
+
username: @username,
|
39
|
+
password: @password
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
37
43
|
end
|
@@ -3,19 +3,17 @@ module ChinaSMS
|
|
3
3
|
module Service
|
4
4
|
module Emay
|
5
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"
|
6
|
+
URL = "http://sdkhttp.eucp.b2m.cn/sdkproxy"
|
9
7
|
|
10
8
|
def to(phone, content, options)
|
11
9
|
phones = Array(phone).join(',')
|
12
|
-
res = Net::HTTP.post_form(URI.parse(
|
10
|
+
res = Net::HTTP.post_form(URI.parse("#{URL}/sendsms.action"), cdkey: options[:username], password: options[:password], phone: phones, message: content)
|
13
11
|
result res.body
|
14
12
|
end
|
15
13
|
|
16
14
|
def get(options)
|
17
15
|
# res = Net::HTTP.post_form(URI.parse(GET_URL), cdkey: options[:username], password: options[:password])
|
18
|
-
url =
|
16
|
+
url = "#{URL}/getmo.action?cdkey=#{options[:username]}&password=#{options[:password]}"
|
19
17
|
res = Net::HTTP.get(URI.parse(url))
|
20
18
|
res.body
|
21
19
|
end
|
@@ -5,6 +5,7 @@ module ChinaSMS
|
|
5
5
|
extend self
|
6
6
|
|
7
7
|
URL = "http://api.smsbao.com/sms"
|
8
|
+
REMAIN_URL = "http://www.smsbao.com/query"
|
8
9
|
|
9
10
|
MESSAGES = {
|
10
11
|
'0' => '短信发送成功',
|
@@ -23,6 +24,18 @@ module ChinaSMS
|
|
23
24
|
result res.body
|
24
25
|
end
|
25
26
|
|
27
|
+
def get options
|
28
|
+
res = Net::HTTP.post_form(URI.parse(REMAIN_URL), u: options[:username], p: Digest::MD5.hexdigest(options[:password]))
|
29
|
+
r = res.body.match(/(\d+)\n(\d+),(\d+)/)
|
30
|
+
{
|
31
|
+
success: (r[1] == '0'),
|
32
|
+
code: r[1],
|
33
|
+
message: MESSAGES[r[1]],
|
34
|
+
send: r[2].to_i,
|
35
|
+
remain: r[3].to_i
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
26
39
|
def result(code)
|
27
40
|
{
|
28
41
|
success: (code == '0'),
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ChinaSMS
|
3
|
+
module Service
|
4
|
+
module Yunpian
|
5
|
+
extend self
|
6
|
+
|
7
|
+
URL = "http://yunpian.com/v1/sms/tpl_send.json"
|
8
|
+
GET_URL = "http://yunpian.com/v1/sms/get.json"
|
9
|
+
|
10
|
+
def to phone, content, options = {}
|
11
|
+
message = parse_content content, options[:company]
|
12
|
+
options[:tpl_id] ||= 2
|
13
|
+
options[:apikey] ||= options[:password]
|
14
|
+
except! options, :username, :password, :company
|
15
|
+
options.merge!({mobile: phone, tpl_value: message})
|
16
|
+
res = Net::HTTP.post_form(URI.parse(URL), options)
|
17
|
+
result res.body
|
18
|
+
end
|
19
|
+
|
20
|
+
def get options = {}
|
21
|
+
options[:apikey] ||= options[:password]
|
22
|
+
except! options, :username, :password, :company
|
23
|
+
res = Net::HTTP.post_form(URI.parse(GET_URL), options)
|
24
|
+
result res.body
|
25
|
+
end
|
26
|
+
|
27
|
+
def result body
|
28
|
+
begin
|
29
|
+
JSON.parse body
|
30
|
+
rescue => e
|
31
|
+
{
|
32
|
+
code: 502,
|
33
|
+
msg: "内容解析错误",
|
34
|
+
detail: e.to_s
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def except! options = {}, *keys
|
42
|
+
keys.each {|key| options.delete(key)}
|
43
|
+
options
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_content content, company
|
47
|
+
content ||= '1234'
|
48
|
+
company ||= '云片网'
|
49
|
+
"#code#=#{content}&#company#=#{company}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/lib/china_sms/version.rb
CHANGED
data/spec/service/smsbao_spec.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe "Smsbao" do
|
5
|
+
let(:username) { 'saberma' }
|
6
|
+
let(:password) { '666666' }
|
5
7
|
describe "#to" do
|
6
|
-
let(:username) { 'saberma' }
|
7
|
-
let(:password) { '666666' }
|
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 }
|
@@ -36,5 +36,25 @@ describe "Smsbao" do
|
|
36
36
|
its([:code]) { should eql '0' }
|
37
37
|
its([:message]) { should eql "短信发送成功" }
|
38
38
|
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "get" do
|
43
|
+
let(:remain_url) { "http://www.smsbao.com/query" }
|
44
|
+
subject { ChinaSMS::Service::Smsbao.get username: username, password: password }
|
45
|
+
|
46
|
+
describe "remain send count" do
|
47
|
+
before do
|
48
|
+
stub_request(:post, remain_url).
|
49
|
+
with(body: {u: username, p: Digest::MD5.hexdigest(password)}).
|
50
|
+
to_return(body: "0\n100,200")
|
51
|
+
end
|
52
|
+
|
53
|
+
its([:success]) { should eql true }
|
54
|
+
its([:code]) { should eql '0' }
|
55
|
+
its([:message]) { should eql '短信发送成功' }
|
56
|
+
its([:send]) { should eql 100 }
|
57
|
+
its([:remain]) { should eql 200 }
|
58
|
+
end
|
39
59
|
end
|
40
60
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Yunpian" do
|
5
|
+
describe "#to" do
|
6
|
+
let(:apikey) { '2022b1599967a8cb788c05ddd9fc339e' }
|
7
|
+
let(:url) { "http://yunpian.com/v1/sms/tpl_send.json" }
|
8
|
+
let(:content) { '云片测试:验证码 1234。' }
|
9
|
+
subject { ChinaSMS::Service::Yunpian.to phone, content, password: apikey }
|
10
|
+
|
11
|
+
describe 'single phone' do
|
12
|
+
let(:phone) { '13928452841' }
|
13
|
+
|
14
|
+
before do
|
15
|
+
stub_request(:post, url).
|
16
|
+
with(
|
17
|
+
:body => {
|
18
|
+
"apikey" => apikey,
|
19
|
+
"mobile" => phone,
|
20
|
+
"tpl_id" => "2",
|
21
|
+
"tpl_value" =>"#code#=#{content}&#company#=云片网"},
|
22
|
+
:headers => {
|
23
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
24
|
+
}
|
25
|
+
).
|
26
|
+
to_return(
|
27
|
+
body: {
|
28
|
+
'code' => 0,
|
29
|
+
'msg' => 'OK',
|
30
|
+
'result' => {
|
31
|
+
'count' => '1',
|
32
|
+
'fee' => '1',
|
33
|
+
'sid' => '592762800'
|
34
|
+
}
|
35
|
+
}.to_json
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
its(["code"]) { should eql 0 }
|
40
|
+
its(["msg"]) { should eql "OK" }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'invalid key' do
|
44
|
+
let(:phone) { '13928452841' }
|
45
|
+
let(:apikey) { '666666' }
|
46
|
+
|
47
|
+
before do
|
48
|
+
stub_request(:post, url).
|
49
|
+
with(
|
50
|
+
:body => {
|
51
|
+
"apikey" => apikey,
|
52
|
+
"mobile" => phone,
|
53
|
+
"tpl_id" => "2",
|
54
|
+
"tpl_value" =>"#code#=#{content}&#company#=云片网"},
|
55
|
+
:headers => {
|
56
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
57
|
+
}
|
58
|
+
).
|
59
|
+
to_return(
|
60
|
+
body: {
|
61
|
+
"code" => -1,
|
62
|
+
"msg" => "非法的apikey",
|
63
|
+
"detail" => "请检查的apikey是否正确"
|
64
|
+
}.to_json
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
its(["code"]) { should eql -1 }
|
69
|
+
its(["msg"]) { should eql "非法的apikey" }
|
70
|
+
its(["detail"]) { should eql "请检查的apikey是否正确" }
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- saberma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,12 +85,14 @@ files:
|
|
85
85
|
- lib/china_sms/service/emay.rb
|
86
86
|
- lib/china_sms/service/smsbao.rb
|
87
87
|
- lib/china_sms/service/tui3.rb
|
88
|
+
- lib/china_sms/service/yunpian.rb
|
88
89
|
- lib/china_sms/version.rb
|
89
90
|
- spec/china_sms_spec.rb
|
90
91
|
- spec/service/chanyoo_spec.rb
|
91
92
|
- spec/service/emay_spec.rb
|
92
93
|
- spec/service/smsbao_spec.rb
|
93
94
|
- spec/service/tui3_spec.rb
|
95
|
+
- spec/service/yunpian_spec.rb
|
94
96
|
- spec/spec_helper.rb
|
95
97
|
homepage: https://github.com/saberma/china_sms
|
96
98
|
licenses:
|
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
114
|
version: '0'
|
113
115
|
requirements: []
|
114
116
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.1.11
|
116
118
|
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: a gem for chinese people to send sms
|
@@ -122,4 +124,5 @@ test_files:
|
|
122
124
|
- spec/service/emay_spec.rb
|
123
125
|
- spec/service/smsbao_spec.rb
|
124
126
|
- spec/service/tui3_spec.rb
|
127
|
+
- spec/service/yunpian_spec.rb
|
125
128
|
- spec/spec_helper.rb
|