From 44a7f35c999b7a6c37e8e41258af5440785f03c9 Mon Sep 17 00:00:00 2001 From: wtp <1813748440@qq.com> Date: Tue, 28 Nov 2023 20:11:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=B7=E6=8A=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GDZZ.Application/Enum/SystemConst.cs | 8 ++++++ GDZZ.Application/Help/CacheService.cs | 18 +++++++++++++ GDZZ.Application/Help/ICacheService.cs | 16 +++++++++++ GDZZ.Application/Service/Auth/AuthService.cs | 27 ++++++++++++++++--- .../Service/WXPay/WXPayService.cs | 5 ++-- GDZZ.Web.Entry/GDZZ.Web.Entry.csproj | 1 + 6 files changed, 70 insertions(+), 5 deletions(-) diff --git a/GDZZ.Application/Enum/SystemConst.cs b/GDZZ.Application/Enum/SystemConst.cs index 0cba508..4527e7a 100644 --- a/GDZZ.Application/Enum/SystemConst.cs +++ b/GDZZ.Application/Enum/SystemConst.cs @@ -50,5 +50,13 @@ namespace GDZZ.Application /// public const string MINI_ACCESSTOKEN = "AccessToken:"; #endregion + + #region 二维码 + + /// + /// 二维码生成 + /// + public const string MINI_QRCODE = "QRCode:"; + #endregion } } diff --git a/GDZZ.Application/Help/CacheService.cs b/GDZZ.Application/Help/CacheService.cs index fd6ac4f..29fe629 100644 --- a/GDZZ.Application/Help/CacheService.cs +++ b/GDZZ.Application/Help/CacheService.cs @@ -173,6 +173,24 @@ namespace GDZZ.Application.Help } + + + #endregion + + + #region 二维码 + + public async Task GetQRCodeAsync(long UserID) + { + string cacheKey = SystemConst.MINI_QRCODE + $"{UserID}"; + return await _redisCache.GetAsync(cacheKey); + } + + public async Task SetQRCodeAsync(long UserID,string Url) + { + string cacheKey = SystemConst.MINI_QRCODE+$"{UserID}"; + await _redisCache.SetAsync(cacheKey, Url); + } #endregion } } diff --git a/GDZZ.Application/Help/ICacheService.cs b/GDZZ.Application/Help/ICacheService.cs index 2d1131b..afab3e7 100644 --- a/GDZZ.Application/Help/ICacheService.cs +++ b/GDZZ.Application/Help/ICacheService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace GDZZ.Application.Help { @@ -72,7 +73,22 @@ namespace GDZZ.Application.Help #endregion + #region 二维码生成 + /// + /// 存储二维码bate[] + /// + /// + Task GetQRCodeAsync(long UserID); + + /// + /// 存储二维码bate[] + /// + /// + Task SetQRCodeAsync(long UserID, string Url); + + + #endregion } } diff --git a/GDZZ.Application/Service/Auth/AuthService.cs b/GDZZ.Application/Service/Auth/AuthService.cs index 3395a39..9d3e36d 100644 --- a/GDZZ.Application/Service/Auth/AuthService.cs +++ b/GDZZ.Application/Service/Auth/AuthService.cs @@ -20,6 +20,9 @@ using Mapster; using GDZZ.Core.Service; using TencentCloud.Sms.V20210111.Models; using TencentCloud.Common; +using Polly; +using System.IO; +using System.Diagnostics.Eventing.Reader; namespace GDZZ.Application.Service.Auth { @@ -493,6 +496,10 @@ namespace GDZZ.Application.Service.Auth [HttpGet("/Mini/GetShareCode")] public async Task GetShareCode(string scene, string page) { + + var url = await this.cacheService.GetQRCodeAsync(UserManager.UserId); + if(url != null) + return url; var value = await cacheService.GetAccessTokenAsync(); if (value == null) { @@ -500,9 +507,23 @@ namespace GDZZ.Application.Service.Auth await cacheService.SetAccessTokenAsync(token.Result.AccessToken); value = token.Result.AccessToken; } - var res = await this._wechatOAuth.GetShareCodeAsync(value,scene, page); - - return Convert.ToBase64String(res); + var res = await this._wechatOAuth.GetShareCodeAsync(value,scene, page); + var fileName = Path.Combine(App.WebHostEnvironment.WebRootPath+ UserManager.UserId + "_" + DateTime.Now + "png"); + Console.WriteLine(fileName); + try + { + MemoryStream ms = new MemoryStream(res); + FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate); + ms.WriteTo(fs); + ms.Close(); + fs.Close(); + await this.cacheService.SetQRCodeAsync(UserManager.UserId, fileName); + } + catch (Exception e) + { + throw Oops.Oh(e.Message); + } + return fileName; } diff --git a/GDZZ.Application/Service/WXPay/WXPayService.cs b/GDZZ.Application/Service/WXPay/WXPayService.cs index d826190..998541d 100644 --- a/GDZZ.Application/Service/WXPay/WXPayService.cs +++ b/GDZZ.Application/Service/WXPay/WXPayService.cs @@ -40,11 +40,9 @@ namespace GDZZ.Application.Service.WXPay private readonly SqlSugarRepository self; //职业仓储 private readonly SqlSugarRepository ComsumeRep; //消费记录仓储 private readonly SqlSugarRepository balance; //余额仓储 - private readonly SqlSugarRepository rechargeRep; //充值仓储 private readonly SqlSugarRepository payTakeRep; //支付仓储 private readonly SqlSugarRepository refundRep; //退款仓储 - private readonly WechatOAuth _wechatOAuth; //微信权限服务 private readonly IHttpContextAccessor _httpContextAccessor; //http服务 @@ -425,6 +423,9 @@ namespace GDZZ.Application.Service.WXPay [Route("Mini/v1/GetBalance")] public async Task MerchantTransfer(TransferInput wxRefundInput) { + + + throw Oops.Oh("参数错误"); } #endregion diff --git a/GDZZ.Web.Entry/GDZZ.Web.Entry.csproj b/GDZZ.Web.Entry/GDZZ.Web.Entry.csproj index 5beeb18..b16d1cd 100644 --- a/GDZZ.Web.Entry/GDZZ.Web.Entry.csproj +++ b/GDZZ.Web.Entry/GDZZ.Web.Entry.csproj @@ -89,6 +89,7 @@ +