ali_dayu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/ali_dayu.gemspec +34 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ali_dayu/base.rb +41 -0
- data/lib/ali_dayu/sms.rb +31 -0
- data/lib/ali_dayu/version.rb +3 -0
- data/lib/ali_dayu/voice.rb +30 -0
- data/lib/ali_dayu.rb +22 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b0d84da374371e4362eeec0942941d9d3a2b870
|
4
|
+
data.tar.gz: 4c80110502d6bbd09811695794c9943c0e12fb34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 850253d507f50a356fb7e4cb5df7310d2354ebf57953e397a82d6c155d604c9e6263337e3dfbbcbaa350a35078edc072205ce3b4aa06379009dd5a08a98f3bc4
|
7
|
+
data.tar.gz: ac2e1a96d2d6006443250eb2037a8f48fac4c75216455bd9fe22c7721431b58d8a02a9f2ad4b1bfb2a46b3397e99e78bdf10d1f9ced1e01dee944604c22ffd52
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# AliDayu
|
2
|
+
|
3
|
+
阿里大鱼的短信、语音发送
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ali_dayu'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ali_dayu
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
|
24
|
+
AliDayu.app_key = "23492851"
|
25
|
+
AliDayu.app_secret = "913d361c4d210badaaa759d2bddc8e0c"
|
26
|
+
AliDayu.post_url = "http://gw.api.taobao.com/router/rest"
|
27
|
+
#AliDayu.sms_send('18600256695', {code: '123456', product: '进货宝'}, 'SMS_22585207', '进货宝')
|
28
|
+
AliDayu.voice_send('18600256695', {product: '进货宝', code: '123456'}, 'TTS_22585215', '051482043260')
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
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.
|
33
|
+
|
34
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ali_dayu.
|
39
|
+
|
data/Rakefile
ADDED
data/ali_dayu.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ali_dayu/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ali_dayu"
|
8
|
+
spec.version = AliDayu::VERSION
|
9
|
+
spec.authors = ["windstill"]
|
10
|
+
spec.email = ["202070317@163.com"]
|
11
|
+
|
12
|
+
spec.summary = "ali dayu"
|
13
|
+
spec.description = "ali dayu sms & voice"
|
14
|
+
spec.homepage = "https://github.com/WindStill/ali_dayu"
|
15
|
+
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
19
|
+
# delete this section to allow pushing this gem to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ali_dayu"
|
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,41 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'digest'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class AliDayu::Base
|
6
|
+
attr_accessor :app_key, :app_secret, :post_url
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
self.app_key = options['app_key'] || AliDayu.app_key
|
10
|
+
self.app_secret = options['app_secret'] || AliDayu.app_secret
|
11
|
+
self.post_url = options['post_url'] || AliDayu.post_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def deliver(*args)
|
15
|
+
raise NotImplementedError, 'crontab must be implemented'
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def sort_options(arg)
|
20
|
+
hash = Hash.new
|
21
|
+
arg.sort.map{|e| hash[e[0]] = e[1] }
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
|
25
|
+
def encrypt(arg)
|
26
|
+
_arg = arg.map{|k,v| "#{k}#{v}"}
|
27
|
+
::Digest::MD5.hexdigest("#{self.app_secret}#{_arg.join("")}#{self.app_secret}").upcase
|
28
|
+
end
|
29
|
+
|
30
|
+
def post(uri, options)
|
31
|
+
response = ""
|
32
|
+
url = URI.parse(uri)
|
33
|
+
Net::HTTP.start(url.host, url.port) do |http|
|
34
|
+
req = Net::HTTP::Post.new(url.path)
|
35
|
+
req.set_form_data(options)
|
36
|
+
response = http.request(req).body
|
37
|
+
end
|
38
|
+
|
39
|
+
JSON.parse(response)
|
40
|
+
end
|
41
|
+
end
|
data/lib/ali_dayu/sms.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class AliDayu::Sms < AliDayu::Base
|
2
|
+
|
3
|
+
def deliver(*args)
|
4
|
+
_telphones, _sms_param, _sms_template_code, _sms_free_sign_name, _extend = args
|
5
|
+
_timestamp = Time.now.strftime("%F %T")
|
6
|
+
options = {
|
7
|
+
app_key: self.app_key,
|
8
|
+
format: 'json',
|
9
|
+
method: 'alibaba.aliqin.fc.sms.num.send',
|
10
|
+
partner_id: 'apidoc',
|
11
|
+
sign_method: 'md5',
|
12
|
+
timestamp: _timestamp,
|
13
|
+
v: '2.0',
|
14
|
+
extend: _extend,
|
15
|
+
sms_type: 'normal',
|
16
|
+
sms_free_sign_name: _sms_free_sign_name,
|
17
|
+
sms_param: _sms_param.to_json,
|
18
|
+
rec_num: _telphones,
|
19
|
+
sms_template_code: _sms_template_code
|
20
|
+
}
|
21
|
+
|
22
|
+
options = sort_options(options)
|
23
|
+
puts "options: #{options}"
|
24
|
+
md5_str = encrypt(options)
|
25
|
+
options.merge!(sign: md5_str)
|
26
|
+
|
27
|
+
response = post(self.post_url, options.merge(sign: md5_str))
|
28
|
+
puts "phones: #{_telphones}, #{_sms_param}, and respone: #{response}"
|
29
|
+
response
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class AliDayu::Voice < AliDayu::Base
|
2
|
+
|
3
|
+
def deliver(*args)
|
4
|
+
_telphones, _tts_param, _tts_code, _called_show_num, _extend = args
|
5
|
+
_timestamp = Time.now.strftime("%F %T")
|
6
|
+
options = {
|
7
|
+
app_key: self.app_key,
|
8
|
+
format: 'json',
|
9
|
+
method: 'alibaba.aliqin.fc.tts.num.singlecall',
|
10
|
+
partner_id: 'apidoc',
|
11
|
+
sign_method: 'md5',
|
12
|
+
timestamp: _timestamp,
|
13
|
+
v: '2.0',
|
14
|
+
extend: _extend,
|
15
|
+
tts_param: _tts_param.to_json,
|
16
|
+
called_num: _telphones,
|
17
|
+
called_show_num: _called_show_num,
|
18
|
+
tts_code: _tts_code
|
19
|
+
}
|
20
|
+
|
21
|
+
options = sort_options(options)
|
22
|
+
puts "options: #{options}"
|
23
|
+
md5_str = encrypt(options)
|
24
|
+
options.merge!(sign: md5_str)
|
25
|
+
|
26
|
+
response = post(self.post_url, options.merge(sign: md5_str))
|
27
|
+
puts "phones: #{_telphones}, #{_tts_param}, and respone: #{response}"
|
28
|
+
response
|
29
|
+
end
|
30
|
+
end
|
data/lib/ali_dayu.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#require File.expand_path('../ali_dayu/version', __FILE__)
|
2
|
+
#require File.expand_path('../ali_dayu/base', __FILE__)
|
3
|
+
#require File.expand_path('../ali_dayu/sms', __FILE__)
|
4
|
+
#require File.expand_path('../ali_dayu/voice', __FILE__)
|
5
|
+
require "ali_dayu/version"
|
6
|
+
require "ali_dayu/base"
|
7
|
+
require "ali_dayu/sms"
|
8
|
+
require "ali_dayu/voice"
|
9
|
+
|
10
|
+
module AliDayu
|
11
|
+
class << self
|
12
|
+
attr_accessor :app_key, :app_secret, :post_url
|
13
|
+
|
14
|
+
def sms_send telphones, sms_param, sms_template_code, sms_free_sign_name, extend="", options={}
|
15
|
+
Sms.new(options).deliver(telphones, sms_param, sms_template_code, sms_free_sign_name, extend)
|
16
|
+
end
|
17
|
+
|
18
|
+
def voice_send telphones, sms_param, tts_code, called_show_num, extend="", options={}
|
19
|
+
Voice.new(options).deliver(telphones, sms_param, tts_code, called_show_num, extend)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ali_dayu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- windstill
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-27 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: ali dayu sms & voice
|
56
|
+
email:
|
57
|
+
- 202070317@163.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- ali_dayu.gemspec
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/ali_dayu.rb
|
72
|
+
- lib/ali_dayu/base.rb
|
73
|
+
- lib/ali_dayu/sms.rb
|
74
|
+
- lib/ali_dayu/version.rb
|
75
|
+
- lib/ali_dayu/voice.rb
|
76
|
+
homepage: https://github.com/WindStill/ali_dayu
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata:
|
80
|
+
allowed_push_host: https://rubygems.org
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.8
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: ali dayu
|
101
|
+
test_files: []
|