geetest3 0.0.1a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/images/favicon.ico +0 -0
- data/example/sinatra.rb +49 -0
- data/example/views/_header.html.erb +44 -0
- data/example/views/embed.html.erb +60 -0
- data/example/views/layout.html.erb +27 -0
- data/example/views/popup.html.erb +68 -0
- data/geetest3.gemspec +36 -0
- data/lib/geetest.rb +6 -0
- data/lib/geetest/sdk3.rb +147 -0
- data/lib/geetest/version.rb +4 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e1e7be5381fd6d7b63e8fc33e52a57b42c27a9b
|
4
|
+
data.tar.gz: 66c71edbf3257b17f87d079972a6ed759c5b9119
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c4d17c2b1d1c4780ac928ea39f9b4deaeb0ba2dab9c2f7099813692e87744cb7086e77da14834e10fca3611fe04b2292ef4bfd751ab7885a05fcad0c6816775
|
7
|
+
data.tar.gz: e33ca5286183144f2d3caf3068bef8310aff277c5ef593812d8730edd5ee790c050fcaa1819bb47326a39fc265730750385ffef07afded562644cc1ed5a8bb7a
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 jay_li@intfocus.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
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
geetest3 (0.0.1a)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.5.0)
|
12
|
+
rspec-core (~> 3.5.0)
|
13
|
+
rspec-expectations (~> 3.5.0)
|
14
|
+
rspec-mocks (~> 3.5.0)
|
15
|
+
rspec-core (3.5.4)
|
16
|
+
rspec-support (~> 3.5.0)
|
17
|
+
rspec-expectations (3.5.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.5.0)
|
20
|
+
rspec-mocks (3.5.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.5.0)
|
23
|
+
rspec-support (3.5.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.13)
|
30
|
+
geetest3!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.13.5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 俊杰.li
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 jay16
|
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,52 @@
|
|
1
|
+
# Gt Ruby SDK3
|
2
|
+
|
3
|
+
ruby gem [geetest(0.1.6)](https://rubygems.org/gems/geetest) already deprecated.
|
4
|
+
|
5
|
+
[Geetest SDK3](http://www.geetest.com/install/sections/idx-server-sdk.html#python) logic copy from [gt-python-sdk](https://github.com/GeeTeam/gt-python-sdk)
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'geetest3'
|
11
|
+
```
|
12
|
+
|
13
|
+
```
|
14
|
+
require 'gestest'
|
15
|
+
|
16
|
+
# register when page load done
|
17
|
+
get '/popup/register' do
|
18
|
+
user_id = nil # set here if can get user_id
|
19
|
+
gt = Geetest::SDK3.new(captcha_id, private_key)
|
20
|
+
status = gt.pre_process(user_id)
|
21
|
+
session[gt.session_key] = status
|
22
|
+
session['token'] = user_id || params[:avoid_cache_token]
|
23
|
+
gt.response_str
|
24
|
+
end
|
25
|
+
|
26
|
+
# validate geetest before submit
|
27
|
+
post '/:type/validate' do
|
28
|
+
gt = Geetest::SDK3.new(captcha_id, private_key)
|
29
|
+
challenge = params[gt.fn_challenge]
|
30
|
+
validate = params[gt.fn_validate]
|
31
|
+
seccode = params[gt.fn_seccode]
|
32
|
+
|
33
|
+
if session[gt.session_key]
|
34
|
+
result = gt.success_validate(challenge, validate, seccode, session['token'])
|
35
|
+
else
|
36
|
+
result = gt.failback_validate(challenge, validate, seccode)
|
37
|
+
end
|
38
|
+
|
39
|
+
{ status: (result ? 'login successfully' : 'login falied') }.to_json
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
## Example
|
44
|
+
|
45
|
+
```
|
46
|
+
$ git clone git@github.com:jay16/gt-ruby-sdk3.git
|
47
|
+
$ cd gt-ruby-sdk3/example
|
48
|
+
$ gem install sinatra
|
49
|
+
$ ruby sinatra.rb
|
50
|
+
```
|
51
|
+
|
52
|
+
browser visit localhost:4567 view demo.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "geetest3"
|
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
Binary file
|
data/example/sinatra.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH.push(File.expand_path('../../lib', __FILE__))
|
3
|
+
require 'sinatra'
|
4
|
+
require 'geetest'
|
5
|
+
|
6
|
+
enable :sessions
|
7
|
+
|
8
|
+
captcha_id = 'd764fd5f1d8dc1be32eee54e75789384'
|
9
|
+
private_key = '667ffc1532e5925d1c3619f1f1adf8e7'
|
10
|
+
|
11
|
+
get '/' do
|
12
|
+
redirect to('/embed')
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/embed' do
|
16
|
+
erb :'embed.html', layout: :'layout.html'
|
17
|
+
end
|
18
|
+
|
19
|
+
get '/popup' do
|
20
|
+
erb :'popup.html', layout: :'layout.html'
|
21
|
+
end
|
22
|
+
|
23
|
+
get '/images/:filename' do
|
24
|
+
send_file %(images/#{params[:filename]})
|
25
|
+
end
|
26
|
+
|
27
|
+
get '/:type/register' do
|
28
|
+
user_id = nil # set here if can get user_id
|
29
|
+
gt = Geetest::SDK3.new(captcha_id, private_key)
|
30
|
+
status = gt.pre_process(user_id)
|
31
|
+
session[gt.session_key] = status
|
32
|
+
session['token'] = user_id || params[:avoid_cache_token]
|
33
|
+
gt.response_str
|
34
|
+
end
|
35
|
+
|
36
|
+
post '/:type/validate' do
|
37
|
+
gt = Geetest::SDK3.new(captcha_id, private_key)
|
38
|
+
challenge = params[gt.fn_challenge]
|
39
|
+
validate = params[gt.fn_validate]
|
40
|
+
seccode = params[gt.fn_seccode]
|
41
|
+
|
42
|
+
if session[gt.session_key]
|
43
|
+
result = gt.success_validate(challenge, validate, seccode, session['token'])
|
44
|
+
else
|
45
|
+
result = gt.failback_validate(challenge, validate, seccode)
|
46
|
+
end
|
47
|
+
|
48
|
+
{ status: (result ? 'login successfully' : 'login falied') }.to_json
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<nav class='navbar navbar-default' style='margin-bottom:0px;'>
|
2
|
+
<div class='container'>
|
3
|
+
<!-- Brand and toggle get grouped for better mobile display -->
|
4
|
+
<div class='navbar-header'>
|
5
|
+
<button aria-expanded='false' class='navbar-toggle collapsed' data-target='#navbar-collapse' data-toggle='collapse' type='button'>
|
6
|
+
<span class='sr-only'>Toggle navigation</span>
|
7
|
+
<span class='icon-bar'></span>
|
8
|
+
<span class='icon-bar'></span>
|
9
|
+
<span class='icon-bar'></span>
|
10
|
+
</button>
|
11
|
+
<a class='navbar-brand'>Geetest3</a>
|
12
|
+
</div>
|
13
|
+
<div class='collapse navbar-collapse' id='navbar-collapse' role='navigation'>
|
14
|
+
<ul class='nav navbar-nav'>
|
15
|
+
<li class='popup'>
|
16
|
+
<a href='/embed'> Embed </a>
|
17
|
+
</li>
|
18
|
+
<li class='embed'>
|
19
|
+
<a href='/popup'> Popup </a>
|
20
|
+
</li>
|
21
|
+
</ul>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</nav>
|
25
|
+
<script type='text/javascript'>
|
26
|
+
function initBootstrapNavbarLi() {
|
27
|
+
var is_match, navbar_lis, navbar_right_lis, path_name;
|
28
|
+
path_name = window.location.pathname;
|
29
|
+
navbar_right_lis = $('#navbar_right_lis').val() || 1;
|
30
|
+
navbar_lis = $('.navbar-nav:first li, .navbar-right li:lt(' + navbar_right_lis + ')');
|
31
|
+
is_match = false;
|
32
|
+
return navbar_lis.each(function() {
|
33
|
+
var href;
|
34
|
+
href = $(this).children('a:first').attr('href');
|
35
|
+
if (path_name === href || path_name === (href + '/')) {
|
36
|
+
$(this).addClass('active');
|
37
|
+
return is_match = true;
|
38
|
+
} else {
|
39
|
+
return $(this).removeClass('active');
|
40
|
+
}
|
41
|
+
});
|
42
|
+
}
|
43
|
+
initBootstrapNavbarLi();
|
44
|
+
</script>
|
@@ -0,0 +1,60 @@
|
|
1
|
+
<div class='row' style='margin-top:5%;'>
|
2
|
+
<div class='col-lg-4 col-lg-offset-4 col-md-4 col-md-4 col-sm-8 col-sm-offset-2 col-xs-12'>
|
3
|
+
<form class='popup' action='/embed/validate' method='post'>
|
4
|
+
<div class='form-group'>
|
5
|
+
<label for='username'>username:</label>
|
6
|
+
<input class='form-control' id='username' type='text' value='geetest3'>
|
7
|
+
</div>
|
8
|
+
<div class='form-group'>
|
9
|
+
<label for='password'>password:</label>
|
10
|
+
<input class='form-control' id='password' type='password' value='ruby'>
|
11
|
+
</div>
|
12
|
+
<div class='form-group'>
|
13
|
+
<div id='embed-captcha'></div>
|
14
|
+
<p id='wait' class='text-primary' style='text-align: center;'>正在加载验证码......</p>
|
15
|
+
<p id='notice' class='hidden' style='text-align: center;'>请先拖动验证码到相应位置</p>
|
16
|
+
</div>
|
17
|
+
<input class='btn btn-default' value='Submit' type='submit'>
|
18
|
+
</form>
|
19
|
+
<div id='popup-captcha' style='text-align: center;'></div>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<script type='text/javascript'>
|
24
|
+
var handlerEmbed = function (captchaObj) {
|
25
|
+
$('input[type=submit]').click(function (e) {
|
26
|
+
var validate = captchaObj.getValidate();
|
27
|
+
if (!validate) {
|
28
|
+
$('#notice')[0].className = 'text-primary';
|
29
|
+
setTimeout(function () {
|
30
|
+
$('#notice')[0].className = 'hidden';
|
31
|
+
}, 2000);
|
32
|
+
e.preventDefault();
|
33
|
+
}
|
34
|
+
});
|
35
|
+
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
|
36
|
+
captchaObj.appendTo('#embed-captcha');
|
37
|
+
captchaObj.onReady(function () {
|
38
|
+
$('#wait')[0].className = 'hidden';
|
39
|
+
});
|
40
|
+
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
|
41
|
+
};
|
42
|
+
$.ajax({
|
43
|
+
// 获取id,challenge,success(是否启用failback)
|
44
|
+
url: '/embed/register?avoid_cache_token=' + (new Date()).getTime(), // 加随机数防止缓存
|
45
|
+
type: 'get',
|
46
|
+
dataType: 'json',
|
47
|
+
success: function (data) {
|
48
|
+
// 使用initGeetest接口
|
49
|
+
// 参数1:配置参数
|
50
|
+
// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
|
51
|
+
initGeetest({
|
52
|
+
gt: data.gt,
|
53
|
+
challenge: data.challenge,
|
54
|
+
product: 'embed', // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
|
55
|
+
offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
|
56
|
+
// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
|
57
|
+
}, handlerEmbed);
|
58
|
+
}
|
59
|
+
});
|
60
|
+
</script>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset='UTF-8' />
|
5
|
+
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
6
|
+
<title>极验验证码 - SDK3 Ruby Demo</title>
|
7
|
+
<link href='http://www.geetest.com/images/bitbug_favicon.ico' rel='shortcut icon' />
|
8
|
+
<link rel='stylesheet' href='http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css' />
|
9
|
+
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
|
10
|
+
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
|
11
|
+
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
|
12
|
+
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
|
13
|
+
<!-- 引入封装了failback的接口--initGeetest -->
|
14
|
+
<script src='http://static.geetest.com/static/tools/gt.js'></script>
|
15
|
+
<!-- 若是https,使用以下接口 -->
|
16
|
+
<!-- <script src='https://code.jquery.com/jquery-1.12.3.min.js'></script> -->
|
17
|
+
<!-- <script src='https://static.geetest.com/static/tools/gt.js'></script> -->
|
18
|
+
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<%= erb :'_header.html' %>
|
22
|
+
|
23
|
+
<div class='container'>
|
24
|
+
<%= yield %>
|
25
|
+
</div>
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<div class='row form' style='margin-top:10%;'>
|
2
|
+
<div class='col-md-offset-4 col-md-4 col-sm-8 col-sm-offset-2 col-xs-12'>
|
3
|
+
<div class='form-group'>
|
4
|
+
<label for='username'>username:</label>
|
5
|
+
<input class='form-control' id='user_user_num' name='user[user_num]' type='text' value='geetest3'></div>
|
6
|
+
<div class='form-group'>
|
7
|
+
<label for='password'>password:</label>
|
8
|
+
<input class='form-control' id='user_user_pass' name='user[user_pass]' type='password' value='ruby'></div>
|
9
|
+
<input class='btn btn-default' value='Submit' type='submit'>
|
10
|
+
<div id='popup-captcha'></div>
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class='row response hidden' style='margin-top:15%;'>
|
15
|
+
<div class='col-md-offset-4 col-md-4 col-sm-8 col-sm-offset-2 col-xs-12'>
|
16
|
+
<p class='result text-primary' style='text-align:center'></p>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<script type='text/javascript'>
|
21
|
+
var handlerPopup = function (captchaObj) {
|
22
|
+
captchaObj.onSuccess(function () {
|
23
|
+
var validate = captchaObj.getValidate();
|
24
|
+
$.ajax({
|
25
|
+
url: '/popup/validate', // 进行二次验证
|
26
|
+
type: 'post',
|
27
|
+
dataType: 'json',
|
28
|
+
data: {
|
29
|
+
username: $('#username').val(),
|
30
|
+
password: $('#password').val(),
|
31
|
+
geetest_challenge: validate.geetest_challenge,
|
32
|
+
geetest_validate: validate.geetest_validate,
|
33
|
+
geetest_seccode: validate.geetest_seccode
|
34
|
+
},
|
35
|
+
success: function (data) {
|
36
|
+
$('.result').html(data.status);
|
37
|
+
$('.form').addClass('hidden');
|
38
|
+
$('.response').removeClass('hidden');
|
39
|
+
}
|
40
|
+
});
|
41
|
+
});
|
42
|
+
$('input[type=submit]').click(function () {
|
43
|
+
captchaObj.show();
|
44
|
+
});
|
45
|
+
// 将验证码加到id为captcha的元素里
|
46
|
+
captchaObj.appendTo('#popup-captcha');
|
47
|
+
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
|
48
|
+
};
|
49
|
+
// 验证开始需要向网站主后台获取id,challenge,success(是否启用failback)
|
50
|
+
$.ajax({
|
51
|
+
url: '/popup/register?avoid_cache_token=' + (new Date()).getTime(), // 加随机数防止缓存
|
52
|
+
type: 'get',
|
53
|
+
dataType: 'json',
|
54
|
+
success: function (data) {
|
55
|
+
console.log(data);
|
56
|
+
// 使用initGeetest接口
|
57
|
+
// 参数1:配置参数
|
58
|
+
// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
|
59
|
+
initGeetest({
|
60
|
+
gt: data.gt,
|
61
|
+
challenge: data.challenge,
|
62
|
+
product: 'popup', // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
|
63
|
+
offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
|
64
|
+
// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
|
65
|
+
}, handlerPopup);
|
66
|
+
}
|
67
|
+
});
|
68
|
+
</script>
|
data/geetest3.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'geetest/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "geetest3"
|
8
|
+
spec.version = Geetest::VERSION
|
9
|
+
spec.authors = ["jay16"]
|
10
|
+
spec.email = ["jay_li@intfocus.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{geetest sdk3.}
|
13
|
+
spec.description = %q{geetest sdk3.}
|
14
|
+
spec.homepage = %q{http://rubygems.org/gems/geetest3}
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
end
|
data/lib/geetest.rb
ADDED
data/lib/geetest/sdk3.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
module Geetest
|
7
|
+
API_HOST = 'http://api.geetest.com'.freeze
|
8
|
+
API_REGISTER_PATH = '/register.php'.freeze
|
9
|
+
API_VALIDATE_PATH = '/validate.php'.freeze
|
10
|
+
|
11
|
+
class SDK3
|
12
|
+
attr_accessor :captcha_id, :private_key
|
13
|
+
attr_reader :response_str
|
14
|
+
attr_reader :session_key, :fn_challenge, :fn_validate, :fn_seccode
|
15
|
+
|
16
|
+
def initialize(captcha_id, private_key)
|
17
|
+
@captcha_id = captcha_id
|
18
|
+
@private_key = private_key
|
19
|
+
@response_str = ''
|
20
|
+
|
21
|
+
@session_key = 'gt_server_status'.freeze
|
22
|
+
@fn_challenge = 'geetest_challenge'.freeze
|
23
|
+
@fn_validate = 'geetest_validate'.freeze
|
24
|
+
@fn_seccode = 'geetest_seccode'.freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
def pre_process(user_id = nil)
|
28
|
+
status, challenge = register(user_id)
|
29
|
+
@response_str = make_response_format(status, challenge)
|
30
|
+
status
|
31
|
+
end
|
32
|
+
|
33
|
+
def success_validate(challenge = '', validate = '', seccode = '', user_id = nil, gt = nil, data = '', user_info = '')
|
34
|
+
return 0 if challenge.empty? || validate.empty? || seccode.empty?
|
35
|
+
return 0 unless check_result(challenge, validate)
|
36
|
+
|
37
|
+
validate_url = %(#{API_HOST}#{API_VALIDATE_PATH})
|
38
|
+
query = {
|
39
|
+
seccode: seccode,
|
40
|
+
sdk: %(ruby_#{@sdk_version}),
|
41
|
+
user_id: user_id,
|
42
|
+
data: data,
|
43
|
+
timestamp: Time.now.to_s,
|
44
|
+
challenge: challenge,
|
45
|
+
userinfo: user_info,
|
46
|
+
captchaid: gt
|
47
|
+
}
|
48
|
+
response = Net::HTTP.post_form(URI(validate_url), query)
|
49
|
+
response.body == md5_encode(seccode)
|
50
|
+
end
|
51
|
+
|
52
|
+
def failback_validate(challenge = '', validate = '', seccode = '')
|
53
|
+
return 0 if challenge.empty? || validate.empty? || seccode.empty?
|
54
|
+
|
55
|
+
validate_array = validate.split('_')
|
56
|
+
encode_ans = validate_array[0]
|
57
|
+
encode_fbii = validate_array[1]
|
58
|
+
encode_igi = validate_array[2]
|
59
|
+
|
60
|
+
decode_ans = decode_response(challenge, encode_ans)
|
61
|
+
decode_fbii = decode_response(challenge, encode_fbii)
|
62
|
+
decode_igi = decode_response(challenge, encode_igi)
|
63
|
+
validate_fail_image(decode_ans, decode_fbii, decode_igi)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def register(user_id)
|
69
|
+
challenge = register_challenge(user_id)
|
70
|
+
if challenge.length == 32
|
71
|
+
challenge = md5_encode([challenge, private_key].join)
|
72
|
+
[1, challenge]
|
73
|
+
else
|
74
|
+
[0, make_fail_challenge]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def register_challenge(user_id)
|
79
|
+
register_url = %(#{API_HOST}#{API_REGISTER_PATH}?gt=#{captcha_id})
|
80
|
+
register_url = %(#{register_url}&user_id=#{user_id}) if user_id
|
81
|
+
|
82
|
+
response = ::Net::HTTP.get_response(URI(register_url))
|
83
|
+
response.is_a?(Net::HTTPSuccess) ? response.body : ''
|
84
|
+
rescue => e
|
85
|
+
e.message
|
86
|
+
end
|
87
|
+
|
88
|
+
def md5_encode(value)
|
89
|
+
::Digest::MD5.hexdigest(value.to_s)
|
90
|
+
end
|
91
|
+
|
92
|
+
def make_fail_challenge
|
93
|
+
md5_encode(rand(99)) + md5_encode(rand(99))[0..2]
|
94
|
+
end
|
95
|
+
|
96
|
+
def make_response_format(success = 1, challenge = nil)
|
97
|
+
{
|
98
|
+
success: success,
|
99
|
+
gt: @captcha_id,
|
100
|
+
challenge: challenge || make_fail_challenge
|
101
|
+
}.to_json
|
102
|
+
end
|
103
|
+
|
104
|
+
def check_result(origin, validate)
|
105
|
+
validate == md5_encode(@private_key + 'geetest' + origin)
|
106
|
+
end
|
107
|
+
|
108
|
+
def decode_response(challenge, userresponse)
|
109
|
+
return 0 if userresponse.length > 100
|
110
|
+
|
111
|
+
numbers = [1, 2, 5, 10, 50]
|
112
|
+
repeat_numbers = []
|
113
|
+
hash = {}
|
114
|
+
challenge.chars.each_with_index do |char, index|
|
115
|
+
continue if repeat_numbers.include?(char)
|
116
|
+
|
117
|
+
hash[char] = numbers[index % numbers.length]
|
118
|
+
repeat_numbers.push(index)
|
119
|
+
end
|
120
|
+
result = userresponse.to_a.map { |i| key.fetch(i, 0) }.join
|
121
|
+
result - decode_rand_base(challenge)
|
122
|
+
end
|
123
|
+
|
124
|
+
def decode_rand_base(challenge)
|
125
|
+
temp_array = challenge[32..-1].to_a.map do |char|
|
126
|
+
char_ascii = char.ord
|
127
|
+
char_ascii - (char_ascii > 57 ? 87 : 48)
|
128
|
+
end
|
129
|
+
|
130
|
+
temp_array[0] * 36 + temp_array[1]
|
131
|
+
end
|
132
|
+
|
133
|
+
def validate_fail_image(ans, full_bg_index, img_grp_index)
|
134
|
+
thread = 3
|
135
|
+
full_bg_name = md5_encode(full_bg_index)[0..10]
|
136
|
+
bg_name = md5_encode(img_grp_index)[10..20]
|
137
|
+
|
138
|
+
answer_decode = 0.upto(9).map do |i|
|
139
|
+
i.even? ? full_bg_name[i] : bg_name[i]
|
140
|
+
end.join
|
141
|
+
x_decode = answer_decode[4..-1]
|
142
|
+
result = x_decode.to_i(16) % 200
|
143
|
+
result = 40 if result < 40
|
144
|
+
(ans - result).abs < thread
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geetest3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1a
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jay16
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-15 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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: geetest sdk3.
|
56
|
+
email:
|
57
|
+
- jay_li@intfocus.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- example/images/favicon.ico
|
74
|
+
- example/sinatra.rb
|
75
|
+
- example/views/_header.html.erb
|
76
|
+
- example/views/embed.html.erb
|
77
|
+
- example/views/layout.html.erb
|
78
|
+
- example/views/popup.html.erb
|
79
|
+
- geetest3.gemspec
|
80
|
+
- lib/geetest.rb
|
81
|
+
- lib/geetest/sdk3.rb
|
82
|
+
- lib/geetest/version.rb
|
83
|
+
homepage: http://rubygems.org/gems/geetest3
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata:
|
87
|
+
allowed_push_host: https://rubygems.org
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.3.1
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.6.8
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: geetest sdk3.
|
108
|
+
test_files: []
|