alidayu_sms 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +18 -0
- data/Gemfile.lock +5 -2
- data/README.md +24 -20
- data/alidayu_sms.gemspec +3 -3
- data/bin/alidayu_sms +2 -2
- data/lib/alidayu_sms.rb +5 -2
- data/lib/alidayu_sms/alidayu.rb +5 -1
- data/lib/alidayu_sms/version.rb +1 -1
- data/lib/tasks/alidayu_sms.rake +1 -1
- data/pkg/alidayu_sms-0.3.0.gem +0 -0
- data/pkg/alidayu_sms-0.3.1.gem +0 -0
- metadata +12 -22
- data/.idea/alidayu_sms.iml +0 -27
- data/README.md~ +0 -6
- data/Rakefile~ +0 -12
- data/alidayu_sms.gemspec~ +0 -27
- data/bin/alidayu_sms~ +0 -68
- data/lib/alidayu_sms.rb~ +0 -55
- data/lib/alidayu_sms/alidayu.rb~ +0 -67
- data/lib/alidayu_sms/version.rb~ +0 -3
- data/lib/sms.rb~ +0 -60
- data/lib/tasks/alidayu_sms.rake~ +0 -7
- data/lib/templates/sms.yml~ +0 -18
- data/sms.gemspec~ +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e4e64b32dd376d7582bb610c7cb0dd991be870c
|
4
|
+
data.tar.gz: 8119a7ea51e98851b93558a2ae3e722c6db432cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c843c1c4ccbae5b7da8d179a819123d2db032f05d71efaad7a1b660317f29ce218d5604574c2833121cf81d0dcdf7ff4f0e5c8b644684a271d591f940fc40c44
|
7
|
+
data.tar.gz: 040ff6361c3e9bc7f05cae8976d441dfdf8f8cf204ee3b1a2afa90ccf9ddc62378cd064a5f919cd95f0683821e010ce3b70cf2cec1d6b2f782c8ada362685a9a
|
data/.gitignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
/.bundle
|
2
|
+
|
3
|
+
# Ignore the default SQLite database.
|
4
|
+
/db/*.sqlite3
|
5
|
+
/db/*.sqlite3-journal
|
6
|
+
|
7
|
+
# Ignore all logfiles and tempfiles.
|
8
|
+
/log/*
|
9
|
+
!/log/.keep
|
10
|
+
/tmp
|
11
|
+
/.idea
|
12
|
+
/config/*.yml
|
13
|
+
/test
|
14
|
+
/public/api_chekoubei_doc/
|
15
|
+
/public/Attachments/*
|
16
|
+
public/system/*
|
17
|
+
*~
|
18
|
+
public/vc/*
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
alidayu_sms (0.
|
4
|
+
alidayu_sms (0.3.1)
|
5
5
|
i18n
|
6
6
|
|
7
7
|
GEM
|
@@ -26,8 +26,11 @@ PLATFORMS
|
|
26
26
|
ruby
|
27
27
|
|
28
28
|
DEPENDENCIES
|
29
|
-
activesupport (~> 4.1
|
29
|
+
activesupport (~> 4.1)
|
30
30
|
alidayu_sms!
|
31
31
|
bundler (~> 1.9)
|
32
32
|
rack
|
33
33
|
rake (~> 10.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
1.11.2
|
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
# alidayu_sms
|
2
2
|
阿里大鱼的短信发送api,暂时只支持 alibaba.aliqin.fc.sms.num.send 短信发送
|
3
3
|
|
4
|
-
# Gemfile
|
4
|
+
# Gemfile
|
5
|
+
```ruby
|
5
6
|
gem 'alidayu_sms'
|
7
|
+
```
|
6
8
|
|
7
9
|
# start
|
8
|
-
|
9
|
-
|
10
|
+
##生成配置文件 config/alidayu_sms.yml
|
11
|
+
|
12
|
+
`rake alidayu_sms:create_default_config_file`
|
13
|
+
|
10
14
|
```ruby
|
11
15
|
defaults: &defaults
|
12
16
|
alidayu:
|
@@ -28,11 +32,24 @@ test:
|
|
28
32
|
production:
|
29
33
|
<<: *defaults
|
30
34
|
```
|
31
|
-
|
35
|
+
|
36
|
+
# 用法
|
37
|
+
## 登录短信示例
|
38
|
+
- 配置文件config/alidayu_sms.yml里的product即为 sms_param = sms_param[:product] = "阿里云", 则可不传这个字段
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# Alidayu::Sms.send_code_for_{name}( phone, sms_param={code: '1314520', product: '可选'}, extend="") {name}为配置文件sms_templates[:name]
|
42
|
+
|
43
|
+
Alidayu::Sms.send_code_for_sign_up("15921076830", {code: '1314520'}, '')
|
44
|
+
```
|
45
|
+
|
46
|
+
# 自定义模板
|
47
|
+
|
32
48
|
```ruby
|
49
|
+
|
33
50
|
options = {
|
34
|
-
sms_param: "'code':
|
35
|
-
phones: '
|
51
|
+
sms_param: "{'code':'1314520','product':'阿里云'}",
|
52
|
+
phones: '152012211, 15921076830',
|
36
53
|
extend: '', # 公共回传参数,在“消息返回”中会透传回该参数;举例:用户可以传入自己下级的会员ID,在消息返回时,该会员ID会包含在内,用户可以根据该会员ID识别是哪位会员使用了你的应用
|
37
54
|
sms_free_sign_name: "注册验证", # 短信签名
|
38
55
|
sms_template_code: "SMS_5045503" # 短信模板
|
@@ -40,17 +57,4 @@ options = {
|
|
40
57
|
result = AlidayuSmsSender.new.batchSendSms(options)
|
41
58
|
|
42
59
|
# 返回码参考 阿里大鱼 api文档
|
43
|
-
```
|
44
|
-
# v0.3.0最新用法
|
45
|
-
## 配置文件里的product即为 sms_param = sms_param[:product] = "阿里云", 则可不传这个字段
|
46
|
-
```ruby
|
47
|
-
# Alidayu::Sms.send_code_for_{name}( phone, sms_param={code: '1314520', product: '可选'}, extend="") {name}为配置文件sms_templates[:name]
|
48
|
-
Alidayu::Sms.send_code_for_sign_up("15921076830", {code: '1314520'}, '')
|
49
|
-
```
|
50
|
-
|
51
|
-
# v0.2.0用法
|
52
|
-
## 配置文件里的product即为 options里的 product: "阿里云", 模板的{product}字段,配置好之后可以用如下方法
|
53
|
-
```ruby
|
54
|
-
# Alidayu::Sms.send_code_for_{name}(code, phone, extend="") {name}为配置文件sms_templates[:name]
|
55
|
-
Alidayu::Sms.send_code_for_sign_up(1314520, "1520122011")
|
56
|
-
```
|
60
|
+
```
|
data/alidayu_sms.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency 'i18n'
|
21
|
+
spec.add_dependency 'i18n', '~> 0'
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.9"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "activesupport", "~> 4.1
|
25
|
-
spec.add_development_dependency 'rack'
|
24
|
+
spec.add_development_dependency "activesupport", "~> 4.1"
|
25
|
+
spec.add_development_dependency 'rack', '~> 0'
|
26
26
|
end
|
data/bin/alidayu_sms
CHANGED
@@ -42,12 +42,12 @@ EOF
|
|
42
42
|
attributes = Rack::Utils.parse_nested_query(x)
|
43
43
|
end
|
44
44
|
|
45
|
-
o.on("-h", "--help", "
|
45
|
+
o.on("-h", "--help", "帮助") do |x|
|
46
46
|
puts o
|
47
47
|
exit
|
48
48
|
end
|
49
49
|
|
50
|
-
o.on("-v", "--version", "
|
50
|
+
o.on("-v", "--version", "版本号") do |x|
|
51
51
|
puts "Version: #{AlidayuSms::VERSION}"
|
52
52
|
exit
|
53
53
|
end
|
data/lib/alidayu_sms.rb
CHANGED
@@ -25,7 +25,10 @@ class AlidayuSmsSender
|
|
25
25
|
options = HashWithIndifferentAccess.new(options)
|
26
26
|
check_system_params(options)
|
27
27
|
|
28
|
-
|
28
|
+
# 基础类实例
|
29
|
+
self.source = AlidayuSms::Alidayu.new(options)
|
30
|
+
|
31
|
+
# 动态方法
|
29
32
|
class_eval do
|
30
33
|
load_config[:alidayu][:sms_templates].each do |sms_template|
|
31
34
|
define_method("send_code_for_#{sms_template[:name]}") do |phone, _sms_param = {}, extend = ""|
|
@@ -57,7 +60,7 @@ class AlidayuSmsSender
|
|
57
60
|
check_params(flag, options)
|
58
61
|
puts "阿里大鱼传入参数为:#{attr}"
|
59
62
|
|
60
|
-
|
63
|
+
source.standard_send_msg(attr)
|
61
64
|
end
|
62
65
|
|
63
66
|
private
|
data/lib/alidayu_sms/alidayu.rb
CHANGED
@@ -43,9 +43,13 @@ module AlidayuSms
|
|
43
43
|
|
44
44
|
private
|
45
45
|
def sort_options(**arg)
|
46
|
-
arg.sort_by{|k,v| k}.to_h
|
46
|
+
# arg.sort_by{|k,v| k}.to_h
|
47
|
+
hash = Hash.new
|
48
|
+
arg.sort.map{|e| hash[e[0]] = e[1] }
|
49
|
+
hash
|
47
50
|
end
|
48
51
|
|
52
|
+
# 中文方法 ~
|
49
53
|
def 加密(**arg)
|
50
54
|
_arg = arg.map{|k,v| "#{k}#{v}"}
|
51
55
|
md5("#{self.app_secret}#{_arg.join("")}#{self.app_secret}").upcase
|
data/lib/alidayu_sms/version.rb
CHANGED
data/lib/tasks/alidayu_sms.rake
CHANGED
@@ -6,6 +6,6 @@ namespace :alidayu_sms do
|
|
6
6
|
unless File.exist?("#{::Rails.root}/config/initializers/alidayu.rb")
|
7
7
|
FileUtils.cp(File.expand_path("../../templates/alidayu.rb", __FILE__), "#{::Rails.root}/config/initializers/alidayu.rb")
|
8
8
|
end
|
9
|
-
puts '
|
9
|
+
puts '阿里大鱼初始化成功'
|
10
10
|
end
|
11
11
|
end
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alidayu_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jack ping
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -58,26 +58,26 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 4.1
|
61
|
+
version: '4.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 4.1
|
68
|
+
version: '4.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: alidayu_sms send.
|
@@ -85,12 +85,11 @@ email:
|
|
85
85
|
- 525399584@qq.com
|
86
86
|
executables:
|
87
87
|
- alidayu_sms
|
88
|
-
- alidayu_sms~
|
89
88
|
extensions: []
|
90
89
|
extra_rdoc_files: []
|
91
90
|
files:
|
91
|
+
- ".gitignore"
|
92
92
|
- ".idea/.rakeTasks"
|
93
|
-
- ".idea/alidayu_sms.iml"
|
94
93
|
- ".idea/misc.xml"
|
95
94
|
- ".idea/modules.xml"
|
96
95
|
- ".idea/vcs.xml"
|
@@ -98,28 +97,19 @@ files:
|
|
98
97
|
- Gemfile
|
99
98
|
- Gemfile.lock
|
100
99
|
- README.md
|
101
|
-
- README.md~
|
102
100
|
- Rakefile
|
103
|
-
- Rakefile~
|
104
101
|
- alidayu_sms.gemspec
|
105
|
-
- alidayu_sms.gemspec~
|
106
102
|
- bin/alidayu_sms
|
107
|
-
- bin/alidayu_sms~
|
108
103
|
- lib/alidayu_sms.rb
|
109
|
-
- lib/alidayu_sms.rb~
|
110
104
|
- lib/alidayu_sms/alidayu.rb
|
111
|
-
- lib/alidayu_sms/alidayu.rb~
|
112
105
|
- lib/alidayu_sms/version.rb
|
113
|
-
- lib/alidayu_sms/version.rb~
|
114
|
-
- lib/sms.rb~
|
115
106
|
- lib/tasks/alidayu_sms.rake
|
116
|
-
- lib/tasks/alidayu_sms.rake~
|
117
107
|
- lib/templates/alidayu.rb
|
118
108
|
- lib/templates/alidayu_sms.yml
|
119
|
-
- lib/templates/sms.yml~
|
120
109
|
- pkg/alidayu_sms-0.1.0.gem
|
121
110
|
- pkg/alidayu_sms-0.2.0.gem
|
122
|
-
-
|
111
|
+
- pkg/alidayu_sms-0.3.0.gem
|
112
|
+
- pkg/alidayu_sms-0.3.1.gem
|
123
113
|
homepage: https://github.com/wangping0105/alidayu_sms
|
124
114
|
licenses: []
|
125
115
|
metadata: {}
|
@@ -139,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
129
|
version: '0'
|
140
130
|
requirements: []
|
141
131
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.5.1
|
143
133
|
signing_key:
|
144
134
|
specification_version: 4
|
145
135
|
summary: alidayu_sms send.
|
data/.idea/alidayu_sms.iml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="RUBY_MODULE" version="4">
|
3
|
-
<component name="FacetManager">
|
4
|
-
<facet type="gem" name="Ruby Gem">
|
5
|
-
<configuration>
|
6
|
-
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
-
<option name="GEM_APP_TEST_PATH" value="$MODULE_DIR$/test" />
|
8
|
-
<option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
|
9
|
-
</configuration>
|
10
|
-
</facet>
|
11
|
-
</component>
|
12
|
-
<component name="NewModuleRootManager">
|
13
|
-
<content url="file://$MODULE_DIR$">
|
14
|
-
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
15
|
-
</content>
|
16
|
-
<orderEntry type="inheritedJdk" />
|
17
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
18
|
-
<orderEntry type="library" scope="PROVIDED" name="activesupport (v4.1.14.1, RVM: ruby-2.1.5) [gem]" level="application" />
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.7.0, RVM: ruby-2.1.5) [gem]" level="application" />
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="json (v1.8.3, RVM: ruby-2.1.5) [gem]" level="application" />
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.8.4, RVM: ruby-2.1.5) [gem]" level="application" />
|
22
|
-
<orderEntry type="library" scope="PROVIDED" name="rack (v1.6.4, RVM: ruby-2.1.5) [gem]" level="application" />
|
23
|
-
<orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, RVM: ruby-2.1.5) [gem]" level="application" />
|
24
|
-
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.5, RVM: ruby-2.1.5) [gem]" level="application" />
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.2, RVM: ruby-2.1.5) [gem]" level="application" />
|
26
|
-
</component>
|
27
|
-
</module>
|
data/README.md~
DELETED
data/Rakefile~
DELETED
data/alidayu_sms.gemspec~
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'alidayu_sms/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "alidayu_sms"
|
8
|
-
spec.version = AlidayuSms::VERSION
|
9
|
-
spec.authors = ["jack ping"]
|
10
|
-
spec.email = ["525399584@qq.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{alidayu_sms send.}
|
13
|
-
spec.description = %q{alidayu_sms send.}
|
14
|
-
spec.homepage = "https://github.com/wangping0105/alidayu_sms"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir = "bin"
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency 'i18n'
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.9"
|
24
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
spec.add_development_dependency "activesupport", "~> 4.1.12"
|
26
|
-
spec.add_development_dependency 'rack'
|
27
|
-
end
|
data/bin/alidayu_sms~
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "optparse"
|
4
|
-
require "pp"
|
5
|
-
require 'rack'
|
6
|
-
|
7
|
-
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
8
|
-
require 'alidayu_sms'
|
9
|
-
|
10
|
-
options = {source: 'zucp', method: 'single'}
|
11
|
-
attributes = {}
|
12
|
-
|
13
|
-
OptionParser.new do |o|
|
14
|
-
o.banner = <<-EOF
|
15
|
-
Usage:
|
16
|
-
Starting:
|
17
|
-
alidayu_sms [-p <phone>] [-c <content>] [-m <model>] [-t <type>]
|
18
|
-
|
19
|
-
Querying:
|
20
|
-
alidayu_sms -v
|
21
|
-
|
22
|
-
Options:
|
23
|
-
EOF
|
24
|
-
|
25
|
-
o.on("-p", "--phone=phone", String, "send alidayu_sms phone") do |x|
|
26
|
-
options[:phone] = x
|
27
|
-
end
|
28
|
-
|
29
|
-
o.on("-c", "--content=content", String, "send alidayu_sms content") do |x|
|
30
|
-
options[:content] = x
|
31
|
-
end
|
32
|
-
|
33
|
-
o.on("-s", "--source=source", String, "send alidayu_sms source [zucp|taobao] (Default: zucp)") do |x|
|
34
|
-
options[:source] = x
|
35
|
-
end
|
36
|
-
|
37
|
-
o.on("-m", "--m=method", String, "send alidayu_sms method [single|batch] (Default: single)") do |x|
|
38
|
-
options[:method] = x
|
39
|
-
end
|
40
|
-
|
41
|
-
o.on("-a", "--a=attributes", String, "attributes: ()") do |x|
|
42
|
-
attributes = Rack::Utils.parse_nested_query(x)
|
43
|
-
end
|
44
|
-
|
45
|
-
o.on("-h", "--help", "Show help documentation") do |x|
|
46
|
-
puts o
|
47
|
-
exit
|
48
|
-
end
|
49
|
-
|
50
|
-
o.on("-v", "--version", "Show alidayu_sms version") do |x|
|
51
|
-
puts "Version: #{AlidayuSms::VERSION}"
|
52
|
-
exit
|
53
|
-
end
|
54
|
-
end.parse!
|
55
|
-
|
56
|
-
options.merge!(attributes)
|
57
|
-
|
58
|
-
begin
|
59
|
-
puts options.inspect
|
60
|
-
puts AlidayuSmsSender.new(options).send("#{options[:method]}Send", options[:phone])
|
61
|
-
rescue => e
|
62
|
-
puts 'Uncaught exception'
|
63
|
-
puts e.message
|
64
|
-
puts e.backtrace.join("\n")
|
65
|
-
end
|
66
|
-
|
67
|
-
# sms -p 13262902619 -s taobao -a 'app_secret=5aff003ac3c7243da65adef1e7c9c363&app_key=23272925&sms_free_sign_name=爱客验证码&sms_template_code=SMS_2575137&sms_param[code]=xxx&sms_param[product]=ddd'
|
68
|
-
|
data/lib/alidayu_sms.rb~
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
require "active_support/all"
|
5
|
-
|
6
|
-
require "alidayu_sms/version"
|
7
|
-
require "alidayu_sms/alidayu"
|
8
|
-
|
9
|
-
require 'yaml' unless defined? YMAL
|
10
|
-
|
11
|
-
def load_config
|
12
|
-
if defined? ::Rails
|
13
|
-
@sms_config ||= HashWithIndifferentAccess.new(YAML.load_file("#{::Rails.root}/config/alidayu_sms.yml")[::Rails.env] || {})
|
14
|
-
else
|
15
|
-
{}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class AlidayuSmsSender
|
20
|
-
attr_accessor :source, :template_code
|
21
|
-
|
22
|
-
def initialize(options = {})
|
23
|
-
if load_config.present? && load_config[:alidayu].present?
|
24
|
-
options = load_config[:alidayu].merge(options)
|
25
|
-
end
|
26
|
-
|
27
|
-
options = HashWithIndifferentAccess.new(options)
|
28
|
-
@source = AlidayuSms::Alidayu.new(options)
|
29
|
-
end
|
30
|
-
|
31
|
-
# 发送短信
|
32
|
-
def batchSendSms(options = {})
|
33
|
-
arr = %w(code product phones extend sms_free_sign_name sms_template_code)
|
34
|
-
arr.each do |a|
|
35
|
-
unless options[a.to_sym]
|
36
|
-
puts "参数不全!"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
@source.standard_send_msg(arr.map{|a| options[a.to_sym]})
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
if defined? ::Rails
|
46
|
-
module AlidayuSms
|
47
|
-
module Rails
|
48
|
-
class Railtie < ::Rails::Railtie
|
49
|
-
rake_tasks do
|
50
|
-
load "tasks/alidayu_sms.rake"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/lib/alidayu_sms/alidayu.rb~
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
|
3
|
-
module Sms
|
4
|
-
class Alidayu
|
5
|
-
attr_accessor :app_key, :app_secret, :post_url
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
app_key = options[:app_key]
|
9
|
-
app_secret = options[:app_secret]
|
10
|
-
post_url = options[:post_url]
|
11
|
-
end
|
12
|
-
|
13
|
-
def standard_send_msg(code, product, _phones, _extend, _sms_free_sign_name, _sms_template_code)
|
14
|
-
_sms_param = "{'code':'#{code}','product':'#{product}'}"
|
15
|
-
|
16
|
-
_timestamp = Time.now.strftime("%F %T")
|
17
|
-
options = {
|
18
|
-
app_key: self.app_key,
|
19
|
-
format: 'json',
|
20
|
-
method: 'alibaba.aliqin.fc.sms.num.send',
|
21
|
-
partner_id: 'apidoc',
|
22
|
-
sign_method: 'md5',
|
23
|
-
timestamp: _timestamp,
|
24
|
-
v: '2.0',
|
25
|
-
extend: _extend,
|
26
|
-
rec_num: _phones,
|
27
|
-
sms_free_sign_name: _sms_free_sign_name,
|
28
|
-
sms_param: _sms_param,
|
29
|
-
sms_template_code: _sms_template_code,
|
30
|
-
sms_type: 'normal'
|
31
|
-
}
|
32
|
-
options = sort_options(options)
|
33
|
-
|
34
|
-
md5_str = 加密(options)
|
35
|
-
response = post(self.post_url, options.merge(sign: md5_str))
|
36
|
-
puts "phones: #{_phones}, #{_sms_param}, and respone: #{response}"
|
37
|
-
response
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def sort_options(**arg)
|
42
|
-
arg.sort_by{|k,v| k}.to_h
|
43
|
-
end
|
44
|
-
|
45
|
-
def 加密(**arg)
|
46
|
-
_arg = arg.map{|k,v| "#{k}#{v}"}
|
47
|
-
md5("#{self.app_secret}#{_arg.join("")}#{self.app_secret}").upcase
|
48
|
-
end
|
49
|
-
|
50
|
-
def md5(arg)
|
51
|
-
Digest::MD5.hexdigest(arg)
|
52
|
-
end
|
53
|
-
|
54
|
-
def post(uri, options)
|
55
|
-
response = ""
|
56
|
-
url = URI.parse(uri)
|
57
|
-
Net::HTTP.start(url.host, url.port) do |http|
|
58
|
-
req = Net::HTTP::Post.new(url.path)
|
59
|
-
req.set_form_data(options)
|
60
|
-
response = http.request(req).body
|
61
|
-
end
|
62
|
-
JSON(response)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
|
data/lib/alidayu_sms/version.rb~
DELETED
data/lib/sms.rb~
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
require "active_support/all"
|
5
|
-
|
6
|
-
require "sms/version"
|
7
|
-
require "sms/alidayu"
|
8
|
-
|
9
|
-
require 'yaml' unless defined? YMAL
|
10
|
-
|
11
|
-
def load_config
|
12
|
-
if defined? ::Rails
|
13
|
-
@sms_config ||= HashWithIndifferentAccess.new(YAML.load_file("#{::Rails.root}/config/sms.yml")[::Rails.env] || {})
|
14
|
-
else
|
15
|
-
{}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class AlidayuSmsSender
|
20
|
-
|
21
|
-
SOURCES = %w(alidayu)
|
22
|
-
|
23
|
-
attr_accessor :source, :template_code
|
24
|
-
|
25
|
-
def initialize(options = {})
|
26
|
-
return unless options[:source].in?(SOURCES)
|
27
|
-
|
28
|
-
if load_config.present? && load_config[:alidayu].present?
|
29
|
-
options = load_config[:alidayu].merge(options)
|
30
|
-
end
|
31
|
-
|
32
|
-
options = HashWithIndifferentAccess.new(options)
|
33
|
-
@source = Sms::Alidayu.new(options)
|
34
|
-
end
|
35
|
-
|
36
|
-
# 发送短信
|
37
|
-
def batchSendSms(options = {})
|
38
|
-
arr = %w(code product phones extend sms_free_sign_name sms_template_code)
|
39
|
-
arr.each do |a|
|
40
|
-
unless options[a.to_sym]
|
41
|
-
puts "参数不全!"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
standard_send_msg(arr.map{|a| options[a.to_sym]})
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
if defined? ::Rails
|
51
|
-
module Sms
|
52
|
-
module Rails
|
53
|
-
class Railtie < ::Rails::Railtie
|
54
|
-
rake_tasks do
|
55
|
-
load "tasks/sms.rake"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/tasks/alidayu_sms.rake~
DELETED
data/lib/templates/sms.yml~
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
defaults: &defaults
|
2
|
-
alidayu:
|
3
|
-
app_key: xxxx
|
4
|
-
app_secret: xxxx
|
5
|
-
post_url: 'http://gw.api.taobao.com/router/rest'
|
6
|
-
templates:
|
7
|
-
devise_supplier_applies_otp_code_confirm: "验证码:%{code},有效期5分钟~ 如非本人操作,请忽略本短信"
|
8
|
-
devise_passwords_otp_code_confirm: "验证码:%{code},有效期5分钟~ 如非本人操作,请忽略本短信"
|
9
|
-
devise_confirmations_otp_code_confirm: "验证码:%{code},有效期5分钟,请尽快完成注册哦~ 如非本人操作,请忽略本短信"
|
10
|
-
|
11
|
-
development:
|
12
|
-
<<: *defaults
|
13
|
-
|
14
|
-
test:
|
15
|
-
<<: *defaults
|
16
|
-
|
17
|
-
production:
|
18
|
-
<<: *defaults
|
data/sms.gemspec~
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'sms/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "alidayu_sms"
|
8
|
-
spec.version = Sms::VERSION
|
9
|
-
spec.authors = ["jack ping"]
|
10
|
-
spec.email = ["525399584@qq.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{sms send.}
|
13
|
-
spec.description = %q{sms send.}
|
14
|
-
spec.homepage = "https://github.com/wangping0105/alidayu_sms"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir = "bin"
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency 'i18n'
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.9"
|
24
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
spec.add_development_dependency "activesupport", "~> 4.1.12"
|
26
|
-
spec.add_development_dependency 'rack'
|
27
|
-
end
|