Module: ConfirmationCode::Service::Lianzhong

Extended by:
Lianzhong
Includes:
ConfirmationCode
Included in:
Lianzhong
Defined in:
lib/confirmation_code/service/lianzhong.rb

Constant Summary collapse

UPLOAD_URL =
'http://bbb4.hyslt.com/api.php?mod=php&act=upload'
ACCOUNT_URL =
'http://bbb4.hyslt.com/api.php?mod=php&act=point'
RECOGNITION_ERROR_URL =
'http://bbb4.hyslt.com/api.php?mod=php&act=error'

Constants included from ConfirmationCode

VERSION

Instance Attribute Summary

Attributes included from ConfirmationCode

#password, #username

Instance Method Summary collapse

Methods included from ConfirmationCode

#use

Instance Method Details

#account(options = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/confirmation_code/service/lianzhong.rb', line 46

def (options = {})
  options = lianzhong_options.merge options
  print options
  response = client.post(, options)
  result(JSON.parse(response.body))
end

#clientObject



17
18
19
# File 'lib/confirmation_code/service/lianzhong.rb', line 17

def client
  @client ||= HTTPClient.new
end

#lianzhong_optionsObject



59
60
61
62
63
64
65
66
# File 'lib/confirmation_code/service/lianzhong.rb', line 59

def lianzhong_options
  {
      yzm_minlen:  '4',
      yzm_maxlen: '6',
      yzmtype_mark: '',
      zztool_token: '',
  }
end

#recognition_error(ret_id, options = {}) ⇒ Object



53
54
55
56
57
# File 'lib/confirmation_code/service/lianzhong.rb', line 53

def recognition_error(ret_id, options = {})
  options['yzm_id'] = ret_id
  response = client.post(RECOGNITION_ERROR_URL, options)
  result(JSON.parse(response.body))
end

#result(body) ⇒ Object



68
69
70
71
72
73
# File 'lib/confirmation_code/service/lianzhong.rb', line 68

def result(body)
  {
      "success" => body['result'],
      "data" => body['data']
  }
end

#set_extra_options(options) ⇒ Object



21
22
23
# File 'lib/confirmation_code/service/lianzhong.rb', line 21

def set_extra_options(options)

end

#upload(image_url, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/confirmation_code/service/lianzhong.rb', line 25

def upload(image_url, options = {})
  File.open("code.jpeg", "wb") do |f|
    f.write open(image_url).read
  end
  options = lianzhong_options.merge options
  File.open('code.jpeg') do |file|
    options['upload'] = file
    response = client.post(UPLOAD_URL, options)
    result(JSON.parse(response.body))
  end
end

#upload_local(image_path, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/confirmation_code/service/lianzhong.rb', line 37

def upload_local(image_path, options = {})
  options = lianzhong_options.merge options
  File.open(image_path) do |file|
    options['upload'] = file
    response = client.post(UPLOAD_URL, options)
    result(JSON.parse(response.body))
  end
end