155 lines
5.4 KiB
Lua
155 lines
5.4 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 = ServerConfigManager.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",'')
|
|
|
|
this.isRegister = false
|
|
|
|
SDKMgr.onRegisterCallback = function()
|
|
this.isRegister = true
|
|
end
|
|
|
|
SDKMgr.onLoginCallback = function(loginResp)
|
|
-- 获取登录信息
|
|
local result = string.split(loginResp, "#")
|
|
result[1] = tonumber(result[1])
|
|
if result[1] == SDK_RESULT.SUCCESS then
|
|
AppConst.SdkId = result[2]
|
|
AppConst.OpenId = result[2]
|
|
AppConst.TokenStr = result[4]
|
|
AppConst.SdkChannel = result[5]
|
|
AppConst.SdkPackageName = AndroidDeviceInfo.Instance:GetPackageName()
|
|
end
|
|
-- 判断是否是注册并登录
|
|
if this.isRegister then
|
|
this.isRegister = false
|
|
-- 登出之前的账号
|
|
ThinkingAnalyticsManager.Logout()
|
|
ThinkingAnalyticsManager.ClearSuperProperties()
|
|
-- 开始
|
|
ThinkingAnalyticsManager.SetSuperProperties({
|
|
account = AppConst.isSDK and tostring(AppConst.OpenId) or "",
|
|
Bundle_id = AppConst.isSDK and AppConst.SdkPackageName or "",
|
|
xx_id = AppConst.isSDK and AppConst.SdkChannel or "",
|
|
device_id = AppConst.isSDK and ThinkingAnalyticsManager.GetDeviceId() or ""
|
|
})
|
|
ThinkingAnalyticsManager.Track("create_account")
|
|
end
|
|
-- 发送登录成功事件
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.LoginSuccess.OnLoginSuccess,result[1])
|
|
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")
|
|
Game.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")
|
|
Game.Restart()
|
|
end
|
|
-- 发送登出事件
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.LoginSuccess.OnLogout)
|
|
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[11132])
|
|
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[11133]..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[11134])
|
|
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
|
|
|
|
return this |