From 81794c24d23f824b159bfab92416fbe4e1f023a6 Mon Sep 17 00:00:00 2001 From: zpc Date: Sun, 22 Dec 2024 16:56:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appsettings.Development.json | 2 +- .../CloudGaming.Web/Pages/Handle/Index.cshtml | 11 ++++-- .../Pages/Handle/Index.cshtml.cs | 6 ++++ .../Api/CloudGaming.Web/Program.cs | 34 +++++++------------ .../wwwroot/js/JYConnection.js | 9 ++--- .../Code/CloudGaming.Code/Contract/IJYApi.cs | 4 +-- .../Code/CloudGaming.Code/Game/PlayGameBLL.cs | 8 ++--- .../JY/JYRequestCommonParameter.cs | 8 +++++ 8 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/CloudGaming/Api/CloudGaming.Api/appsettings.Development.json b/src/CloudGaming/Api/CloudGaming.Api/appsettings.Development.json index ba883d4..c7ca56c 100644 --- a/src/CloudGaming/Api/CloudGaming.Api/appsettings.Development.json +++ b/src/CloudGaming/Api/CloudGaming.Api/appsettings.Development.json @@ -10,7 +10,7 @@ "secret": "95BB717C61D1ECB0E9FB82C932CC77FF", "nodes": "http://124.220.55.158:94", //多个节点使用逗号分隔 "url": "http://124.220.55.158:94", - "env": "TEST", + "env": "PROD", "UserName": "admin", "Password": "dbt@com@1234" }, diff --git a/src/CloudGaming/Api/CloudGaming.Web/Pages/Handle/Index.cshtml b/src/CloudGaming/Api/CloudGaming.Web/Pages/Handle/Index.cshtml index f22c1d3..c30982b 100644 --- a/src/CloudGaming/Api/CloudGaming.Web/Pages/Handle/Index.cshtml +++ b/src/CloudGaming/Api/CloudGaming.Web/Pages/Handle/Index.cshtml @@ -288,7 +288,7 @@ $jy.channelId ='@(Model.AppConfig?.GameConfig?.ChannelId ?? "")'; $jy.token = ''; $jy.ip = '@(Model.IP)'; - $jy.sn ='@(Guid.NewGuid().ToString("N"))'; + $jy.sn ='@(Model.Sn)'; $jy.gameId = gameId; $jy.clientSid = userId; @@ -626,7 +626,7 @@ //window.close(); } - function start() { + async function start() { try { WeixinJSBridge.call('hideOptionMenu'); //隐藏右上角三个点按钮。 WeixinJSBridge.call('hideAllNonBaseMenuItem'); //隐藏所有非基础按钮接口。 @@ -648,6 +648,13 @@ $("#joystick2").on("touchmove", joystickMove2); $("#joystick2").on("touchend", joystickEnd2); //配置(客户端) + var token= await $.get("@(Model.AppConfig?.Site?.Api ?? "")/api/PlayGame/GetToken?userId=@(Model.UserId)&sn=@(Model.Sn)"); + console.log("tokentokentokentokentokentoken", token.data); + if(token==null||token.data==null||token.data.token==null){ + alert("初始化失败!请刷新页面重试!!!"); + return ; + } + $jy.token = token.data.token; initGame(); setTimeout(function() { try { diff --git a/src/CloudGaming/Api/CloudGaming.Web/Pages/Handle/Index.cshtml.cs b/src/CloudGaming/Api/CloudGaming.Web/Pages/Handle/Index.cshtml.cs index 6334845..236200a 100644 --- a/src/CloudGaming/Api/CloudGaming.Web/Pages/Handle/Index.cshtml.cs +++ b/src/CloudGaming/Api/CloudGaming.Web/Pages/Handle/Index.cshtml.cs @@ -33,12 +33,18 @@ public class IndexModel : PageModel /// /// public string IP { get; set; } + + /// + /// + /// + public string Sn { get; set; } /// /// app配置 /// public AppConfig AppConfig { get; set; } public void OnGet(string identifier, int userId, string gameId) { + Sn = Guid.NewGuid().ToString("N"); this.GameId = gameId; this.UserId = userId; if (string.IsNullOrEmpty(identifier)) diff --git a/src/CloudGaming/Api/CloudGaming.Web/Program.cs b/src/CloudGaming/Api/CloudGaming.Web/Program.cs index 0398780..c292bab 100644 --- a/src/CloudGaming/Api/CloudGaming.Web/Program.cs +++ b/src/CloudGaming/Api/CloudGaming.Web/Program.cs @@ -67,30 +67,22 @@ app.UseAuthorization(); app.MapRazorPages(); app.MapGet("/qrcode/{identifier}/{userId}/{gameId}.png", async (string identifier, int userId, string gameId, IServiceProvider serviceProvider, IHttpContextAccessor httpContextAccessor) => { - string qrcodeContent = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host.ToString()}/handle/{identifier}/{userId}/{gameId}.html"; - //if (!string.IsNullOrEmpty(identifier)) - //{ - // if (identifier.ToLower() == "cloudgaming") - // { - // identifier = "default"; - // } - // var app = AppConfigurationExtend.GetAppConfigIdentifier(identifier); - // if (app != null) - // { - // var appConfig = serviceProvider.GetRequiredService(); - // app.ToAppConfig(appConfig); - // CloudGamingBase cloudGamingBase = new CloudGamingBase(serviceProvider); - // var gameInfo = await PlayGameExtend.GetPlayGameUserInfoOrNull(cloudGamingBase, userId, gameId); - // if (gameInfo != null) - // { - // qrcodeContent += $"/handle/{identifier}/{userId}/{gameId}"; - // } - // } - - //} + if (!string.IsNullOrEmpty(identifier)) + { + if (identifier.ToLower() == "cloudgaming") + { + identifier = "default"; + } + var app = AppConfigurationExtend.GetAppConfigIdentifier(identifier); + if (app != null) + { + qrcodeContent = $"{app.Site.Web}/handle/{identifier}/{userId}/{gameId}.html"; + } + + } // 创建一个 QRCodeGenerator 实例 var qrGenerator = new QRCodeGenerator(); diff --git a/src/CloudGaming/Api/CloudGaming.Web/wwwroot/js/JYConnection.js b/src/CloudGaming/Api/CloudGaming.Web/wwwroot/js/JYConnection.js index 1ad698c..7c1237d 100644 --- a/src/CloudGaming/Api/CloudGaming.Web/wwwroot/js/JYConnection.js +++ b/src/CloudGaming/Api/CloudGaming.Web/wwwroot/js/JYConnection.js @@ -27,12 +27,13 @@ JYConnection.prototype.setTagID = function (tagID) { */ JYConnection.prototype.initSdk = function () { //sdk初始化 + console.log(this.channelId, this.bsUrl, this.token, this.sn, this.callback); this.jy.sdkLoading(this.channelId, this.bsUrl, this.token, this.sn, this.callback); }; - - /** - * 停止游戏 - */ + +/** +* 停止游戏 +*/ JYConnection.prototype.stop = function () { //停止游戏 this.jy.stop(); diff --git a/src/CloudGaming/Code/CloudGaming.Code/Contract/IJYApi.cs b/src/CloudGaming/Code/CloudGaming.Code/Contract/IJYApi.cs index d8b477b..623ab18 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Contract/IJYApi.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Contract/IJYApi.cs @@ -87,9 +87,9 @@ namespace CloudGaming.Code.Contract /// - /// 查看自己的会话列表 + /// /// - /// + /// /// [Post("/jyapi/myScList")] Task> MyScList([Body(BodySerializationMethod.UrlEncoded)] JYRequestParameter parameter); diff --git a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs index acf993d..7449016 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Game/PlayGameBLL.cs @@ -643,11 +643,9 @@ public class PlayGameBLL : CloudGamingBase { throw MessageBox.ErrorShow("未找到游戏信息"); } - JYRequestCommonParameter playGameCommonSetting = new JYRequestCommonParameter() + JYRequestCommonParameter playGameCommonSetting = new JYRequestCommonParameter(sn,userId) { ScId = gameInfoCache.ScId, - Sn = sn, - ClientSid = $"{userId}", Ip = this.HttpContextAccessor.HttpContext.GetClientIpAddress() }; var dic = await JYApi.CreateSimpleHandler(playGameCommonSetting); @@ -676,7 +674,9 @@ public class PlayGameBLL : CloudGamingBase } GameSettingDto gameSettingDto = new GameSettingDto() { - HandleQrCode = $"{AppConfig.Site.Web}/qrcode/{AppConfig.Identifier}/{_UserId}/{gameId}.png" + //HandleQrCode = $"{AppConfig.Site.Web}/qrcode/{AppConfig.Identifier}/{_UserId}/{gameId}.png" + HandleQrCode = $"{AppConfig.Site.Web}/handle/{AppConfig.Identifier}/{_UserId}/{gameId}.html" + }; return gameSettingDto; } diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/JY/JYRequestCommonParameter.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/JY/JYRequestCommonParameter.cs index 5becc77..a4a1462 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/JY/JYRequestCommonParameter.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/JY/JYRequestCommonParameter.cs @@ -12,6 +12,14 @@ namespace CloudGaming.DtoModel.JY; /// public class JYRequestCommonParameter : JYRequestParameter { + public JYRequestCommonParameter(string sn, string clientSid) : base(sn, clientSid) + { + + } + public JYRequestCommonParameter(string sn, int userId) : base(sn, userId) + { + + } /// /// 本次游戏连接会话 id ///