confirmation_code 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b2e71831c04e65a01c06615b8069478c2dda270
4
- data.tar.gz: 91801c970dbcf51fa5c7b35fcdfa103979666c45
3
+ metadata.gz: c0009cee084165c1cabeee0c05d9a4e900569550
4
+ data.tar.gz: 3eaf2fc4a90edd34cdf34f5ca6978e62b3663fdc
5
5
  SHA512:
6
- metadata.gz: fc64f9d6ec397a531558e2eb461ed040d56c5c958f7e2a1388fdf042fe07b4b30a28d9f5bf99200023fb85a330e0aea8cbcd22583e1f524dbdbb783853211890
7
- data.tar.gz: 7685756871eea8077671f86fcbf464016937457d3e5b641cdaa74d48b8081b180436a49f70fe95b978c1ca7ab0de5547170c44c51aca64203a6e6f2390c9ae0a
6
+ metadata.gz: 06042427c72b5a822eaf1d131154be75b00c34014f2554efd5012ada8230a683d6a8f41425193218cbd1d1c9c380816f87b01b5ca58eb351dee3cfbb75fc11cc
7
+ data.tar.gz: 4f0ba8abc5137f3b62e6a99e35de7442c90c999cb7f644801f0c54a67853fa17ddb142ef6684a044b489868b8d4546f2c7a21abd206e3bdedd8ac689af33d57d
data/.gitignore ADDED
@@ -0,0 +1,41 @@
1
+ ### Ruby template
2
+ *.gem
3
+ .idea/
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /spec/examples.txt
11
+ /test/tmp/
12
+ /test/version_tmp/
13
+ /tmp/
14
+
15
+ ## Specific to RubyMotion:
16
+ .dat*
17
+ .repl_history
18
+ build/
19
+
20
+ ## Documentation cache and generated files:
21
+ /.yardoc/
22
+ /_yardoc/
23
+ /doc/
24
+ /rdoc/
25
+
26
+ ## Environment normalisation:
27
+ /.bundle/
28
+ /vendor/bundle
29
+ /lib/bundler/man/
30
+
31
+ # for a library or gem, you might want to ignore these files since the code is
32
+ # intended to run in multiple environments; otherwise, check them in:
33
+ # Gemfile.lock
34
+ # .ruby-version
35
+ # .ruby-gemset
36
+
37
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
38
+ .rvmrc
39
+ *.jpeg
40
+
41
+ # Created by .ignore support plugin (hsz.mobi)
data/api.py ADDED
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/python
2
+ #coding=utf-8
3
+
4
+ import urllib
5
+ import urllib2
6
+ import mimetools, mimetypes
7
+ import os, stat
8
+
9
+ class Callable:
10
+ def __init__(self, anycallable):
11
+ self.__call__ = anycallable
12
+
13
+ doseq = 1
14
+
15
+ class MultipartPostHandler(urllib2.BaseHandler):
16
+ handler_order = urllib2.HTTPHandler.handler_order - 10 # needs to run first
17
+
18
+ def http_request(self, request):
19
+ data = request.get_data()
20
+ if data is not None and type(data) != str:
21
+ v_files = []
22
+ v_vars = []
23
+ try:
24
+ for(key, value) in data.items():
25
+ if type(value) == file:
26
+ v_files.append((key, value))
27
+ else:
28
+ v_vars.append((key, value))
29
+ except TypeError:
30
+ systype, value, traceback = sys.exc_info()
31
+ raise TypeError, "not a valid non-string sequence or mapping object", traceback
32
+
33
+ if len(v_files) == 0:
34
+ data = urllib.urlencode(v_vars, doseq)
35
+ else:
36
+ boundary, data = self.multipart_encode(v_vars, v_files)
37
+ contenttype = 'multipart/form-data; boundary=%s' % boundary
38
+ if(request.has_header('Content-Type')
39
+ and request.get_header('Content-Type').find('multipart/form-data') != 0):
40
+ print "Replacing %s with %s" % (request.get_header('content-type'), 'multipart/form-data')
41
+ request.add_unredirected_header('Content-Type', contenttype)
42
+
43
+ request.add_data(data)
44
+ return request
45
+
46
+ def multipart_encode(vars, files, boundary = None, buffer = None):
47
+ if boundary is None:
48
+ boundary = "--1234567890"
49
+ if buffer is None:
50
+ buffer = ''
51
+ for(key, value) in vars:
52
+ buffer += '--%s\r\n' % boundary
53
+ buffer += 'Content-Disposition: form-data; name="%s"' % key
54
+ buffer += '\r\n\r\n' + value + '\r\n'
55
+ for(key, fd) in files:
56
+ file_size = os.fstat(fd.fileno())[stat.ST_SIZE]
57
+ filename = fd.name.split('/')[-1]
58
+ contenttype = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
59
+ buffer += '--%s\r\n' % boundary
60
+ buffer += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename)
61
+ buffer += 'Content-Type: %s\r\n' % contenttype
62
+ fd.seek(0)
63
+ buffer += '\r\n' + fd.read() + '\r\n'
64
+ buffer += '--%s--\r\n\r\n' % boundary
65
+ return boundary, buffer
66
+ multipart_encode = Callable(multipart_encode)
67
+ https_request = http_request
68
+
69
+ def main(api_username,api_password,img_url,api_post_url,yzm_min='',yzm_max='',yzm_type='',tools_token=''):
70
+ import tempfile
71
+
72
+ validatorURL = api_post_url
73
+ opener = urllib2.build_opener(MultipartPostHandler)
74
+
75
+ if yzm_min == '' :
76
+ yzm_min = '4'
77
+ if yzm_max == '' :
78
+ yzm_max = '4'
79
+
80
+ def validateFile(url):
81
+ temp = tempfile.mkstemp(suffix=".png")
82
+ os.write(temp[0],opener.open(url).read())
83
+ params = { "user_name" : '%s' % api_username,
84
+ "user_pw" : "%s" % api_password ,
85
+ "yzm_minlen" : "%s" % yzm_min ,
86
+ "yzm_maxlen" : "%s" % yzm_max ,
87
+ "yzmtype_mark" : "%s" % yzm_type ,
88
+ "zztool_token" : "%s" % tools_token ,
89
+ "upload" : open(temp[1], "rb")
90
+ }
91
+ print params
92
+ print opener.open(validatorURL, params).read()
93
+
94
+ validateFile(img_url)
95
+
96
+ if __name__=="__main__":
97
+ main('seaify',
98
+ '67c86225',
99
+ 'https://passport.58.com/validatecode?temp=123i1knr04o',
100
+ "http://bbb4.hyslt.com/api.php?mod=php&act=upload",
101
+ '4',
102
+ '6',
103
+ '',
104
+ '')
105
+
106
+ '''
107
+ main() 参数介绍
108
+ api_username (API账号) --必须提供
109
+ api_password (API账号密码) --必须提供
110
+ img_url (需要打码的验证码URL) --必须提供
111
+ api_post_url (API接口地址) --必须提供
112
+ yzm_min (验证码最小值) --可空提供
113
+ yzm_max (验证码最大值) --可空提供
114
+ yzm_type (验证码类型) --可空提供
115
+ tools_token (工具或软件token) --可空提供
116
+ '''
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'confirmation_code/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "confirmation_code"
7
+ s.version = ConfirmationCode::VERSION
8
+ s.date = "2016-02-03"
9
+ s.summary = "use platforms like lianzhong to auto input confirmation code"
10
+ s.description = "support platforms like lianzhong"
11
+ s.authors = ["seaify"]
12
+ s.email = "dilin.life@gmail.com"
13
+ s.files += `git ls-files`.split($/)
14
+ s.homepage = "https://github.com/seaify/confirmation_code"
15
+ s.license = "MIT"
16
+
17
+ s.executables << 'confirmation_code'
18
+ s.add_dependency 'httpclient', '~> 2.7'
19
+ s.add_dependency 'awesome_print', '~> 1.6'
20
+ end
@@ -0,0 +1,54 @@
1
+ require 'awesome_print'
2
+ require 'open-uri'
3
+ require 'httpclient'
4
+ require 'json'
5
+
6
+ module ConfirmationCode
7
+ module Service
8
+ module Lianzhong
9
+
10
+ extend self
11
+ include ConfirmationCode
12
+
13
+ UPLOAD_URL = 'http://bbb4.hyslt.com/api.php?mod=php&act=upload'
14
+ ACCOUNT_URL = 'http://bbb4.hyslt.com/api.php?mod=php&act=point'
15
+ RECOGNITION_ERROR_URL = 'http://bbb4.hyslt.com/api.php?mod=php&act=error'
16
+
17
+ def client
18
+ @client ||= HTTPClient.new
19
+ end
20
+
21
+ def upload(image_url, options = {})
22
+ File.open("code.jpeg", "wb") do |f|
23
+ f.write open(image_url).read
24
+ end
25
+ options = default_options.merge options
26
+ File.open('code.jpeg') do |file|
27
+ options['upload'] = file
28
+ response = client.post(UPLOAD_URL, options)
29
+ JSON.parse(response.body)
30
+ end
31
+ end
32
+
33
+ def account(options = {})
34
+ response = client.post(ACCOUNT_URL, options)
35
+ JSON.parse(response.body)
36
+ end
37
+
38
+ def recognition_error(options = {})
39
+ response = client.post(RECOGNITION_ERROR_URL, options)
40
+ JSON.parse(response.body)
41
+ end
42
+
43
+ def default_options
44
+ {
45
+ yzm_minlen: '4',
46
+ yzm_maxlen: '6',
47
+ yzmtype_mark: '',
48
+ zztool_token: '',
49
+ }
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module ConfirmationCode
2
+ VERSION = "0.0.4"
3
+ end
data/run.rb ADDED
@@ -0,0 +1,12 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'confirmation_code'
5
+
6
+ ConfirmationCode.use :lianzhong, 'seaify', '67c86225'
7
+ ap ConfirmationCode.account
8
+ result = ConfirmationCode.upload 'https://passport.58.com/validatecode?temp=123i1knr04o'
9
+ ap result
10
+ ap ConfirmationCode.recognition_error result['data']['id']
11
+ ap ConfirmationCode.account
12
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confirmation_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - seaify
@@ -45,8 +45,14 @@ executables:
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".gitignore"
49
+ - api.py
48
50
  - bin/confirmation_code
51
+ - confirmation_code.gemspec
49
52
  - lib/confirmation_code.rb
53
+ - lib/confirmation_code/service/lianzhong.rb
54
+ - lib/confirmation_code/version.rb
55
+ - run.rb
50
56
  homepage: https://github.com/seaify/confirmation_code
51
57
  licenses:
52
58
  - MIT