tencent_simple_sms 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a80372c270c3bf999fc6a3efa56e1b0a11d3833ccba4f700269aeff48bc0ab8d
4
+ data.tar.gz: cdf3427235d24bf196c8490be4f0530d9db5c1cf9f1112fb84f24bbf410fa237
5
+ SHA512:
6
+ metadata.gz: cccebc277a3d88aeefea8581bafb5c65f87a9c8292f8f92496126822221a1de8670d47c48b6d3fb7be2bf2fe5300d92c3e5200a606940f45da096e01695477e9
7
+ data.tar.gz: 6f43cff2de3f5c9a164acd31e36d268773a902bd664618943bfca4f9ca0a3e8535cc7baec27c30ef3a44ec132a367906bb667815d2fbb99c9af87226f4c68041
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 anke1460
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.
@@ -0,0 +1,49 @@
1
+ # tencent_simple_sms
2
+
3
+ 基于腾讯云短信服务的简易发送短信Ruby gem
4
+
5
+ ## 按照
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tencent_simple_sms'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tencent_simple_sms
20
+
21
+ ## Usage
22
+
23
+ #### 在config/initializers目录下添加配置文件tencent_simple_sms.rb
24
+
25
+ ```ruby
26
+ TencentSimpleSms.configure do |config|
27
+ config.app_id = ''
28
+ config.secret_id = ''
29
+ config.secret_key = ''
30
+ config.sign = ''
31
+ end
32
+
33
+ ```
34
+ #### 发送短信, 支持支付多个手机号发送,一次最多支持[200个手机号](https://cloud.tencent.com/document/product/382/38778)
35
+
36
+ ```ruby
37
+ TencentSimpleSms.sender ['13111111111', '13111111112'], templ_id
38
+ ```
39
+
40
+
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tencent_simple_sms.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,19 @@
1
+ require 'net/http'
2
+ require 'securerandom'
3
+ require 'openssl'
4
+ require "base64"
5
+
6
+ require "tencent_simple_sms/version"
7
+ require "tencent_simple_sms/sms"
8
+ require "tencent_simple_sms/config"
9
+
10
+
11
+ module TencentSimpleSms
12
+ class Error < StandardError; end
13
+
14
+ class << self
15
+ def configure(&block)
16
+ Config.configure(&block)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module TencentSimpleSms
2
+ class Config
3
+ class << self
4
+ attr_accessor :app_id, :secret_id, :secret_key, :sign
5
+
6
+ def configure
7
+ yield self
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ module TencentSimpleSms
2
+ class << self
3
+ def sender(mobiles, templ_id)
4
+ request = {}
5
+ mobiles.each_with_index do |m, i|
6
+ request["PhoneNumberSet.#{i}"] = "+86#{m}"
7
+ end
8
+ request['Action'] = 'SendSms'
9
+ request['Region'] = ''
10
+ request["Version"] = '2019-07-11'
11
+ request["TemplateID"] = templ_id
12
+ request['Sign'] = Config.sign
13
+ request['SmsSdkAppid'] = Config.app_id
14
+ request['Timestamp'] = Time.now.to_i
15
+ request['Nonce'] = SecureRandom.random_number.to_s.slice(-10..-1)
16
+ request['SecretId'] = Config.secret_id
17
+ request['Signature'] = sig(request)
18
+ http_post('https://sms.tencentcloudapi.com', request)
19
+ end
20
+
21
+ def http_post(url, postdata)
22
+ Net::HTTP.post_form(URI(url),postdata).body
23
+ end
24
+
25
+
26
+ def params_to_string(params)
27
+ params.sort.map { |item| item.join('=') }.join('&')
28
+ end
29
+
30
+ def sig(request)
31
+ signature = params_to_string(request)
32
+ signature = "POSTsms.tencentcloudapi.com/?" + signature
33
+ digest = OpenSSL::Digest.new('sha1')
34
+ Base64.encode64(OpenSSL::HMAC.digest(digest, Config.secret_key, signature))
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module TencentSimpleSms
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tencent_simple_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - anke1460
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: An unofficial simple tencent cloud sms gem.
14
+ email:
15
+ - zuosjob@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - lib/tencent_simple_sms.rb
23
+ - lib/tencent_simple_sms/config.rb
24
+ - lib/tencent_simple_sms/sms.rb
25
+ - lib/tencent_simple_sms/version.rb
26
+ homepage: https://github.com/anke1460/tencent_cloud_sms
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.7.7
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: An unofficial simple tencent cloud sms gem.
50
+ test_files: []