aliyun-cloud_sms 0.1.1 → 0.2.0
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 +17 -3
- data/aliyun-cloud_sms.gemspec +1 -0
- data/lib/aliyun/cloud_sms/client.rb +10 -59
- data/lib/aliyun/cloud_sms/configure.rb +0 -9
- data/lib/aliyun/cloud_sms/request/base.rb +83 -0
- data/lib/aliyun/cloud_sms/request/message_query.rb +34 -0
- data/lib/aliyun/cloud_sms/request/message_send.rb +32 -0
- data/lib/aliyun/cloud_sms/version.rb +1 -1
- metadata +25 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11d78bf025f601b8bea4127c55db87ef68307c5a
|
4
|
+
data.tar.gz: 95f9e07fb0caeffe2941443e7ce513ad1f39f6a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 317b1c814f11d02a947cd63313c5e9ffddb2ffe6271d4b3cdd00396143a35a0fb513c81a62f2df5dc39adc2b7528e74984f18b2a2a1ce456c90bf94a67f32628
|
7
|
+
data.tar.gz: 200d2db45fd2edc3c973668f3f7d29f5f7ca296ab460836ee78d73f4148d2bee3c58502bb3e2b2ed2375e6691275eb350b1c079d2508a64ec8ea56977637bba4
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Aliyun::CloudSms
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem is used for sending sms via aliyun sms service, and querying the message status as well.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -47,6 +45,22 @@ client = Aliyun::CloudSms.new('your_access_key_id', 'your_access_key_secret', 'y
|
|
47
45
|
client.send_msg('13800000000', 'SMS_80190090', {"customer": "jere"} )
|
48
46
|
```
|
49
47
|
|
48
|
+
`template_params` can be a string as well.
|
49
|
+
```ruby
|
50
|
+
client.send_msg('13800000000', 'SMS_80190090', "{\"customer\":\"jeremy\"}" )
|
51
|
+
```
|
52
|
+
|
53
|
+
## Message query
|
54
|
+
```ruby
|
55
|
+
client.query_status(mobile, send_date = "#{Time.now.strftime('%Y%m%d')}", biz_id = nil, page_size = 1, current_page = 1)
|
56
|
+
|
57
|
+
# e.g.
|
58
|
+
client.query_status '13800000000'
|
59
|
+
client.query_status '13800000000', '20170806'
|
60
|
+
client.query_status '13800000000', '20170806', '109177619494^4112265203597'
|
61
|
+
client.query_status '13800000000', '20170806', nil, 10
|
62
|
+
client.query_status '13800000000', '20170806', nil, 10, 2
|
63
|
+
```
|
50
64
|
## Development
|
51
65
|
|
52
66
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/aliyun-cloud_sms.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_dependency "uuid", ">=2.0", "<6.0"
|
25
|
+
spec.add_dependency "rest-client", ">=2.0", "<6.0"
|
25
26
|
|
26
27
|
spec.add_development_dependency "bundler", "~> 1.14"
|
27
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'cgi'
|
4
|
-
require 'openssl'
|
5
|
-
require 'base64'
|
1
|
+
require 'aliyun/cloud_sms/request/message_send'
|
2
|
+
require 'aliyun/cloud_sms/request/message_query'
|
6
3
|
|
7
4
|
module Aliyun::CloudSms
|
8
5
|
class Client
|
@@ -14,65 +11,19 @@ module Aliyun::CloudSms
|
|
14
11
|
self.sign_name = sign_name
|
15
12
|
end
|
16
13
|
|
17
|
-
SERVICE_URL = "http://dysmsapi.aliyuncs.com/"
|
18
14
|
|
19
15
|
def send_msg(mobile, template_code, template_param)
|
20
|
-
|
21
|
-
|
22
|
-
q_full= "Signature=#{sign(q_without_sig)}&#{q_without_sig}"
|
16
|
+
request = Request::MessageSend.new mobile, template_code, template_param
|
17
|
+
request.client = self
|
23
18
|
|
24
|
-
|
25
|
-
response = RestClient.get "#{SERVICE_URL}?#{q_full}"
|
26
|
-
rescue RestClient::ExceptionWithResponse => e
|
27
|
-
Rails.logger.error(e.response) if defined? Rails
|
28
|
-
end
|
19
|
+
request.send_request
|
29
20
|
end
|
30
21
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
:PhoneNumbers => mobile,
|
35
|
-
:TemplateCode => template_code,
|
36
|
-
:TemplateParam => template_param.to_json.to_s,
|
37
|
-
:Timestamp => timestamp,
|
38
|
-
:SignatureNonce => nonce,
|
39
|
-
}
|
40
|
-
end
|
22
|
+
def query_status(mobile, send_date = "#{Time.now.strftime('%Y%m%d')}", biz_id = nil, page_size = 1, current_page = 1)
|
23
|
+
request = Request::MessageQuery.new mobile, send_date, biz_id, page_size, current_page
|
24
|
+
request.client = self
|
41
25
|
|
42
|
-
|
43
|
-
|
44
|
-
:AccessKeyId => self.access_key_id,
|
45
|
-
:SignName => self.sign_name,
|
46
|
-
:Action => Aliyun::CloudSms.action,
|
47
|
-
:Format => Aliyun::CloudSms.format,
|
48
|
-
:RegionId => Aliyun::CloudSms.region_id,
|
49
|
-
:SignatureMethod => Aliyun::CloudSms.signature_method,
|
50
|
-
:SignatureVersion => Aliyun::CloudSms.signature_version,
|
51
|
-
:Version => Aliyun::CloudSms.sms_version
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
def timestamp
|
56
|
-
Time.now.utc.strftime("%FT%TZ")
|
57
|
-
end
|
58
|
-
|
59
|
-
def nonce
|
60
|
-
UUID.generate
|
61
|
-
end
|
62
|
-
|
63
|
-
def build_url(hash)
|
64
|
-
hash.map{|k,v|"#{encode(k.to_s)}=#{encode(v.to_s)}"}.sort.join('&')
|
65
|
-
end
|
66
|
-
|
67
|
-
def encode(str)
|
68
|
-
CGI.escape(str)
|
69
|
-
end
|
70
|
-
|
71
|
-
def sign(str)
|
72
|
-
str = "GET&#{encode('/')}&#{encode(str)}"
|
73
|
-
ret = OpenSSL::HMAC.digest('sha1', "#{self.access_key_secret}&", str)
|
74
|
-
ret = Base64.encode64(ret)
|
75
|
-
encode(ret.chomp)
|
76
|
-
end
|
26
|
+
request.send_request
|
27
|
+
end
|
77
28
|
end
|
78
29
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Aliyun::CloudSms
|
2
2
|
module Configure
|
3
|
-
@@action = "SendSms"
|
4
3
|
@@format = "JSON"
|
5
4
|
@@region_id = "cn-hangzhou"
|
6
5
|
@@signature_method = "HMAC-SHA1"
|
@@ -27,14 +26,6 @@ module Aliyun::CloudSms
|
|
27
26
|
@@sign_name = sign_name
|
28
27
|
end
|
29
28
|
|
30
|
-
def action=(action)
|
31
|
-
@@action = action
|
32
|
-
end
|
33
|
-
|
34
|
-
def action
|
35
|
-
@@action
|
36
|
-
end
|
37
|
-
|
38
29
|
def format
|
39
30
|
@@format
|
40
31
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'uuid'
|
2
|
+
require 'json'
|
3
|
+
require 'cgi'
|
4
|
+
require 'openssl'
|
5
|
+
require 'base64'
|
6
|
+
require 'rest-client'
|
7
|
+
|
8
|
+
module Aliyun
|
9
|
+
module CloudSms
|
10
|
+
module Request
|
11
|
+
class Base
|
12
|
+
|
13
|
+
attr_accessor :client
|
14
|
+
|
15
|
+
SERVICE_URL = "http://dysmsapi.aliyuncs.com/"
|
16
|
+
|
17
|
+
def action
|
18
|
+
""
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_params
|
22
|
+
custom_params.merge intrinsic_params
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_request
|
26
|
+
q_without_sig = build_url(get_params)
|
27
|
+
q_full= "Signature=#{sign(q_without_sig)}&#{q_without_sig}"
|
28
|
+
|
29
|
+
begin
|
30
|
+
response = RestClient.get "#{SERVICE_URL}?#{q_full}"
|
31
|
+
rescue RestClient::ExceptionWithResponse => e
|
32
|
+
puts e.response
|
33
|
+
Rails.logger.error(e.response) if defined? Rails
|
34
|
+
e.response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def custom_params
|
40
|
+
{}
|
41
|
+
end
|
42
|
+
|
43
|
+
def intrinsic_params
|
44
|
+
{
|
45
|
+
:AccessKeyId => client.access_key_id,
|
46
|
+
:SignName => client.sign_name,
|
47
|
+
:Format => Aliyun::CloudSms.format,
|
48
|
+
:RegionId => Aliyun::CloudSms.region_id,
|
49
|
+
:SignatureMethod => Aliyun::CloudSms.signature_method,
|
50
|
+
:SignatureVersion => Aliyun::CloudSms.signature_version,
|
51
|
+
:Timestamp => timestamp,
|
52
|
+
:SignatureNonce => nonce,
|
53
|
+
:Action => action,
|
54
|
+
:Version => Aliyun::CloudSms.sms_version
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def timestamp
|
59
|
+
Time.now.utc.strftime("%FT%TZ")
|
60
|
+
end
|
61
|
+
|
62
|
+
def nonce
|
63
|
+
UUID.generate
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_url(hash)
|
67
|
+
hash.map{|k,v|"#{encode(k.to_s)}=#{encode(v.to_s)}"}.sort.join('&')
|
68
|
+
end
|
69
|
+
|
70
|
+
def encode(str)
|
71
|
+
CGI.escape(str)
|
72
|
+
end
|
73
|
+
|
74
|
+
def sign(str)
|
75
|
+
str = "GET&#{encode('/')}&#{encode(str)}"
|
76
|
+
ret = OpenSSL::HMAC.digest('sha1', "#{client.access_key_secret}&", str)
|
77
|
+
ret = Base64.encode64(ret)
|
78
|
+
encode(ret.chomp)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module CloudSms
|
3
|
+
module Request
|
4
|
+
class MessageQuery < Base
|
5
|
+
attr_accessor :mobile, :send_date, :biz_id, :page_size, :current_page
|
6
|
+
|
7
|
+
def initialize(mobile, send_date, biz_id, page_size, current_page)
|
8
|
+
self.mobile = mobile
|
9
|
+
self.send_date = send_date
|
10
|
+
self.biz_id = biz_id
|
11
|
+
self.page_size = page_size
|
12
|
+
self.current_page = current_page
|
13
|
+
end
|
14
|
+
|
15
|
+
def action
|
16
|
+
"QuerySendDetails"
|
17
|
+
end
|
18
|
+
|
19
|
+
def custom_params
|
20
|
+
params = {
|
21
|
+
:PhoneNumber => mobile,
|
22
|
+
:SendDate => send_date,
|
23
|
+
:PageSize => page_size,
|
24
|
+
:CurrentPage => current_page
|
25
|
+
}
|
26
|
+
|
27
|
+
params.merge!({:BizId => biz_id}) if biz_id
|
28
|
+
|
29
|
+
params
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'aliyun/cloud_sms/request/base'
|
2
|
+
|
3
|
+
module Aliyun
|
4
|
+
module CloudSms
|
5
|
+
module Request
|
6
|
+
class MessageSend < Base
|
7
|
+
|
8
|
+
attr_accessor :mobile, :template_code, :template_param
|
9
|
+
|
10
|
+
def initialize(mobile, template_code, template_param)
|
11
|
+
self.mobile = mobile
|
12
|
+
self.template_code = template_code
|
13
|
+
self.template_param = template_param
|
14
|
+
end
|
15
|
+
|
16
|
+
def action
|
17
|
+
"SendSms"
|
18
|
+
end
|
19
|
+
|
20
|
+
def custom_params
|
21
|
+
self.template_param = self.template_param.to_json if self.template_param.is_a?(Hash)
|
22
|
+
|
23
|
+
{
|
24
|
+
:PhoneNumbers => self.mobile,
|
25
|
+
:TemplateCode => self.template_code,
|
26
|
+
:TemplateParam => self.template_param.to_s,
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyun-cloud_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Cui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuid
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '6.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rest-client
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.0'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '6.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '6.0'
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: bundler
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,6 +113,9 @@ files:
|
|
93
113
|
- lib/aliyun/cloud_sms.rb
|
94
114
|
- lib/aliyun/cloud_sms/client.rb
|
95
115
|
- lib/aliyun/cloud_sms/configure.rb
|
116
|
+
- lib/aliyun/cloud_sms/request/base.rb
|
117
|
+
- lib/aliyun/cloud_sms/request/message_query.rb
|
118
|
+
- lib/aliyun/cloud_sms/request/message_send.rb
|
96
119
|
- lib/aliyun/cloud_sms/version.rb
|
97
120
|
homepage: https://github.com/jerecui/aliyun-cloud_sms
|
98
121
|
licenses:
|