aliyun-sms-with-10dlc 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +210 -0
- data/README.zh-CN.md +215 -0
- data/Rakefile +2 -0
- data/aliyun-sms.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/aliyun/sms/version.rb +5 -0
- metadata +12 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d272ca1805496d72543154e043c15d4695b7e036fbcce72549bc4c41fce5b2ec
|
4
|
+
data.tar.gz: 341d250d9ed464dac6a8d50c83a98235f056ab651280abec25b09ec7e03be092
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 333e1fc712ee266e56b82eddebaf6fdb59ef0d8b713ac209c9a84b8c20d03054131fc8f0231ae86e76e462b1cbeccf285570ee83aeac76e8f32ec79eda5eecfb
|
7
|
+
data.tar.gz: 96ed0f35602a3f5b0337803f3376e0315930d7cec865616b3eb5e8b9a369c273f2cdf02c7a17375da9f877733eb9b726db3d31579c1ef03388985e01edf2b2d2
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at victor-luo@outlook.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 VICTOR LUO
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
## [中文说明](./README.zh-CN.md)
|
2
|
+
|
3
|
+
# 添加10DLC的接口
|
4
|
+
文档地址:https://help.aliyun.com/document_detail/164194.html
|
5
|
+
|
6
|
+
``` ruby
|
7
|
+
#发送号码
|
8
|
+
mobile = '1646xxxxxxx'
|
9
|
+
#内容
|
10
|
+
text = 'code is 19384'
|
11
|
+
#发送类型
|
12
|
+
type = 'OTP'
|
13
|
+
#10DLC号码
|
14
|
+
from = '1xxxxxxxxxx'
|
15
|
+
Aliyun::Sms.send_globle(mobile, text, from, type)
|
16
|
+
```
|
17
|
+
|
18
|
+
# Aliyun::Sms Ruby Gem for Aliyun Short Message Service(aliyun-sms)
|
19
|
+
|
20
|
+
**Comfortable to aliyun sms *2017-05-25 version* api**
|
21
|
+
|
22
|
+
## Notice
|
23
|
+
|
24
|
+
Currently, aliyun has three services of short message,named:
|
25
|
+
|
26
|
+
1. ali-dayu(阿里大于)
|
27
|
+
2. aliyun-mq(阿里云消息队列)
|
28
|
+
3. aliyun-sms(阿里云短信服务)
|
29
|
+
|
30
|
+
They all are usable, and will merge togather in future. But before merged, they are Independent, and every user only use one between them.
|
31
|
+
|
32
|
+
**This gem only for aliyun-sms(阿里云短信服务), and you must confirm that you just use it. If you can't confirm, please see the document [阿里云短信业务说明](https://help.aliyun.com/document_detail/63097.html?spm=a2c4g.11186623.6.542.6fZlRU) to get guidance.**
|
33
|
+
|
34
|
+
## Before
|
35
|
+
|
36
|
+
Before use aliyun-sms, you must apply and open the aliyun-sms, and get the parameters as follows:
|
37
|
+
|
38
|
+
1. ACCESS\_KEY\_SECRET: apply on aliyun console
|
39
|
+
2. ACCESS\_KEY\_ID: apply on aliyun console
|
40
|
+
3. SIGN\_NAME: get when open the aliyun-sms
|
41
|
+
4. TEMPLATE\_CODE: get when open the aliyun-sms
|
42
|
+
|
43
|
+
## Installation
|
44
|
+
|
45
|
+
### Ruby Common Method
|
46
|
+
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
gem install aliyun-sms
|
50
|
+
```
|
51
|
+
|
52
|
+
### Rails Method
|
53
|
+
|
54
|
+
Add in Gemfile :
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
gem 'aliyun-sms' # Ruby Gems 安装源
|
58
|
+
```
|
59
|
+
|
60
|
+
Run command:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
bundle
|
64
|
+
```
|
65
|
+
|
66
|
+
### Download Method
|
67
|
+
|
68
|
+
Clone and install by rake.
|
69
|
+
|
70
|
+
```bash
|
71
|
+
git clone https://github.com/VICTOR-LUO-F/aliyun-sms.git
|
72
|
+
|
73
|
+
cd aliyun-sms
|
74
|
+
|
75
|
+
rake build
|
76
|
+
|
77
|
+
rake install
|
78
|
+
```
|
79
|
+
|
80
|
+
### Problem and Resolve
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
require 'aliyun/sms'
|
84
|
+
```
|
85
|
+
|
86
|
+
If you get a error as follows, when running above command:
|
87
|
+
|
88
|
+
> ./config/initializers/aliyun-sms.rb:1:in `<top (required)>': uninitialized constant Aliyun::Sms (NameError)
|
89
|
+
|
90
|
+
You could switch to github resource, and modify the the Rails Gemfile to:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
gem 'aliyun-sms', '1.1.1', git: 'https://github.com/VICTOR-LUO-F/aliyun-sms.git'
|
94
|
+
```
|
95
|
+
|
96
|
+
## Usage
|
97
|
+
|
98
|
+
### Ruby Common Program(irb)
|
99
|
+
|
100
|
+
#### First Step:
|
101
|
+
|
102
|
+
```bash
|
103
|
+
$ require 'aliyun/sms'
|
104
|
+
```
|
105
|
+
|
106
|
+
return
|
107
|
+
|
108
|
+
```bash
|
109
|
+
=> true
|
110
|
+
```
|
111
|
+
|
112
|
+
#### Second Step:
|
113
|
+
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
$ Aliyun::Sms.configure do |config|
|
117
|
+
config.access_key_secret = ACCESS_KEY_SECRET
|
118
|
+
config.access_key_id = ACCESS_KEY_ID
|
119
|
+
config.action = 'SendSms' # default value
|
120
|
+
config.format = 'XML' # http return format, value is 'JSON' or 'XML'
|
121
|
+
config.region_id = 'cn-hangzhou' # default value
|
122
|
+
config.sign_name = SIGN_NAME
|
123
|
+
config.signature_method = 'HMAC-SHA1' # default value
|
124
|
+
config.signature_version = '1.0' # default value
|
125
|
+
config.version = '2017-05-25' # default value
|
126
|
+
end
|
127
|
+
|
128
|
+
```
|
129
|
+
return
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
=> "2017-05-25"
|
133
|
+
```
|
134
|
+
|
135
|
+
#### Third Step:
|
136
|
+
|
137
|
+
Send message:
|
138
|
+
|
139
|
+
$ Aliyun::Sms.send(phone_numbers, template_code, template_param, out_id)
|
140
|
+
|
141
|
+
Explanation:
|
142
|
+
|
143
|
+
1. phone_numbers: the phone number, string type, such as '1234567890'. You can use multiple phone numbers devided by comma, such as '1234567890,12388888888'.
|
144
|
+
2. template\_code: message template code, string type, such as 'SMS_12345678'.
|
145
|
+
3. template_param: message template params, tring type, such as '{"code":"666666", "product":"content" }'.
|
146
|
+
4. out_id:out extension id,string type,could be null。
|
147
|
+
|
148
|
+
|
149
|
+
### Rails Application
|
150
|
+
|
151
|
+
#### First Step:
|
152
|
+
|
153
|
+
In Rails direction 'config/initializers/', create file 'aliyun-sms.rb', and add code:
|
154
|
+
|
155
|
+
|
156
|
+
config/initializers/aliyun-sms.rb
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
Aliyun::Sms.configure do |config|
|
160
|
+
config.access_key_secret = ACCESS_KEY_SECRET
|
161
|
+
config.access_key_id = ACCESS_KEY_ID
|
162
|
+
config.action = 'SendSms' # default value
|
163
|
+
config.format = 'XML' # http return format, value is 'JSON' or 'XML'
|
164
|
+
config.region_id = 'cn-hangzhou' # default value
|
165
|
+
config.sign_name = SIGN_NAME
|
166
|
+
config.signature_method = 'HMAC-SHA1' # default value
|
167
|
+
config.signature_version = '1.0' # default value
|
168
|
+
config.version = '2017-05-25' # default value
|
169
|
+
end
|
170
|
+
```
|
171
|
+
then, restart Rails application。
|
172
|
+
|
173
|
+
#### Second Step:
|
174
|
+
|
175
|
+
Send message in your program:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
Aliyun::Sms.send(phone_numbers, template_code, template_param, out_id)
|
179
|
+
```
|
180
|
+
|
181
|
+
Explanation:
|
182
|
+
|
183
|
+
1. phone_numbers: the phone number, string type, such as '1234567890'. You can use multiple phone numbers devided by comma, such as '1234567890,12388888888'.
|
184
|
+
2. template\_code: message template code, string type, such as 'SMS_12345678'.
|
185
|
+
3. template_param: message template params, tring type, such as '{"code":"666666", "product":"content" }'.
|
186
|
+
4. out_id:out extension id,string type,could be null。
|
187
|
+
|
188
|
+
Specially:
|
189
|
+
|
190
|
+
In Rails application program, you could organize your message content as a hash, and trans it bo be a param of Aliyun::Sms.send by to_json method. For instance:
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
...
|
194
|
+
phone_number = '1234567890'
|
195
|
+
template_code = 'SMS_12345678'
|
196
|
+
template_param = {"code"=>"666666", "product"=>"conten" }.to_json
|
197
|
+
Aliyun::Sms.send(phone_numbers, template_code, template_param)
|
198
|
+
...
|
199
|
+
```
|
200
|
+
|
201
|
+
## Development
|
202
|
+
|
203
|
+
According to [Aliyun Official Document](https://help.aliyun.com/document_detail/56189.html?spm=a2c4g.11186623.6.580.o8Fm0S) example, I had written spect test. You could run the test after clone as follows:
|
204
|
+
|
205
|
+
$ bundle exec rspec spec
|
206
|
+
|
207
|
+
|
208
|
+
## License
|
209
|
+
|
210
|
+
MIT License。 [MIT License](http://opensource.org/licenses/MIT).
|
data/README.zh-CN.md
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
## [ENGLISH README](./README.md)
|
2
|
+
|
3
|
+
# 添加10DLC的接口
|
4
|
+
文档地址:https://help.aliyun.com/document_detail/164194.html
|
5
|
+
|
6
|
+
``` ruby
|
7
|
+
#发送号码
|
8
|
+
mobile = '1646xxxxxxx'
|
9
|
+
#内容
|
10
|
+
text = 'code is 19384'
|
11
|
+
#发送类型
|
12
|
+
type = 'OTP'
|
13
|
+
#10DLC号码
|
14
|
+
from = '1xxxxxxxxxx'
|
15
|
+
Aliyun::Sms.send_globle(mobile, text, from, type)
|
16
|
+
```
|
17
|
+
|
18
|
+
# Aliyun::Sms 阿里云短信服务 Ruby Gem aliyun-sms
|
19
|
+
|
20
|
+
**适用于阿里云短信服务最新的 *2017-05-25* 版接口**
|
21
|
+
|
22
|
+
## 特别说明
|
23
|
+
|
24
|
+
目前阿里云通信提供三个短信产品,分别是:
|
25
|
+
|
26
|
+
1. 原阿里大于
|
27
|
+
2. 阿里云消息服务
|
28
|
+
3. 阿里云短信服务
|
29
|
+
|
30
|
+
这三个短信服务均可使用,并将最终深度融合,综合为一个产品。在合并之前,请注意以下几点:
|
31
|
+
|
32
|
+
* 各短信产品账号独立、资金独立;
|
33
|
+
* 各短信产品内使用数据独立;
|
34
|
+
* 各短信产品具有自己的 API&SDK,不可兼容使用;
|
35
|
+
* 同一账号只可使用其中一个产品,不可使用多个产品。
|
36
|
+
|
37
|
+
**这个 gem 针对的是前面所述的第 3 个短信产品,即“阿里云短信服务”。请您在使用 aliyun-sms 前,确认自己申请的阿里云短信产品是“阿里云短信服务”,如果无法确定,请参考官方说明文档[阿里云短信业务说明](https://help.aliyun.com/document_detail/63097.html?spm=a2c4g.11186623.6.542.6fZlRU)进行区分。**
|
38
|
+
|
39
|
+
## 使用前提
|
40
|
+
|
41
|
+
使用 aliyun-sms 前,您必须已经是阿里云注册用户,申请开通了“阿里云短信服务”,并且获得了以下几个关键参数:
|
42
|
+
|
43
|
+
1. ACCESS\_KEY\_SECRET: 阿里云用户密钥,在阿里云控制台申请获取。
|
44
|
+
2. ACCESS\_KEY\_ID: 阿里云用户 ID, 在阿里云控制台申请获取。
|
45
|
+
3. SIGN\_NAME: 短信签名,在阿里云申请开通短信服务时获取。
|
46
|
+
4. TEMPLATE\_CODE: 短信模版代码,在阿里云申请开通短信服务时申请获取。
|
47
|
+
|
48
|
+
## Installation 安装
|
49
|
+
|
50
|
+
### Ruby 通用安装方法
|
51
|
+
在命令行中输入命令(电脑已经安装 gems 命令行工具)
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
gem install aliyun-sms
|
55
|
+
```
|
56
|
+
|
57
|
+
### Rails 应用安装方法
|
58
|
+
|
59
|
+
在应用的 Gemfile 文件中添加 Ruby Gems 安装源:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
gem 'aliyun-sms' # Ruby Gems 安装源
|
63
|
+
```
|
64
|
+
|
65
|
+
应用的根目录下运行:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
bundle
|
69
|
+
```
|
70
|
+
|
71
|
+
### 下载后安装
|
72
|
+
|
73
|
+
使用 Git 将代码克隆到本地后使用 Rake 命令安装
|
74
|
+
|
75
|
+
```bash
|
76
|
+
git clone https://github.com/VICTOR-LUO-F/aliyun-sms.git
|
77
|
+
|
78
|
+
cd aliyun-sms
|
79
|
+
|
80
|
+
rake build
|
81
|
+
|
82
|
+
rake install
|
83
|
+
```
|
84
|
+
|
85
|
+
### 安装可能遇到的问题及其解决方式
|
86
|
+
|
87
|
+
安装后,如果在 irb 命令行输入命令
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require 'aliyun/sms'
|
91
|
+
```
|
92
|
+
|
93
|
+
后,无法正确获取 Gem 引用,或者在 Rails 启动时报错提示如下:
|
94
|
+
|
95
|
+
> ./config/initializers/aliyun-sms.rb:1:in `<top (required)>': uninitialized constant Aliyun::Sms (NameError)
|
96
|
+
|
97
|
+
可以改为 Github 安装源,例如 Rails Gemfile 文件引用可以改为下面格式,即可正确安装。
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
gem 'aliyun-sms', '1.1.1', git: 'https://github.com/VICTOR-LUO-F/aliyun-sms.git'
|
101
|
+
```
|
102
|
+
|
103
|
+
## Usage 使用
|
104
|
+
|
105
|
+
### Ruby 程序通用方法(irb命令行示例)
|
106
|
+
|
107
|
+
#### 第一步:
|
108
|
+
|
109
|
+
```bash
|
110
|
+
$ require 'aliyun/sms'
|
111
|
+
```
|
112
|
+
|
113
|
+
```bash
|
114
|
+
=> true
|
115
|
+
```
|
116
|
+
|
117
|
+
#### 第二步:
|
118
|
+
|
119
|
+
参数设置:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
$ Aliyun::Sms.configure do |config|
|
123
|
+
config.access_key_secret = ACCESS_KEY_SECRET # 阿里云接入密钥,在阿里云控制台申请
|
124
|
+
config.access_key_id = ACCESS_KEY_ID # 阿里云接入 ID, 在阿里云控制台申请
|
125
|
+
config.action = 'SendSms' # 默认设置
|
126
|
+
config.format = 'XML' # 短信推送返回信息格式,可以填写 'JSON'或者'XML'
|
127
|
+
config.region_id = 'cn-hangzhou' # 默认设置,如果没有特殊需要,可以不改
|
128
|
+
config.sign_name = SIGN_NAME # 短信签名,在阿里云申请开通短信服务时申请获取
|
129
|
+
config.signature_method = 'HMAC-SHA1' # 加密算法,默认设置
|
130
|
+
config.signature_version = '1.0' # 签名版本,默认设置,不用修改
|
131
|
+
config.version = '2017-05-25' # 服务版本,默认设置,不用修改
|
132
|
+
end
|
133
|
+
|
134
|
+
```
|
135
|
+
返回
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
=> "2017-05-25"
|
139
|
+
```
|
140
|
+
|
141
|
+
#### 第三步:
|
142
|
+
|
143
|
+
发送短信:
|
144
|
+
|
145
|
+
$ Aliyun::Sms.send(phone_numbers, template_code, template_param, out_id)
|
146
|
+
|
147
|
+
参数说明:
|
148
|
+
|
149
|
+
1. phone_numbers: 接收短信的手机号,必须为字符型,例如 '1234567890',如果有多个号码,中间用","隔开,例如:'1234567890,12388888888';
|
150
|
+
2. template\_code: 短信模版代码,必须为字符型,申请开通短信服务后,由阿里云提供,例如 'SMS_12345678';
|
151
|
+
3. template_param: 请求字符串,向短信模版提供参数,必须是转为字符串的json格式对象,例如 '{"code":"666666", "product":"测试网站" }';
|
152
|
+
4. out_id:外部流水扩展字段,必须为字符型,可以为空。
|
153
|
+
|
154
|
+
|
155
|
+
### Rails 应用使用方法
|
156
|
+
|
157
|
+
#### 第一步:
|
158
|
+
|
159
|
+
在 Rails 应用目录 config/initializers/ 下创建脚本文件 aliyun-sms.rb,在文件中加入以下内容:
|
160
|
+
|
161
|
+
config/initializers/aliyun-sms.rb
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
Aliyun::Sms.configure do |config|
|
165
|
+
config.access_key_secret = ACCESS_KEY_SECRET # 阿里云接入密钥,在阿里云控制台申请
|
166
|
+
config.access_key_id = ACCESS_KEY_ID # 阿里云接入 ID, 在阿里云控制台申请
|
167
|
+
config.action = 'SendSms' # 默认设置
|
168
|
+
config.format = 'XML' # 短信推送返回信息格式,可以填写 'JSON'或者'XML'
|
169
|
+
config.region_id = 'cn-hangzhou' # 默认设置,如果没有特殊需要,可以不改
|
170
|
+
config.sign_name = SIGN_NAME # 短信签名,在阿里云申请开通短信服务时申请获取
|
171
|
+
config.signature_method = 'HMAC-SHA1' # 加密算法,默认设置
|
172
|
+
config.signature_version = '1.0' # 签名版本,默认设置,不用修改
|
173
|
+
config.version = '2017-05-25' # 服务版本,默认设置,不用修改
|
174
|
+
end
|
175
|
+
```
|
176
|
+
之后,重新启动 Rails,加载配置。
|
177
|
+
|
178
|
+
#### 第二步:
|
179
|
+
|
180
|
+
在 Rails 应用中调用短信发送代码:
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
Aliyun::Sms.send(phone_numbers, template_code, template_param, out_id)
|
184
|
+
```
|
185
|
+
|
186
|
+
参数说明:
|
187
|
+
|
188
|
+
1. phone_numbers: 接收短信的手机号,必须为字符型,例如 '1234567890',如果有多个号码,中间用","隔开,例如:'1234567890,12388888888';
|
189
|
+
2. template\_code: 短信模版代码,必须为字符型,申请开通短信服务后,由阿里云提供,例如 'SMS_12345678';
|
190
|
+
3. template_param: 请求字符串,向短信模版提供参数,必须是转为字符串的json格式对象,例如 '{"code":"666666", "product":"测试网站" }';
|
191
|
+
4. out_id:外部流水扩展字段,必须为字符型,可以为空。
|
192
|
+
|
193
|
+
特别说明:
|
194
|
+
|
195
|
+
在程序中可以先用 HASH 组织 template\_param 内容,再使用 to_json 方法转换为 json 格式字符串,例如:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
...
|
199
|
+
phone_number = '1234567890'
|
200
|
+
template_code = 'SMS_12345678'
|
201
|
+
template_param = {"code"=>"666666", "product"=>"测试网站" }.to_json
|
202
|
+
Aliyun::Sms.send(phone_numbers, template_code, template_param)
|
203
|
+
...
|
204
|
+
```
|
205
|
+
|
206
|
+
## Development 开发
|
207
|
+
|
208
|
+
按照阿里云[官方接口文档](https://help.aliyun.com/document_detail/56189.html?spm=a2c4g.11186623.6.580.o8Fm0S)提供的 SMS 样例做了 spect 测试,可以 clone 项目后,在根目录下用命令行运行以下命令测试:
|
209
|
+
|
210
|
+
$ bundle exec rspec spec
|
211
|
+
|
212
|
+
|
213
|
+
## License 许可
|
214
|
+
|
215
|
+
MIT 协议下的开源项目。 [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/aliyun-sms.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aliyun/sms/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aliyun-sms-with-10dlc"
|
8
|
+
spec.version = Aliyun::Sms::VERSION
|
9
|
+
spec.authors = ["kun"]
|
10
|
+
spec.email = ["zhukun6150909@outlook.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Ruby Gem for using aliyun sms service, in accordance with aliyun sms 2017-05-25 version api. 适用于阿里云短信服务最新的 2017-05-25 版接口.}
|
13
|
+
spec.description = %q{A Ruby Gem for using aliyun sms service, in accordance with aliyun sms 2017-05-25 version api. 适用于阿里云短信服务最新的 2017-05-25 版接口.}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_dependency "typhoeus"
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "aliyun/sms"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyun-sms-with-10dlc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kun
|
@@ -74,7 +74,18 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- CODE_OF_CONDUCT.md
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- README.zh-CN.md
|
83
|
+
- Rakefile
|
84
|
+
- aliyun-sms.gemspec
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
77
87
|
- lib/aliyun/sms.rb
|
88
|
+
- lib/aliyun/sms/version.rb
|
78
89
|
homepage: ''
|
79
90
|
licenses:
|
80
91
|
- MIT
|