源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

597 lines
17 KiB

GamePlatform = GamePlatform or BaseClass()
local GamePlatform = GamePlatform
function GamePlatform:__init()
--是否自定义用户中心
self.custom_user_center = false
--是否自定义退出界面
self.custom_exit_game = ClientConfig.plat_custom_exit
--是否支持切换账号
self.custom_change_account = false
--登陆请求参数
self.login_param = nil
--充值请求参数
self.pay_param = {}
--平台用户ID
self.uid = 0
--外部登陆回调函数
self.login_callback = nil
--外部充值回调函数
self.pay_callback = nil
--上次调用登陆时间
self.last_login_time = 0
--平台标识
self.plat_name = ClientConfig.plat_name
--登陆状态
self.login_state = false
--上次请求充值时间
self.last_pay_request_time = 0
--上次发送角色等级时间
self.last_sent_role_level_time = os.time()
--SDK登陆服务器验证函数
self.login_method_name = "check_login_" .. string.gsub(self.plat_name, "_alpha", "")
ClientConfig.source_plat_name = ClientConfig.plat_name
self.can_send_voice = false --语音权限
self:InitOperTypeValue()
end
function GamePlatform:SDKCallBack( func_name, func_data)
if func_name == "LoginRequest" then
self.wait_login_call_back = false
GlobalEventSystem:Fire(EventName.HIDE_LOADING_VIEW)
self:LoginCallBack(func_data)
elseif func_name == "PayRequest" then
self:PayCallBack(func_data)
elseif func_name == "LoginOut" then
ClientConfig.login_token = nil
self:LoginOutCallBack(func_data)
elseif func_name == "RequestAudioPermission" then
self:OnRequestAudioPermission(func_data)
elseif func_name == "ScreenShot" then
self:ScreenShotBack(func_data)
end
end
function GamePlatform:ScreenShotBack(data)
if data then
local out_data = data
if type(data) == "string" then
out_data = JsonToTable(data)
end
if out_data and out_data.name then
local png_path = "phone/"..out_data.name..".png"
local save_path = Util.DataPath..png_path
if SystemRuntimePlatform.IsAndroid() then
local game_path = "luaFramework/"
save_path = game_path..png_path
end
if UnityEngine and UnityEngine.ScreenCapture then
UnityEngine.ScreenCapture.CaptureScreenshot(save_path)
end
self:CallStringFunc("ScreenShotPath", {path = save_path})
end
end
end
function GamePlatform:CallStringFunc(func,value)
return SDKUtil.CallStringFunc( "SDKPlatform", func, value)
end
function GamePlatform:InitWindow()
PlatformSetting:getInstance():Init(self)
end
function GamePlatform:InitSDK()
end
function GamePlatform:LoginRequest(login_back)
ClientConfig.login_token = nil
local cur_time = os.time()
if cur_time - self.last_login_time < 3 then
return
end
self.last_login_time = cur_time
self.login_callback = login_back
local login_data = {}
local login_func = function()
self:CallSDKMethod("LoginRequest",login_data)
GlobalEventSystem:Fire(EventName.SHOW_LOADING_VIEW)
self.wait_login_call_back = true
local hide_func = function()
if self.wait_login_call_back then
GlobalEventSystem:Fire(EventName.HIDE_LOADING_VIEW)
end
end
setTimeout(hide_func,3)
end
if self.login_state then
self.login_state = false
self:CallSDKMethod("LoginOut",login_data)
setTimeout(login_func, 0.5)
else
login_func()
end
end
function GamePlatform:SetLoginCallBack(login_back)
self.login_callback = login_back
end
function GamePlatform:LoginCallBack( data )
if data then
local login_data = data
if type(data) == "string" then
login_data = JsonToTable(data)
end
if login_data then
if login_data.paramstr then
login_data.paramstr = UrlEncode(login_data.paramstr) --阻止非法字符问题
end
if login_data.uid then
if login_data.token then
ClientConfig.login_token = login_data.token
end
self.uid = login_data.uid or 0
if login_data.sdk_channel and login_data.sdk_channel ~= "" then
self.checkChannel = login_data.sdk_channel
ClientConfig.source_plat_name = ClientConfig.plat_name .. "_" .. self.checkChannel
Debugger.Log("source_plat_name " .. ClientConfig.source_plat_name)
else
self.channel_id = (login_data.sdk_channel or login_data.channel) or login_data.login_channel
if self.channel_id then
self.channel_id = ClientConfig.plat_name .. "_" .. self.channel_id
end
end
local server_check = function( state, error, data )
if state then
local login_data = JsonToTable(data)
if login_data and tonumber(login_data["ret"]) == 0 then
if login_data.token then
ClientConfig.login_token = login_data.token
end
if login_data.uid then --覆盖掉上面的赋值
self.uid = login_data.uid
end
if login_data.sdk_channel and login_data.sdk_channel ~= "" then
self.checkChannel = login_data.sdk_channel
ClientConfig.source_plat_name = ClientConfig.plat_name .. "_" .. self.checkChannel
Debugger.Log("source_plat_name " .. ClientConfig.source_plat_name)
end
if self.login_callback then
self.login_callback( self.uid )
self.login_callback = nil
LoginModel:getInstance().no_login_state = false
end
self.login_state = true
return
end
end
local function ok()
Application.Quit()
end
Alert.show("登陆验证失败,请退出游戏再次进入",Alert.Type.One,ok)
end
self.login_param = {
paramstr = login_data.paramstr or "{}",
}
self:TryCheckLogin( server_check )
if login_data.get_pay_state and tonumber(login_data.get_pay_state) == 1 then
self:GetServerPayState()
end
return
else
local server_check = function(state, error, data)
if state then
local login_data = JsonToTable(data)
if login_data and tonumber(login_data["ret"]) == 0 then
self.uid = login_data.uid or "0"
if login_data.token then
ClientConfig.login_token = login_data.token
end
if login_data.sdk_channel and login_data.sdk_channel ~= "" then
self.checkChannel = login_data.sdk_channel
ClientConfig.source_plat_name = ClientConfig.plat_name .. "_" .. self.checkChannel
Debugger.Log("source_plat_name " .. ClientConfig.source_plat_name)
end
if self.login_callback then
self.login_callback( self.uid )
self.login_callback = nil
LoginModel:getInstance().no_login_state = false
end
self.login_state = true
return
end
end
local function ok()
Application.Quit()
end
Alert.show("登陆验证失败,请退出游戏再次进入",Alert.Type.One,ok)
end
self.check_login = nil
self.login_param = nil
if login_data.checkLogin and tonumber(login_data.checkLogin) == 1 then
self.login_param = {
paramstr = login_data.paramstr or "{}",
}
self:TryCheckLogin( server_check )
end
if login_data.get_pay_state and tonumber(login_data.get_pay_state) == 1 then
self:GetServerPayState()
end
return
end
end
end
Message.show("登陆失败,请重新尝试")
end
function GamePlatform:TryCheckLogin(check_back)
if not self.login_param then
check_back()
else
local callback = function(state, error, data)
self.wait_checklogin_call_back = false
GlobalEventSystem:Fire(EventName.HIDE_LOADING_VIEW)
check_back(state, error, data)
end
local now_time = os.time()
local now_method = self.login_method_name
local now_sign = string.lower(Util.md5(ClientConfig.login_key .. now_time .. now_method))
self.login_param["method"] = now_method
self.login_param["time"] = now_time
self.login_param["sign"] = now_sign
self.login_param["site"] = ClientConfig.plat_name
HttpUtil.HttpGetRequest(ClientConfig.login_php, self.login_param, callback)
GlobalEventSystem:Fire(EventName.SHOW_LOADING_VIEW)
self.wait_checklogin_call_back = true
local hide_func = function()
if self.wait_checklogin_call_back then
GlobalEventSystem:Fire(EventName.HIDE_LOADING_VIEW)
end
end
setTimeout(hide_func,3)
end
end
function GamePlatform:LoginOut()
self.login_state = false --避免多次调用登出接口
self:CallSDKMethod("LoginOut","")
end
function GamePlatform:PayRequest( custom_money, custom_info, custom_callpack )
local cur_time = os.time()
if cur_time - self.last_pay_request_time < 2 then
return
end
self.last_pay_request_time = cur_time
self:PayStart(custom_money * 10, custom_info, custom_callpack)
--TA订单请求打点
local product_id = custom_info.id
local product_cfg = product_id and Config.Rechargeproduct[product_id]
if product_cfg then
local data = {
event_name = "order_init",
currency = "RMB",
pay_amount = tonumber(custom_money) or 0,
pay_item_type = tostring(product_cfg.product_type) or "",
pay_sub_type = tostring(product_cfg.product_subtype) or "",
pay_item_id = tostring(product_id) or "",
pay_item = custom_info.pay_title or "",
is_quick = custom_info.recharge_type and custom_info.recharge_type == 1 or false
}
self:TATrack(data)
end
end
function GamePlatform:PayStart(custom_money, custom_info, custom_callpack)
local server_role = self:ServerRole(custom_info.id or 0)
local random = math.random(100,999)
local role_info = RoleManager.Instance.mainRoleInfo
local playerInfo = LoginController.Instance:GetPlatUserInfo()
local real_plat = string.gsub(self.plat_name, "_alpha", "")
local pay_callback_url = ClientConfig.url_account_path .. "api/pay.php?plat=suyou&platname=".. real_plat
local notify_url_str = ClientConfig.url_account_path .. "api/pay.php?plat=".. real_plat
local notify_url_post_str = ClientConfig.url_account_path .. "api/pay/".. real_plat .. ".php"
local now_order_num = server_role .. "-" .. self.uid .. "-" .. os.time() .. random .. "-" .. self.plat_name
local pay_data = {
pay_money = tostring(custom_money) or 0,
product_id = tostring(custom_info.id),
product_name = custom_info.pay_title or "",
user_id = self.uid,
order_num = now_order_num,
pay_suyou_notify_url = pay_callback_url,
notify_url = notify_url_str,
notify_url_post = notify_url_post_str,
role_id = tostring(role_info.role_id),
role_name = role_info.name,
role_level = tostring(role_info.level),
real_server = tostring(playerInfo.server_id),
server_name = playerInfo.server_name,
pay_state = self.use_web_pay_state or 0,
balance = tostring(role_info.jin),
vip = tostring(role_info.vip_flag),
}
local plat_name = ClientConfig.product_plat or string.gsub(ClientConfig.plat_name, "_alpha", "")
local index = plat_name .. "@" .. pay_data["product_id"]
if Config.Appstroeproduct then
local product_info = Config.Appstroeproduct[index]
if product_info then
pay_data["appstore_product_id"] = Trim(product_info.product) or 0
else
pay_data["appstore_product_id"] = ""
pay_data["appstore_product_id_1"] = plat_name .. (pay_data["pay_money"]/10)
pay_data["appstore_product_id_2"] = plat_name .. (pay_data["pay_money"]*10)
pay_data["appstore_product_id_3"] = plat_name .. (pay_data["pay_money"])
end
end
self:CallSDKMethod("PayRequest",pay_data)
self.pay_callback = custom_callpack
end
function GamePlatform:GetServerPayState()
--向后台获取充值方式
local func_callback = function(state, error, data)
if state then
local login_data = JsonToTable(data)
if login_data and tonumber(login_data["ret"]) == 0 then
local pay_code = tonumber(login_data["data"])
if pay_code ~= 0 and pay_code ~= -1 then
self.use_web_pay_state = pay_code
end
end
end
end
local now_time = os.time()
local now_method = "check_webpay_status"
local now_sign = string.lower(Util.md5(ClientConfig.login_key .. now_time .. now_method))
local get_param = {
method = now_method,
time = now_time,
sign = now_sign,
platform = ClientConfig.plat_name,
lv = 0,
}
HttpUtil.HttpGetRequest(ClientConfig.login_php, get_param, func_callback)
end
function GamePlatform:ServerRole(product_id)
local playerInfo = LoginController.Instance:GetPlatUserInfo()
local role_info = RoleManager.Instance.mainRoleInfo
if not playerInfo or not role_info then
return ""
end
local server_role = playerInfo.server_id .. "gzsy" .. role_info.role_id .. "gzsy" .. product_id
return server_role
end
function GamePlatform:PayCallBack( data )
if self.pay_callback then
self.pay_callback(true)
self.pay_callback = nil
end
end
function GamePlatform:LoginOutCallBack(data)
if data then
local out_data = data
if type(data) == "string" then
out_data = JsonToTable(data)
end
if out_data and out_data.noLogin and tonumber(out_data.noLogin) == 1 then
LoginModel:getInstance().no_login_state = tonumber(out_data.noLogin)
end
end
GlobalEventSystem:Fire(EventName.CHANGE_ACCOUNT)
end
function GamePlatform:CallSDKMethod(func_name, info)
SDKUtil.CallSDKFunc( "SDKPlatform", func_name, info )
end
function GamePlatform:CallBoolFunc(value_name)
return SDKUtil.CallBoolFunc( "SDKPlatform", value_name, "" )
end
function GamePlatform:CallIntFunc(value_name, func_data)
if func_data == nil then
func_data = ""
end
return SDKUtil.CallIntFunc("SDKPlatform", value_name, func_data)
end
function GamePlatform:ShowUserCenter()
self:CallSDKMethod("ShowUserCenter","")
end
function GamePlatform:ExitPlatform()
if self:NeedCustomExitGame() then
self:CallSDKMethod("SDKExit","")
end
self:SubmitExtendData(self.exit_game_type)
end
function GamePlatform:CustonPayParam()
end
function GamePlatform:NeedCustomExitGame()
return self.custom_exit_game
end
function GamePlatform:SubmitCreateRoleInfo(role_id)
self:SubmitExtendData(self.create_role_type,tostring(role_id),"1")
end
function GamePlatform:RoleLevelChange(new_level)
if os.time() - self.last_sent_role_level_time < 30 then
return
end
self.last_sent_role_level_time = os.time()
self:SubmitExtendData(self.role_levelup_type)
end
function GamePlatform:SubmitEnterGame()
self:SubmitExtendData(self.gointo_game_type)
end
function GamePlatform:SubmitSelectServer()
self:SubmitExtendData(self.select_server_type)
end
function GamePlatform:SubmitExtendData( now_type,role_id,role_lv )
if not RoleManager or not RoleManager.Instance then
return
end
local playerInfo = LoginController.Instance:GetPlatUserInfo()
local role_info = RoleManager.Instance.mainRoleInfo
local cur_role_name = role_info.name
if cur_role_name == "" or now_type == self.create_role_type then
cur_role_name = playerInfo.role_name or ""
end
local extend_data = {
type = now_type,
role_id = role_id or tostring(role_info.role_id),
role_name = cur_role_name,
role_level = role_lv or tostring(role_info.level),
real_server = tostring(playerInfo.server_id),
server_name = playerInfo.server_name,
balance = tostring(role_info.jin),
vip = tostring(role_info.vip_flag),
reg_time = tostring(playerInfo.create_time or os.time()),
user_id = self.uid,
--兼容老版本
uid = self.uid,
server = tostring(playerInfo.server_id),
roleCTime = tostring(playerInfo.create_time or os.time()),
serverNanme = playerInfo.server_name,
time = os.time(),
}
self:CallSDKMethod("SubmitExtendData",extend_data)
end
function GamePlatform:InitOperTypeValue()
self.select_server_type = 101
self.create_role_type = 102
self.gointo_game_type = 103
self.role_levelup_type = 104
self.exit_game_type = 105
end
function GamePlatform:GetUserID()
return self.uid
end
function GamePlatform:ShareBySDK()
local share_data = {}
self:CallSDKMethod("ShareBySDK", share_data)
end
function GamePlatform:SuyouEventRecord( event_id )
-- local url = "http://mqapi.suyougame.com/point/mrzj"
-- local secretKey = "9A22E32CA2CFF5282F614F84138437F6"
-- local cur_time = tostring(os.time())
-- local post_param = {
-- type = event_id,
-- source = ClientConfig.plat_name,
-- deviceId = LoginModel:getInstance().devece_id,
-- startTime = LoginModel:getInstance().first_setup_time,
-- time = cur_time,
-- sign = "",
-- }
-- post_param.sign = string.lower(Util.md5("deviceId="..post_param.deviceId.."source="..post_param.source.."startTime="..post_param.startTime.."time="..post_param.time.."type="..post_param.type..secretKey))
-- local call_func = function(ret,error_msg,data)
-- end
-- HttpUtil.HttpPostRequest(url, post_param, call_func)
end
function GamePlatform:RequestAudioPermission( )
local share_data = {}
self:CallSDKMethod("RequestAudioPermission", share_data)
end
function GamePlatform:IsNeedRequestAudioPermission( )
-- local is_need_permission = self:CallIntFunc("RequestAudioPermission")
-- return is_need_permission
end
function GamePlatform:OnRequestAudioPermission( data )
if data then
local out_data = data
self.can_send_voice = false
-- Debugger.Log("OnRequestAudioPermission out_data:" .. out_data)
if out_data and tonumber(out_data) == 1 then
self.can_send_voice = true
end
GlobalEventSystem:Bind(EventName.UPDATE_VOICE_AUTH, self.can_send_voice)
end
end
function GamePlatform:CanSendVoice( )
return self.can_send_voice
end
function GamePlatform:DeleteMe()
end
--ta打点额外数据
function GamePlatform:SubmitSpecialData( parm_type, parm_value )
local share_data = {type = parm_type, value = parm_value}
self:CallSDKMethod("SubmitSpecialData", share_data)
end
--ta打点数据上报,参数{event_name = str, key1 = value1, key2 = value2 ...}
function GamePlatform:TATrack( data )
self:CallSDKMethod("TATrack", data)
end