aliyun-sms-with-10dlc 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2e9a0411cb80d00b36254d93bcc13aed243d51d22778632b67cebcc9f22f173c
4
+ data.tar.gz: eedaa36346fa47ecc3cbcc2ffd7574f1c8dcedfb4ad7c0e5cc191dbd5a987071
5
+ SHA512:
6
+ metadata.gz: 875cc1bdc2d217f3e3ed5738bf850d3027dfe96832f5f5282edf3ff4d2a9abe9672d8b691814f49a34f7202f88347db613af1c89dd969f6ba2aaf77ac8ef2801
7
+ data.tar.gz: 0f8ad0160113e6fdedc4bc9a8fae687ba801811e2543a7d437813841185316c354cac9674e66e988b52ad939433228436e1154ebc138937f77899498a9d0d1f5
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
@@ -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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aliyun-sms.gemspec
4
+ gemspec
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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,29 @@
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
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_dependency "typhoeus"
29
+ 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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ module Aliyun
2
+ module Sms
3
+ VERSION = "1.1.2"
4
+ end
5
+ end
data/lib/aliyun/sms.rb ADDED
@@ -0,0 +1,136 @@
1
+ require "aliyun/sms/version"
2
+ require "openssl"
3
+ require "base64"
4
+ require 'typhoeus'
5
+ require "erb"
6
+ include ERB::Util
7
+
8
+ module Aliyun
9
+ module Sms
10
+ class Configuration
11
+ attr_accessor :access_key_secret, :access_key_id, :action, :format, :region_id,
12
+ :sign_name, :signature_method, :signature_version, :version
13
+
14
+ def initialize
15
+ @access_key_secret = ''
16
+ @access_key_id = ''
17
+ @action = ''
18
+ @format = ''
19
+ @region_id = ''
20
+ @sign_name = ''
21
+ @signature_method = ''
22
+ @signature_version = ''
23
+ @version = ''
24
+ end
25
+ end
26
+
27
+ class << self
28
+ attr_writer :configuration
29
+
30
+ def configuration
31
+ @configuration ||= Configuration.new
32
+ end
33
+
34
+ def configure
35
+ yield(configuration)
36
+ end
37
+
38
+ def send(phone_numbers, template_code, template_param, out_id = '')
39
+ Typhoeus.get(get_url({
40
+ 'PhoneNumbers' => phone_numbers,
41
+ 'TemplateCode' => template_code,
42
+ 'TemplateParam' => template_param,
43
+ 'OutId' => out_id,
44
+ 'SignatureNonce' => seed_signature_nonce,
45
+ 'Timestamp' => seed_timestamp
46
+ }))
47
+ end
48
+
49
+ def send_globle(mobile, text, from, type = 'OTP')
50
+ Typhoeus.get(get_url({
51
+ 'Action' => 'SendMessageToGlobe',
52
+ 'Message' => text,
53
+ 'To' => mobile,
54
+ 'From' => from,
55
+ 'Type' => type,
56
+ 'SignatureNonce' => seed_signature_nonce,
57
+ 'Timestamp' => seed_timestamp
58
+ }))
59
+ end
60
+
61
+ def get_url(user_params)
62
+ params = get_params(user_params)
63
+ coded_params = canonicalized_query_string(params)
64
+ key_secret = configuration.access_key_secret
65
+ url = 'http://dysmsapi.aliyuncs.com/?' + 'Signature=' + sign(key_secret, coded_params) + '&' + coded_params
66
+ end
67
+
68
+ def get_params(user_params)
69
+ params = config_params.merge(user_params)
70
+ end
71
+
72
+ def config_params()
73
+ params ={
74
+ 'AccessKeyId' => configuration.access_key_id,
75
+ 'Action' => configuration.action,
76
+ 'Format' => configuration.format,
77
+ 'RegionId' => configuration.region_id,
78
+ 'SignName' => configuration.sign_name,
79
+ 'SignatureMethod' => configuration.signature_method,
80
+ 'SignatureVersion' => configuration.signature_version,
81
+ 'Version' => configuration.version
82
+ }
83
+ end
84
+
85
+ def canonicalized_query_string(params)
86
+ cqstring = ''
87
+ params.sort_by{|key, val| key}.each do |key, value|
88
+ if cqstring.empty?
89
+ cqstring += "#{encode(key)}=#{encode(value)}"
90
+ else
91
+ cqstring += "&#{encode(key)}=#{encode(value)}"
92
+ end
93
+ end
94
+ cqstring
95
+ end
96
+
97
+ # 生成数字签名
98
+ def sign(key_secret, coded_params)
99
+ key = key_secret + '&'
100
+ signature = 'GET' + '&' + encode('/') + '&' + encode(coded_params)
101
+ sign = Base64.encode64("#{OpenSSL::HMAC.digest('sha1',key, signature)}")
102
+ encode(sign.chomp) # 通过chomp去掉最后的换行符 LF
103
+ end
104
+
105
+ # 对字符串进行 PERCENT 编码
106
+ def encode(input)
107
+ output = url_encode(input)
108
+ end
109
+
110
+ # 生成短信时间戳
111
+ def seed_timestamp
112
+ Time.now.utc.strftime("%FT%TZ")
113
+ end
114
+
115
+ # 生成短信唯一标识码,采用到微秒的时间戳
116
+ def seed_signature_nonce
117
+ Time.now.utc.strftime("%Y%m%d%H%M%S%L")
118
+ end
119
+
120
+ # 测试参数未编码时生成的字符串是否正确(多一道保险)
121
+ def test_query_string(params)
122
+ qstring = ''
123
+ params.sort_by{|key, val| key}.each do |key, value|
124
+ if qstring.empty?
125
+ qstring += "#{key}=#{value}"
126
+ else
127
+ qstring += "&#{key}=#{value}"
128
+ end
129
+ end
130
+ qstring
131
+ end
132
+
133
+ end
134
+
135
+ end
136
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aliyun-sms-with-10dlc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ platform: ruby
6
+ authors:
7
+ - kun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A Ruby Gem for using aliyun sms service, in accordance with aliyun sms
70
+ 2017-05-25 version api. 适用于阿里云短信服务最新的 2017-05-25 版接口.
71
+ email:
72
+ - zhukun6150909@outlook.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
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
87
+ - lib/aliyun/sms.rb
88
+ - lib/aliyun/sms/version.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.1.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A Ruby Gem for using aliyun sms service, in accordance with aliyun sms 2017-05-25
112
+ version api. 适用于阿里云短信服务最新的 2017-05-25 版接口.
113
+ test_files: []