public ActionResult QrCode(string Img) { // Server.MapPath("") 或者 Server.MapPath("~/") try { Img = Img.Replace("data:image/png;base64,", ""); var basePath = Server.MapPath("~/"); string directoryPath = basePath + "/Resource/QRCodFile/H5Scan/" + DateTime.Now.ToString("yyyy-MM-dd"); string fileName = string.Format("{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), new Random().Next(1000, 10000)); string savePath = string.Empty; if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } savePath = directoryPath + "/" + fileName + ".png"; FileStream fs = System.IO.File.Create(savePath); byte[] bytes = Convert.FromBase64String(Img); fs.Write(bytes, 0, bytes.Length); fs.Close(); fs.Dispose(); return(Content(ZXingNetHelper.ReadQrCode(savePath))); } catch (Exception ex) { return(Content(ex.Message)); } }
public ActionResult UpdateSignQRCode(string keyValue, int state = 0) { string imgurl = ""; if (state == 0) { string newday = DateTime.Now.ToString("yyyy-MM-dd"); string host = Request.Url.ToString(); host = host.Replace(Request.RawUrl, ""); string text = string.Format("{0}?key={1}", sys.Util.Config.GetValue("MeetingQRCodUrl"), keyValue); string virtualPath = string.Format("~/Resource/QRCodFile/{0}/", newday); string fullFileName = this.Server.MapPath(virtualPath); string fileName = ZXingNetHelper.GenerateLogoQrCode(text, fullFileName); imgurl = string.Format("{0}/Resource/QRCodFile/{1}/{2}", host, newday, fileName); } meetingBLL.UpdateSignQRCode(keyValue, imgurl); return(Success("操作成功。")); }