源战役客户端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

597 wiersze
17 KiB

4 tygodni temu
  1. GamePlatform = GamePlatform or BaseClass()
  2. local GamePlatform = GamePlatform
  3. function GamePlatform:__init()
  4. --是否自定义用户中心
  5. self.custom_user_center = false
  6. --是否自定义退出界面
  7. self.custom_exit_game = ClientConfig.plat_custom_exit
  8. --是否支持切换账号
  9. self.custom_change_account = false
  10. --登陆请求参数
  11. self.login_param = nil
  12. --充值请求参数
  13. self.pay_param = {}
  14. --平台用户ID
  15. self.uid = 0
  16. --外部登陆回调函数
  17. self.login_callback = nil
  18. --外部充值回调函数
  19. self.pay_callback = nil
  20. --上次调用登陆时间
  21. self.last_login_time = 0
  22. --平台标识
  23. self.plat_name = ClientConfig.plat_name
  24. --登陆状态
  25. self.login_state = false
  26. --上次请求充值时间
  27. self.last_pay_request_time = 0
  28. --上次发送角色等级时间
  29. self.last_sent_role_level_time = os.time()
  30. --SDK登陆服务器验证函数
  31. self.login_method_name = "check_login_" .. string.gsub(self.plat_name, "_alpha", "")
  32. ClientConfig.source_plat_name = ClientConfig.plat_name
  33. self.can_send_voice = false --语音权限
  34. self:InitOperTypeValue()
  35. end
  36. function GamePlatform:SDKCallBack( func_name, func_data)
  37. if func_name == "LoginRequest" then
  38. self.wait_login_call_back = false
  39. GlobalEventSystem:Fire(EventName.HIDE_LOADING_VIEW)
  40. self:LoginCallBack(func_data)
  41. elseif func_name == "PayRequest" then
  42. self:PayCallBack(func_data)
  43. elseif func_name == "LoginOut" then
  44. ClientConfig.login_token = nil
  45. self:LoginOutCallBack(func_data)
  46. elseif func_name == "RequestAudioPermission" then
  47. self:OnRequestAudioPermission(func_data)
  48. elseif func_name == "ScreenShot" then
  49. self:ScreenShotBack(func_data)
  50. end
  51. end
  52. function GamePlatform:ScreenShotBack(data)
  53. if data then
  54. local out_data = data
  55. if type(data) == "string" then
  56. out_data = JsonToTable(data)
  57. end
  58. if out_data and out_data.name then
  59. local png_path = "phone/"..out_data.name..".png"
  60. local save_path = Util.DataPath..png_path
  61. if SystemRuntimePlatform.IsAndroid() then
  62. local game_path = "luaFramework/"
  63. save_path = game_path..png_path
  64. end
  65. if UnityEngine and UnityEngine.ScreenCapture then
  66. UnityEngine.ScreenCapture.CaptureScreenshot(save_path)
  67. end
  68. self:CallStringFunc("ScreenShotPath", {path = save_path})
  69. end
  70. end
  71. end
  72. function GamePlatform:CallStringFunc(func,value)
  73. return SDKUtil.CallStringFunc( "SDKPlatform", func, value)
  74. end
  75. function GamePlatform:InitWindow()
  76. PlatformSetting:getInstance():Init(self)
  77. end
  78. function GamePlatform:InitSDK()
  79. end
  80. function GamePlatform:LoginRequest(login_back)
  81. ClientConfig.login_token = nil
  82. local cur_time = os.time()
  83. if cur_time - self.last_login_time < 3 then
  84. return
  85. end
  86. self.last_login_time = cur_time
  87. self.login_callback = login_back
  88. local login_data = {}
  89. local login_func = function()
  90. self:CallSDKMethod("LoginRequest",login_data)
  91. GlobalEventSystem:Fire(EventName.SHOW_LOADING_VIEW)
  92. self.wait_login_call_back = true
  93. local hide_func = function()
  94. if self.wait_login_call_back then
  95. GlobalEventSystem:Fire(EventName.HIDE_LOADING_VIEW)
  96. end
  97. end
  98. setTimeout(hide_func,3)
  99. end
  100. if self.login_state then
  101. self.login_state = false
  102. self:CallSDKMethod("LoginOut",login_data)
  103. setTimeout(login_func, 0.5)
  104. else
  105. login_func()
  106. end
  107. end
  108. function GamePlatform:SetLoginCallBack(login_back)
  109. self.login_callback = login_back
  110. end
  111. function GamePlatform:LoginCallBack( data )
  112. if data then
  113. local login_data = data
  114. if type(data) == "string" then
  115. login_data = JsonToTable(data)
  116. end
  117. if login_data then
  118. if login_data.paramstr then
  119. login_data.paramstr = UrlEncode(login_data.paramstr) --阻止非法字符问题
  120. end
  121. if login_data.uid then
  122. if login_data.token then
  123. ClientConfig.login_token = login_data.token
  124. end
  125. self.uid = login_data.uid or 0
  126. if login_data.sdk_channel and login_data.sdk_channel ~= "" then
  127. self.checkChannel = login_data.sdk_channel
  128. ClientConfig.source_plat_name = ClientConfig.plat_name .. "_" .. self.checkChannel
  129. Debugger.Log("source_plat_name " .. ClientConfig.source_plat_name)
  130. else
  131. self.channel_id = (login_data.sdk_channel or login_data.channel) or login_data.login_channel
  132. if self.channel_id then
  133. self.channel_id = ClientConfig.plat_name .. "_" .. self.channel_id
  134. end
  135. end
  136. local server_check = function( state, error, data )
  137. if state then
  138. local login_data = JsonToTable(data)
  139. if login_data and tonumber(login_data["ret"]) == 0 then
  140. if login_data.token then
  141. ClientConfig.login_token = login_data.token
  142. end
  143. if login_data.uid then --覆盖掉上面的赋值
  144. self.uid = login_data.uid
  145. end
  146. if login_data.sdk_channel and login_data.sdk_channel ~= "" then
  147. self.checkChannel = login_data.sdk_channel
  148. ClientConfig.source_plat_name = ClientConfig.plat_name .. "_" .. self.checkChannel
  149. Debugger.Log("source_plat_name " .. ClientConfig.source_plat_name)
  150. end
  151. if self.login_callback then
  152. self.login_callback( self.uid )
  153. self.login_callback = nil
  154. LoginModel:getInstance().no_login_state = false
  155. end
  156. self.login_state = true
  157. return
  158. end
  159. end
  160. local function ok()
  161. Application.Quit()
  162. end
  163. Alert.show("登陆验证失败,请退出游戏再次进入",Alert.Type.One,ok)
  164. end
  165. self.login_param = {
  166. paramstr = login_data.paramstr or "{}",
  167. }
  168. self:TryCheckLogin( server_check )
  169. if login_data.get_pay_state and tonumber(login_data.get_pay_state) == 1 then
  170. self:GetServerPayState()
  171. end
  172. return
  173. else
  174. local server_check = function(state, error, data)
  175. if state then
  176. local login_data = JsonToTable(data)
  177. if login_data and tonumber(login_data["ret"]) == 0 then
  178. self.uid = login_data.uid or "0"
  179. if login_data.token then
  180. ClientConfig.login_token = login_data.token
  181. end
  182. if login_data.sdk_channel and login_data.sdk_channel ~= "" then
  183. self.checkChannel = login_data.sdk_channel
  184. ClientConfig.source_plat_name = ClientConfig.plat_name .. "_" .. self.checkChannel
  185. Debugger.Log("source_plat_name " .. ClientConfig.source_plat_name)
  186. end
  187. if self.login_callback then
  188. self.login_callback( self.uid )
  189. self.login_callback = nil
  190. LoginModel:getInstance().no_login_state = false
  191. end
  192. self.login_state = true
  193. return
  194. end
  195. end
  196. local function ok()
  197. Application.Quit()
  198. end
  199. Alert.show("登陆验证失败,请退出游戏再次进入",Alert.Type.One,ok)
  200. end
  201. self.check_login = nil
  202. self.login_param = nil
  203. if login_data.checkLogin and tonumber(login_data.checkLogin) == 1 then
  204. self.login_param = {
  205. paramstr = login_data.paramstr or "{}",
  206. }
  207. self:TryCheckLogin( server_check )
  208. end
  209. if login_data.get_pay_state and tonumber(login_data.get_pay_state) == 1 then
  210. self:GetServerPayState()
  211. end
  212. return
  213. end
  214. end
  215. end
  216. Message.show("登陆失败,请重新尝试")
  217. end
  218. function GamePlatform:TryCheckLogin(check_back)
  219. if not self.login_param then
  220. check_back()
  221. else
  222. local callback = function(state, error, data)
  223. self.wait_checklogin_call_back = false
  224. GlobalEventSystem:Fire(EventName.HIDE_LOADING_VIEW)
  225. check_back(state, error, data)
  226. end
  227. local now_time = os.time()
  228. local now_method = self.login_method_name
  229. local now_sign = string.lower(Util.md5(ClientConfig.login_key .. now_time .. now_method))
  230. self.login_param["method"] = now_method
  231. self.login_param["time"] = now_time
  232. self.login_param["sign"] = now_sign
  233. self.login_param["site"] = ClientConfig.plat_name
  234. HttpUtil.HttpGetRequest(ClientConfig.login_php, self.login_param, callback)
  235. GlobalEventSystem:Fire(EventName.SHOW_LOADING_VIEW)
  236. self.wait_checklogin_call_back = true
  237. local hide_func = function()
  238. if self.wait_checklogin_call_back then
  239. GlobalEventSystem:Fire(EventName.HIDE_LOADING_VIEW)
  240. end
  241. end
  242. setTimeout(hide_func,3)
  243. end
  244. end
  245. function GamePlatform:LoginOut()
  246. self.login_state = false --避免多次调用登出接口
  247. self:CallSDKMethod("LoginOut","")
  248. end
  249. function GamePlatform:PayRequest( custom_money, custom_info, custom_callpack )
  250. local cur_time = os.time()
  251. if cur_time - self.last_pay_request_time < 2 then
  252. return
  253. end
  254. self.last_pay_request_time = cur_time
  255. self:PayStart(custom_money * 10, custom_info, custom_callpack)
  256. --TA订单请求打点
  257. local product_id = custom_info.id
  258. local product_cfg = product_id and Config.Rechargeproduct[product_id]
  259. if product_cfg then
  260. local data = {
  261. event_name = "order_init",
  262. currency = "RMB",
  263. pay_amount = tonumber(custom_money) or 0,
  264. pay_item_type = tostring(product_cfg.product_type) or "",
  265. pay_sub_type = tostring(product_cfg.product_subtype) or "",
  266. pay_item_id = tostring(product_id) or "",
  267. pay_item = custom_info.pay_title or "",
  268. is_quick = custom_info.recharge_type and custom_info.recharge_type == 1 or false
  269. }
  270. self:TATrack(data)
  271. end
  272. end
  273. function GamePlatform:PayStart(custom_money, custom_info, custom_callpack)
  274. local server_role = self:ServerRole(custom_info.id or 0)
  275. local random = math.random(100,999)
  276. local role_info = RoleManager.Instance.mainRoleInfo
  277. local playerInfo = LoginController.Instance:GetPlatUserInfo()
  278. local real_plat = string.gsub(self.plat_name, "_alpha", "")
  279. local pay_callback_url = ClientConfig.url_account_path .. "api/pay.php?plat=suyou&platname=".. real_plat
  280. local notify_url_str = ClientConfig.url_account_path .. "api/pay.php?plat=".. real_plat
  281. local notify_url_post_str = ClientConfig.url_account_path .. "api/pay/".. real_plat .. ".php"
  282. local now_order_num = server_role .. "-" .. self.uid .. "-" .. os.time() .. random .. "-" .. self.plat_name
  283. local pay_data = {
  284. pay_money = tostring(custom_money) or 0,
  285. product_id = tostring(custom_info.id),
  286. product_name = custom_info.pay_title or "",
  287. user_id = self.uid,
  288. order_num = now_order_num,
  289. pay_suyou_notify_url = pay_callback_url,
  290. notify_url = notify_url_str,
  291. notify_url_post = notify_url_post_str,
  292. role_id = tostring(role_info.role_id),
  293. role_name = role_info.name,
  294. role_level = tostring(role_info.level),
  295. real_server = tostring(playerInfo.server_id),
  296. server_name = playerInfo.server_name,
  297. pay_state = self.use_web_pay_state or 0,
  298. balance = tostring(role_info.jin),
  299. vip = tostring(role_info.vip_flag),
  300. }
  301. local plat_name = ClientConfig.product_plat or string.gsub(ClientConfig.plat_name, "_alpha", "")
  302. local index = plat_name .. "@" .. pay_data["product_id"]
  303. if Config.Appstroeproduct then
  304. local product_info = Config.Appstroeproduct[index]
  305. if product_info then
  306. pay_data["appstore_product_id"] = Trim(product_info.product) or 0
  307. else
  308. pay_data["appstore_product_id"] = ""
  309. pay_data["appstore_product_id_1"] = plat_name .. (pay_data["pay_money"]/10)
  310. pay_data["appstore_product_id_2"] = plat_name .. (pay_data["pay_money"]*10)
  311. pay_data["appstore_product_id_3"] = plat_name .. (pay_data["pay_money"])
  312. end
  313. end
  314. self:CallSDKMethod("PayRequest",pay_data)
  315. self.pay_callback = custom_callpack
  316. end
  317. function GamePlatform:GetServerPayState()
  318. --向后台获取充值方式
  319. local func_callback = function(state, error, data)
  320. if state then
  321. local login_data = JsonToTable(data)
  322. if login_data and tonumber(login_data["ret"]) == 0 then
  323. local pay_code = tonumber(login_data["data"])
  324. if pay_code ~= 0 and pay_code ~= -1 then
  325. self.use_web_pay_state = pay_code
  326. end
  327. end
  328. end
  329. end
  330. local now_time = os.time()
  331. local now_method = "check_webpay_status"
  332. local now_sign = string.lower(Util.md5(ClientConfig.login_key .. now_time .. now_method))
  333. local get_param = {
  334. method = now_method,
  335. time = now_time,
  336. sign = now_sign,
  337. platform = ClientConfig.plat_name,
  338. lv = 0,
  339. }
  340. HttpUtil.HttpGetRequest(ClientConfig.login_php, get_param, func_callback)
  341. end
  342. function GamePlatform:ServerRole(product_id)
  343. local playerInfo = LoginController.Instance:GetPlatUserInfo()
  344. local role_info = RoleManager.Instance.mainRoleInfo
  345. if not playerInfo or not role_info then
  346. return ""
  347. end
  348. local server_role = playerInfo.server_id .. "gzsy" .. role_info.role_id .. "gzsy" .. product_id
  349. return server_role
  350. end
  351. function GamePlatform:PayCallBack( data )
  352. if self.pay_callback then
  353. self.pay_callback(true)
  354. self.pay_callback = nil
  355. end
  356. end
  357. function GamePlatform:LoginOutCallBack(data)
  358. if data then
  359. local out_data = data
  360. if type(data) == "string" then
  361. out_data = JsonToTable(data)
  362. end
  363. if out_data and out_data.noLogin and tonumber(out_data.noLogin) == 1 then
  364. LoginModel:getInstance().no_login_state = tonumber(out_data.noLogin)
  365. end
  366. end
  367. GlobalEventSystem:Fire(EventName.CHANGE_ACCOUNT)
  368. end
  369. function GamePlatform:CallSDKMethod(func_name, info)
  370. SDKUtil.CallSDKFunc( "SDKPlatform", func_name, info )
  371. end
  372. function GamePlatform:CallBoolFunc(value_name)
  373. return SDKUtil.CallBoolFunc( "SDKPlatform", value_name, "" )
  374. end
  375. function GamePlatform:CallIntFunc(value_name, func_data)
  376. if func_data == nil then
  377. func_data = ""
  378. end
  379. return SDKUtil.CallIntFunc("SDKPlatform", value_name, func_data)
  380. end
  381. function GamePlatform:ShowUserCenter()
  382. self:CallSDKMethod("ShowUserCenter","")
  383. end
  384. function GamePlatform:ExitPlatform()
  385. if self:NeedCustomExitGame() then
  386. self:CallSDKMethod("SDKExit","")
  387. end
  388. self:SubmitExtendData(self.exit_game_type)
  389. end
  390. function GamePlatform:CustonPayParam()
  391. end
  392. function GamePlatform:NeedCustomExitGame()
  393. return self.custom_exit_game
  394. end
  395. function GamePlatform:SubmitCreateRoleInfo(role_id)
  396. self:SubmitExtendData(self.create_role_type,tostring(role_id),"1")
  397. end
  398. function GamePlatform:RoleLevelChange(new_level)
  399. if os.time() - self.last_sent_role_level_time < 30 then
  400. return
  401. end
  402. self.last_sent_role_level_time = os.time()
  403. self:SubmitExtendData(self.role_levelup_type)
  404. end
  405. function GamePlatform:SubmitEnterGame()
  406. self:SubmitExtendData(self.gointo_game_type)
  407. end
  408. function GamePlatform:SubmitSelectServer()
  409. self:SubmitExtendData(self.select_server_type)
  410. end
  411. function GamePlatform:SubmitExtendData( now_type,role_id,role_lv )
  412. if not RoleManager or not RoleManager.Instance then
  413. return
  414. end
  415. local playerInfo = LoginController.Instance:GetPlatUserInfo()
  416. local role_info = RoleManager.Instance.mainRoleInfo
  417. local cur_role_name = role_info.name
  418. if cur_role_name == "" or now_type == self.create_role_type then
  419. cur_role_name = playerInfo.role_name or ""
  420. end
  421. local extend_data = {
  422. type = now_type,
  423. role_id = role_id or tostring(role_info.role_id),
  424. role_name = cur_role_name,
  425. role_level = role_lv or tostring(role_info.level),
  426. real_server = tostring(playerInfo.server_id),
  427. server_name = playerInfo.server_name,
  428. balance = tostring(role_info.jin),
  429. vip = tostring(role_info.vip_flag),
  430. reg_time = tostring(playerInfo.create_time or os.time()),
  431. user_id = self.uid,
  432. --兼容老版本
  433. uid = self.uid,
  434. server = tostring(playerInfo.server_id),
  435. roleCTime = tostring(playerInfo.create_time or os.time()),
  436. serverNanme = playerInfo.server_name,
  437. time = os.time(),
  438. }
  439. self:CallSDKMethod("SubmitExtendData",extend_data)
  440. end
  441. function GamePlatform:InitOperTypeValue()
  442. self.select_server_type = 101
  443. self.create_role_type = 102
  444. self.gointo_game_type = 103
  445. self.role_levelup_type = 104
  446. self.exit_game_type = 105
  447. end
  448. function GamePlatform:GetUserID()
  449. return self.uid
  450. end
  451. function GamePlatform:ShareBySDK()
  452. local share_data = {}
  453. self:CallSDKMethod("ShareBySDK", share_data)
  454. end
  455. function GamePlatform:SuyouEventRecord( event_id )
  456. -- local url = "http://mqapi.suyougame.com/point/mrzj"
  457. -- local secretKey = "9A22E32CA2CFF5282F614F84138437F6"
  458. -- local cur_time = tostring(os.time())
  459. -- local post_param = {
  460. -- type = event_id,
  461. -- source = ClientConfig.plat_name,
  462. -- deviceId = LoginModel:getInstance().devece_id,
  463. -- startTime = LoginModel:getInstance().first_setup_time,
  464. -- time = cur_time,
  465. -- sign = "",
  466. -- }
  467. -- 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))
  468. -- local call_func = function(ret,error_msg,data)
  469. -- end
  470. -- HttpUtil.HttpPostRequest(url, post_param, call_func)
  471. end
  472. function GamePlatform:RequestAudioPermission( )
  473. local share_data = {}
  474. self:CallSDKMethod("RequestAudioPermission", share_data)
  475. end
  476. function GamePlatform:IsNeedRequestAudioPermission( )
  477. -- local is_need_permission = self:CallIntFunc("RequestAudioPermission")
  478. -- return is_need_permission
  479. end
  480. function GamePlatform:OnRequestAudioPermission( data )
  481. if data then
  482. local out_data = data
  483. self.can_send_voice = false
  484. -- Debugger.Log("OnRequestAudioPermission out_data:" .. out_data)
  485. if out_data and tonumber(out_data) == 1 then
  486. self.can_send_voice = true
  487. end
  488. GlobalEventSystem:Bind(EventName.UPDATE_VOICE_AUTH, self.can_send_voice)
  489. end
  490. end
  491. function GamePlatform:CanSendVoice( )
  492. return self.can_send_voice
  493. end
  494. function GamePlatform:DeleteMe()
  495. end
  496. --ta打点额外数据
  497. function GamePlatform:SubmitSpecialData( parm_type, parm_value )
  498. local share_data = {type = parm_type, value = parm_value}
  499. self:CallSDKMethod("SubmitSpecialData", share_data)
  500. end
  501. --ta打点数据上报,参数{event_name = str, key1 = value1, key2 = value2 ...}
  502. function GamePlatform:TATrack( data )
  503. self:CallSDKMethod("TATrack", data)
  504. end