alidayu-ruby 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94314df41f0fea93bf91a2c8f334b6add3e71f9d
4
+ data.tar.gz: d76e747ae87fc3ab17cc295f89801f6e8a4d00df
5
+ SHA512:
6
+ metadata.gz: 08aa201faf3c20caf7e182e98654ff52e2b39f1f894d09d0048c8a838c66e30e13b3e1c9abc21b13d61b40654b5cd94c3668edd26968f14456f2492b13e15599
7
+ data.tar.gz: 8adf8b7726981bb745862ece4d7f73cfeae063ee09489f1d0e277d89529a5f3a709f769902e73acce5b089263a171100cf47426fc71f0a4dbed0654f63af2653
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alidayu-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 david
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,62 @@
1
+ # Alidayu::Ruby
2
+
3
+ 阿里大鱼发送短信ruby sdk
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'alidayu-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install alidayu-ruby
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # 配置 appkey 和 appsecret
25
+ # 如果使用rails 可以放到 config/alidayu.rb
26
+
27
+ Alidayu.appkey = ""
28
+ Alidayu.appsecret = ""
29
+
30
+ # 发短信
31
+ # 必须参数
32
+ # template_id 模版ID String
33
+ # params 模版参数 Hash
34
+ # phones 电话号码 String or String[]
35
+ # sign_name 签名
36
+
37
+ # 具体文档 http://open.taobao.com/doc2/apiDetail?apiId=25450
38
+
39
+ Alidayu.send_sms({
40
+ template_id: "SMS_0000000",
41
+ sign_name: "身份验证",
42
+ params: {
43
+ code: '',
44
+ product: '',
45
+ },
46
+ phones: "填写电话号码"
47
+ })
48
+ ```
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it ( https://github.com/davidqhr/alidayu-ruby/fork )
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alidayu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alidayu-ruby"
8
+ spec.version = Alidayu::VERSION
9
+ spec.authors = ["david"]
10
+ spec.email = ["davidqhr@gmail.com"]
11
+
12
+ spec.summary = %q{阿里大鱼发送短信ruby sdk}
13
+ spec.description = %q{阿里大鱼发送短信ruby sdk}
14
+ spec.homepage = "https://github.com/davidqhr/alidayu-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency 'rspec'
25
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alidayu/alidayu"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,73 @@
1
+ require "alidayu/version"
2
+ require 'json'
3
+ require 'net/https'
4
+ require 'uri'
5
+
6
+ module Alidayu
7
+ class << self
8
+ attr_accessor :appkey, :appsecret
9
+
10
+ # 必须参数
11
+ # template_id 模版ID String
12
+ # params 模版参数 Hash
13
+ # phones 电话号码 String or String[]
14
+ # sign_name 签名
15
+ def send_sms params
16
+ params = build_params(params)
17
+
18
+ uri = URI.parse('https://eco.taobao.com/router/rest')
19
+
20
+ http = Net::HTTP.new(uri.host, uri.port)
21
+ http.use_ssl = true
22
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
23
+
24
+ request = Net::HTTP::Post.new(uri.path)
25
+ request.add_field('Content-Type', 'application/json')
26
+ request.set_form_data(params)
27
+ response = http.request(request)
28
+ res_body = JSON.parse response.body
29
+ res_body
30
+ end
31
+
32
+ private
33
+
34
+ def build_params params
35
+ alidayu_params = {
36
+ :method => 'alibaba.aliqin.fc.sms.num.send',
37
+ :app_key => appkey,
38
+ :timestamp => Time.new.strftime("%Y-%m-%d %T"),
39
+ :format => 'json',
40
+ :v => '2.0',
41
+ :sign_method => 'md5',
42
+ :sms_type => 'normal',
43
+ }
44
+
45
+ # 电话号码
46
+ if params[:phones].is_a? String
47
+ alidayu_params[:rec_num] = params[:phones]
48
+ elsif params[:phones].is_a? Array
49
+ alidayu_params[:rec_num] = params[:phones].join(',')
50
+ else
51
+ raise 'phones格式错误'
52
+ end
53
+
54
+ # 模版ID
55
+ alidayu_params[:sms_template_code] = params[:template_id]
56
+
57
+ # 模版参数
58
+ alidayu_params[:sms_param] = JSON(params[:params])
59
+
60
+ # 签名
61
+ alidayu_params[:sms_free_sign_name] = params[:sign_name] || sign_name
62
+
63
+ sign = sign alidayu_params
64
+ alidayu_params.merge!({:sign => sign})
65
+ alidayu_params
66
+ end
67
+
68
+ def sign params
69
+ joind_string = params.sort_by{ |k,v| k}.to_h.map { |k, v| "#{k}#{v}" }.join('')
70
+ Digest::MD5.hexdigest("#{appsecret}#{joind_string}#{appsecret}").upcase
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Alidayu
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alidayu-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - david
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-22 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: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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
+ description: "阿里大鱼发送短信ruby sdk"
56
+ email:
57
+ - davidqhr@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - alidayu-ruby.gemspec
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/alidayu/alidayu.rb
73
+ - lib/alidayu/version.rb
74
+ homepage: https://github.com/davidqhr/alidayu-ruby
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: "阿里大鱼发送短信ruby sdk"
98
+ test_files: []