140 lines
4.5 KiB
Lua
140 lines
4.5 KiB
Lua
LoginManager = {};
|
|
local this = LoginManager
|
|
this.sign = "d13b3e8ef74bf72d8aafce3a1c8672a0"
|
|
this.openId = nil
|
|
this.token = nil
|
|
this.IsLogin = false
|
|
this.pt_pId = ""
|
|
this.pt_gId = ""
|
|
|
|
local LoginRoot_Url = VersionManager:GetVersionInfo("serverUrl")
|
|
function this.Initialize()
|
|
this.IsLogin = false
|
|
this.GameName='DouDou'
|
|
local defaultLoginWay=0
|
|
if UnityEngine.Application.isMobilePlatform then
|
|
defaultLoginWay=1
|
|
else
|
|
defaultLoginWay=0
|
|
end
|
|
this.CurLoginWay=PlayerPrefs.GetInt(this.GameName.."LoginWay",defaultLoginWay)
|
|
this.CurAccount=PlayerPrefs.GetString(this.GameName.."Account",'')
|
|
this.CurSession=PlayerPrefs.GetString(this.GameName.."Session",'')
|
|
|
|
SDKMgr.onLoginCallback = function(loginResp)
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.LoginSuccess.OnLoginSuccess,loginResp)
|
|
ThinkingAnalyticsManager.Track("app_login")
|
|
end
|
|
|
|
SDKMgr.onSwitchAccountCallback = function(resp)
|
|
Log("onSwitchAccountCallback::"..resp)
|
|
local result = string.split(resp, "#")
|
|
--Util.LogError(debug.traceback("<color=#00ccee>onSwitchAccountCallback:" .. result[1] .. "</color>"))
|
|
if LoginManager.IsLogin and tonumber(result[1]) == SDK_RESULT.SUCCESS then
|
|
ThinkingAnalyticsManager.Track("change_account")
|
|
Framework.Dispose()
|
|
App.Instance:ReStart()
|
|
end
|
|
end
|
|
|
|
SDKMgr.onLogoutCallback = function(resp)
|
|
Log("onLogoutCallback::"..resp)
|
|
local result = string.split(resp, "#")
|
|
--Util.LogError(debug.traceback("<color=#00ccee>onLogoutCallback:" .. result[1] .. "</color>"))
|
|
if LoginManager.IsLogin and tonumber(result[1]) == SDK_RESULT.SUCCESS then
|
|
ThinkingAnalyticsManager.Track("quit_account")
|
|
Framework.Dispose()
|
|
App.Instance:ReStart()
|
|
end
|
|
end
|
|
end
|
|
|
|
function this.SaveLoginInfo(user, pw)
|
|
--[[
|
|
PlayerPrefs.SetInt(this.GameName.."LoginWay", this.CurLoginWay);
|
|
PlayerPrefs.SetString(this.GameName.."Account", this.CurAccount);
|
|
PlayerPrefs.SetString(this.GameName.."Session", this.CurSession);
|
|
PlayerPrefs.Save();
|
|
]]--
|
|
--sdkMgr:SaveSession(this.CurLoginWay)
|
|
|
|
|
|
end
|
|
|
|
function this.RequestRegist(name, pw, call)
|
|
local sign = Util.MD5Encrypt(string.format("%s%s%s", name,
|
|
pw, this.sign))
|
|
|
|
RequestPanel.Show(Language[11115])
|
|
networkMgr:SendGetHttp(LoginRoot_Url .. "jl_loginserver/registerUser?userName=".. name .. "&password=".. pw .."&repeat=".. pw .. "&sign=" .. sign,
|
|
function(str)
|
|
RequestPanel.Hide()
|
|
if str == nil then
|
|
return
|
|
end
|
|
--Log(str)
|
|
local json = require 'cjson'
|
|
local data = json.decode(str)
|
|
|
|
if data.code==1 then
|
|
PopupTipPanel.ShowTip(Language[11116]..name.." "..data.msg)
|
|
else
|
|
--PopupTipPanel.ShowTip("账号:"..name.." "..data.msg)
|
|
end
|
|
if call then
|
|
call(data.code)
|
|
end
|
|
end,nil,nil,nil)
|
|
end
|
|
|
|
function this.RequestUser(name, pw, call)
|
|
local sign = Util.MD5Encrypt(string.format("%s%s%s", name,
|
|
pw, this.sign))
|
|
|
|
RequestPanel.Show(Language[11117])
|
|
networkMgr:SendGetHttp(LoginRoot_Url .. "jl_loginserver/userLogin?userName=".. name .. "&password=".. pw .. "&sign=" .. sign, function(str)
|
|
RequestPanel.Hide()
|
|
if str == nil then
|
|
return
|
|
end
|
|
--Log(str)
|
|
local json = require 'cjson'
|
|
local data = json.decode(str)
|
|
|
|
--Log("data.code:"..data.code)
|
|
--Log("data.msg:"..data.msg)
|
|
|
|
if data.code==0 then
|
|
--Log("data.parms.openId:"..data.parms.openId)
|
|
--Log("data.parms.token:"..data.parms.token)
|
|
|
|
--PopupTipPanel.ShowTip(data.msg)
|
|
this.openId = data.parms.openId
|
|
this.token = data.parms.token
|
|
--场景转换
|
|
else
|
|
PopupTipPanel.ShowTip(data.msg)
|
|
end
|
|
if call then
|
|
call(data.code)
|
|
end
|
|
end,nil,nil,nil)
|
|
end
|
|
|
|
--注销
|
|
function this.LogOut()
|
|
this.CurLoginWay=-1
|
|
this.CurAccount=''
|
|
this.CurSession=''
|
|
--sdkMgr:ClearSession()
|
|
--[[
|
|
PlayerPrefs.DeleteKey(this.GameName.."LoginWay")
|
|
PlayerPrefs.DeleteKey(this.GameName.."Account")
|
|
PlayerPrefs.DeleteKey(this.GameName.."Session")
|
|
]]--
|
|
Framework.Dispose();
|
|
--sdkMgr:LogOutTime(tostring(PlayerManager.player.id));
|
|
App.Instance:ReStart();
|
|
end
|
|
|
|
return this |