LoginOtpPassWordProxy.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local LoginOtpPassWordProxy = class("LoginOtpPassWordProxy", RemoteProxy)
  3. LoginOtpPassWordProxy.NAME = global.ProxyTable.LoginOtpPassWordProxy
  4. local cjson = require("cjson")
  5. -- "https://security-center-api-test.tj.996sdk.com" --测试域名
  6. local baseURL = nil
  7. local signkey = "1a3695c8b32665ad02267f972e281156"
  8. local function urlencodechar(char)
  9. return "%" .. string.format("%02X", string.byte(char))
  10. end
  11. local function urlencodeT(input)
  12. -- convert line endings
  13. input = string.gsub(tostring(input), "\n", "\r\n")
  14. -- escape all characters but alphanumeric, '.' and '-'
  15. input = string.gsub(input, "([^%w%.%-%_%~ ])", urlencodechar)
  16. -- convert spaces to "+" symbols
  17. return string.gsub(input, " ", "+")
  18. end
  19. local function calcSuffix(originData)
  20. -- ascii排序
  21. table.sort(originData, function(a, b)
  22. return a.key < b.key
  23. end)
  24. -- 计算sign
  25. local origin = ""
  26. for i, v in ipairs(originData) do
  27. local send_value = v.value
  28. if send_value then
  29. if string.find(send_value, "%%") then
  30. local strList = string.split(send_value, "%")
  31. local t = urlencodeT("%")
  32. send_value = table.concat(strList, t)
  33. end
  34. if string.find(send_value, "%+") then
  35. local strList = string.split(send_value, "+")
  36. local t = urlencodeT("+")
  37. send_value = table.concat(strList, t)
  38. end
  39. if string.find(send_value, "%&") then
  40. local strList = string.split(send_value, "&")
  41. local t = urlencodeT("&")
  42. send_value = table.concat(strList, t)
  43. end
  44. end
  45. origin = origin .. string.format("%s=%s", v.key, v.value)
  46. origin = origin .. (i < #originData and "&" or "")
  47. end
  48. local tempOrigin = string.format("%s%s", origin, signkey)
  49. local sign = get_str_MD5(tempOrigin)
  50. -- 拼接sign
  51. local suffix = origin .. "&" .. string.format("sign=%s", sign)
  52. return suffix
  53. end
  54. function LoginOtpPassWordProxy:ctor()
  55. LoginOtpPassWordProxy.super.ctor(self)
  56. self._is_open = "/api/v1/game/isOpenValidate"
  57. self._check_code = "/api/v1/game/checkCode"
  58. self._is_open_otp = false
  59. local envProxy = global.Facade:retrieveProxy(global.ProxyTable.GameEnvironment)
  60. baseURL = envProxy:GetCustomDataByKey("securityCodeUrl")
  61. if baseURL and string.len(baseURL) > 0 then
  62. self._is_open_otp = true
  63. end
  64. self._check_type = "1"
  65. self._otp_code = 0
  66. end
  67. function LoginOtpPassWordProxy:getCheckType()
  68. return self._check_type or "1"
  69. end
  70. function LoginOtpPassWordProxy:getOtpCode()
  71. return self._otp_code or 0
  72. end
  73. function LoginOtpPassWordProxy:isOpenVerifyOtpPassWord()
  74. if not self._is_open_otp then
  75. global.Facade:sendNotification(global.NoticeTable.Layer_Login_OtpPassWord_Refresh, {
  76. isOpen = false
  77. })
  78. return false
  79. end
  80. local requestURL = baseURL .. self._is_open
  81. local function httpCB(success, response)
  82. local isOpen = false
  83. if success then
  84. local jsonData = cjson.decode(response)
  85. isOpen = jsonData and jsonData.code == 200
  86. end
  87. releasePrint("======是否开启response: ", response)
  88. -- data.result 是否开启保护 false:未开启 true:开启
  89. global.Facade:sendNotification(global.NoticeTable.Layer_Login_OtpPassWord_Refresh, {
  90. isOpen = isOpen == true
  91. })
  92. end
  93. local AuthProxy = global.Facade:retrieveProxy( global.ProxyTable.AuthProxy )
  94. local currModule = global.L_ModuleManager:GetCurrentModule()
  95. local account = AuthProxy:GetUsername()
  96. local account_id = AuthProxy:GetUID()
  97. local game_id = currModule:GetOperID()
  98. local originData = {
  99. {key = "account_id", value = account_id or ""}, -- uid
  100. {key = "game_id", value = game_id or ""}, -- 游戏id
  101. {key = "type", value = self._check_type}, -- 账号类型,默认为1。 1:996sdk
  102. }
  103. local isAccount = true
  104. local currentModule = global.L_ModuleManager:GetCurrentModule()
  105. local envProxy = global.Facade:retrieveProxy(global.ProxyTable.GameEnvironment)
  106. local moduleGameEnv = currentModule:GetGameEnv()
  107. local loginData = moduleGameEnv:GetLoginData()
  108. local token = global.L_GameEnvManager:GetEnvDataByKey("token")
  109. local boxtoken = envProxy:getBoxtoken()
  110. local isPcSdk = global.L_GameEnvManager:GetEnvDataByKey("isPcSdk")
  111. if loginData and loginData.password then
  112. isAccount = false
  113. elseif token and string.len(string.trim(token)) > 0 then
  114. isAccount = false
  115. elseif boxtoken then
  116. isAccount = false
  117. elseif isPcSdk then
  118. isAccount = false
  119. end
  120. -- 账号检测
  121. if isAccount then
  122. originData[#originData] = {key = "account", value = account or ""} -- 账号
  123. end
  124. local suffix = calcSuffix(originData)
  125. HTTPRequestPost(requestURL, httpCB, suffix)
  126. end
  127. function LoginOtpPassWordProxy:verifyOtpPassWord( otp )
  128. if not self._is_open_otp then
  129. return false
  130. end
  131. local requestURL = baseURL .. self._check_code
  132. self._otp_code = otp
  133. local function httpCB(success, response)
  134. local verufySuccess = false
  135. local jsonData = {}
  136. if success then
  137. jsonData = cjson.decode(response)
  138. verufySuccess = jsonData and jsonData.code == 200
  139. end
  140. releasePrint("======验证response: ", response)
  141. local jsonMsg = tostring(jsonData.msg)
  142. local msg = GET_STRING(310000902)
  143. if jsonMsg and string.len(jsonMsg) > 0 then
  144. msg = jsonMsg
  145. end
  146. -- data.result -- false:验证失败 true:验证成功
  147. global.Facade:sendNotification(global.NoticeTable.Layer_Login_OtpPassWord_Refresh, {
  148. verufySuccess = verufySuccess == true,
  149. msg = msg
  150. })
  151. end
  152. local AuthProxy = global.Facade:retrieveProxy( global.ProxyTable.AuthProxy )
  153. local currModule = global.L_ModuleManager:GetCurrentModule()
  154. local account = AuthProxy:GetUsername()
  155. local account_id = AuthProxy:GetUID()
  156. local game_id = currModule:GetOperID()
  157. local originData = {
  158. {key = "account_id", value = account_id or ""}, -- uid
  159. {key = "game_id", value = game_id or ""}, -- 游戏id
  160. {key = "code", value = otp or ""}, -- 验证码
  161. {key = "type", value = self._check_type}, -- 账号类型,默认为1。 1:996sdk
  162. }
  163. local isAccount = true
  164. local currentModule = global.L_ModuleManager:GetCurrentModule()
  165. local envProxy = global.Facade:retrieveProxy(global.ProxyTable.GameEnvironment)
  166. local moduleGameEnv = currentModule:GetGameEnv()
  167. local loginData = moduleGameEnv:GetLoginData()
  168. local token = global.L_GameEnvManager:GetEnvDataByKey("token")
  169. local boxtoken = envProxy:getBoxtoken()
  170. local isPcSdk = global.L_GameEnvManager:GetEnvDataByKey("isPcSdk")
  171. if loginData and loginData.password then
  172. isAccount = false
  173. elseif token and string.len(string.trim(token)) > 0 then
  174. isAccount = false
  175. elseif boxtoken then
  176. isAccount = false
  177. elseif isPcSdk then
  178. isAccount = false
  179. end
  180. -- 账号检测
  181. if isAccount then
  182. originData[#originData] = {key = "account", value = account or ""} -- 账号
  183. end
  184. local suffix = calcSuffix(originData)
  185. HTTPRequestPost(requestURL, httpCB, suffix)
  186. end
  187. function LoginOtpPassWordProxy:RegisterMsgHandler()
  188. LoginOtpPassWordProxy.super.RegisterMsgHandler(self)
  189. end
  190. return LoginOtpPassWordProxy