public async Task <string> GetWxQrCodeAsync(string appId, string secret, string scene, string path, int width = 430) { var key = KeyForOther($"File:Qrcode:{path}_{scene}_{width}"); var fileUrl = await Database.StringGetAsync(key); if (!fileUrl.IsNull) { return(fileUrl.ToString()); } var token = await GetWxAccessTokenAsync(appId, secret); var result = await WeixinHelper.CreateQRCodeAsync(token, scene, path, width); if (result.Code > 0) { throw new Exception($"小程序二维码请求错误,{result.Message}"); } var filename = Guid.NewGuid().ToString().ToLower() + ".jpg"; var dir = Path.Combine(Environment.CurrentDirectory, "wwwroot", "qrcode"); Directory.CreateDirectory(dir); var filepath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "qrcode", filename); using (var file = new FileStream(filepath, FileMode.Create, FileAccess.Write)) { file.Write(result.Result, 0, result.Result.Length); } var url = $"{AppSetting.Setting.FileDomain}/qrcode/{filename}"; await Database.StringSetAsync(key, url); return(url); }