Login.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. require 'spaceship'
  2. require 'mysql2'
  3. require 'json'
  4. require 'pathname'
  5. require Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/Mysql'
  6. class Login
  7. @@showTime = 0;
  8. def initialize(username, password, sleep = 1)
  9. @username = username
  10. @password = password
  11. @sleep = sleep
  12. end
  13. def setShowTime(show = 1)
  14. @@showTime = show
  15. end
  16. def login()
  17. begin
  18. thr = Thread.new{ Spaceship::Portal.login(@username, @password) }
  19. for i in 0..11
  20. sleep @sleep
  21. case thr.status
  22. when false
  23. client = Mysql.instance.getClient();
  24. client.query("update prefix_super_cert set status = 1 where type = 1 and status = 1 and username = '#{@username}'")
  25. break
  26. when nil
  27. raise 'error: 双重验证错误'
  28. break
  29. else
  30. #puts Time.new if @@showTime
  31. end
  32. end
  33. if thr.status
  34. thr.exit
  35. raise 'error: 双重验证超时'
  36. end
  37. rescue Exception => e
  38. client.query("update prefix_super_cert set status = 3 where type = 1 and username = '#{@username}'")
  39. if e.message.include?("=>")
  40. response = JSON.parse e.message.gsub('=>', ':')
  41. jsonData = {
  42. "status" => 0,
  43. "msg" => "登录失败",
  44. "response" => response
  45. }
  46. else
  47. jsonData = {
  48. "status" => 0,
  49. "msg" => e.message
  50. }
  51. end
  52. puts JSON[jsonData]
  53. exit
  54. ensure
  55. #Mysql.instance.close()
  56. end
  57. end
  58. end