コード例 #1
0
        public IActionResult OnPostQRGen(double payAmount, int courseTime = 0)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                var           url      = $"{Request.Scheme}://{Request.Host}/WX/PayQRMoney?amt={payAmount}&ct={courseTime}";
                var           fileName = $"{payAmount}_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.png";
                var           savePath = EduEnviroment.DicPath_QRPay + fileName;
                List <string> desc     = new List <string>();
                desc.Add($"请用户扫码付款,支付金额【{payAmount}】元");
                if (courseTime > 0)
                {
                    desc.Add($"共计: 【{courseTime}】节课时");
                }
                QRHelper.GenQR(url, savePath, desc);
                result.SuccessMsg = EduEnviroment.VirPath_QRPay + fileName;
            }
            catch (Exception ex)
            {
                result.ErrorMsg = "生成失败:" + ex.Message;
                NLogHelper.ErrorTxt($"二维码生成失败:{ex.Message}");
            }
            return(new JsonResult(result));
        }
コード例 #2
0
        public IActionResult OnPostCreateLessonQR(ELessonQR qr)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                var code = EduCodeGenerator.Tool_LessonQRCode();
                var url  = $"http://edu.iqianba.cn/Tools/QRScan?code={code}";
                qr.Code           = code;
                qr.CreateDateTime = DateTime.Now;
                string filePath = EduEnviroment.DicPath_Tools_LessonQR + $"{code}.png";
                qr.QRFilePath = EduEnviroment.VirPath_Tools_LessonQR + $"{code}_logo.png";

                string filePathWithLogo = EduEnviroment.DicPath_Tools_LessonQR + $"{code}_logo.png";

                var desc = new List <string>();
                if (!string.IsNullOrEmpty(qr.Name))
                {
                    desc.Add(qr.Name);
                }

                QRHelper.GenQR(url, filePath, desc);
                var logoUrl = "http://edu.iqianba.cn/images/logo_120.png";

                QRHelper.AddLogoForQR(logoUrl, new Bitmap(filePath), filePathWithLogo);

                _ToolsSrv.AddQR(qr);
                _ToolsSrv.SaveChanges();

                result.SuccessMsg = qr.QRFilePath;
            }
            catch (Exception ex)
            {
                result.ErrorMsg = ex.Message;
            }
            return(new JsonResult(result));
        }