예제 #1
0
        public async Task <IActionResult> DownloadMchQRCode()
        {
            string activityNo = this.GetActivityNo();

            var(mchList, total) = await _operatApplication.MchList(activityNo, "", 1, 1000);

            if (total <= 0)
            {
                return(BadRequest("未找到商户!"));
            }

            string dateName = DateTime.Now.ToString("yyyyMMddHHmmss");
            string filePath = $"{_hostingEnvironment.WebRootPath}/Image/Wish/{dateName}/";

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            foreach (var data in mchList)
            {
                string path = $@"pages/conversion/index?mchNo={data.mchNo}";

                await WxAppApi.GetWxaCodeAsync(_wxOpenAppId, string.Concat(filePath, data.mchName, ".jpeg"), path);
            }

            string zipPath     = $"/File/Wish/";
            string zipPathName = $"{zipPath}{dateName}.zip";
            string zipPathDir  = _hostingEnvironment.WebRootPath + zipPath;

            if (!Directory.Exists(zipPathDir))
            {
                Directory.CreateDirectory(zipPathDir);
            }
            try
            {
                ZipFile.CreateFromDirectory(filePath, $"{_hostingEnvironment.WebRootPath}{zipPathName}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(BadRequest("压缩错误 !"));
            }

            if (Directory.Exists(filePath))
            {
                Directory.Delete(filePath, true);
            }

            return(File(zipPathName, "application/zip", $"商户核销码-{dateName}.zip"));
        }
예제 #2
0
        public async Task <IActionResult> GetQRCode(string path)
        {
            //var memberId = this.GetMemberId();
            ////Console.WriteLine("memberId=={1} path1:{0}", path, memberId);
            //var stream = new MemoryStream();
            //path = HttpUtility.UrlDecode(path);
            ////Console.WriteLine("memberId=={1} path2:{0}", path, memberId);
            //await WxAppApi.GetWxaCodeAsync(_wxOpenAppId, stream, path);
            ////必须将流的当前位置置0,否则将引发异常
            ////如果不设置为0,则流的当前位置在流的末端,然后读流就会从末端开始读取,就会引发无效操作异常System.InvalidOperationException
            ////System.InvalidOperationException: Response Content-Length mismatch: too few bytes written (0 of xxxx)
            //stream.Position = 0;
            //return new FileStreamResult(stream, "image/gif");

            path = HttpUtility.UrlDecode(path);
            using (var ms = new MemoryStream())
            {
                await WxAppApi.GetWxaCodeAsync(_wxOpenAppId, ms, path);

                return(File(ms.GetBuffer(), "image/jpeg"));
            }
        }