public string GetQrCodeImageUrl(string res)
{
JObject obj = (JObject)JsonConvert.DeserializeObject(res);
string JGDM = obj["data"]["JGDM"].ToString();
string GetUrl = "http://baidu/";//定义
string msg = "";
Enterprises model = EnterprisesService.GetEnterprisesByJGDm(JGDM);
if (model != null)
{
try
{
string path = Server.MapPath("/Ent/XCXQrCode/" + model.OrganizationCode + ".jpg");
if (!File.Exists(path))
{
// string key = "";
string tempPath = Server.MapPath("/Ent/XCXQrCode/");
if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
//else DeleteFolder(tempPath);
string url = GetUrl+"Ent/QrCodeMsg.aspx?JGDM=" + model.OrganizationCode + "&EnterpriseName=" + model.EnterpriseName+ "";
string logopath = Server.MapPath("/Images/QrCodelogo.png");//中间log
string ImagePath = QRCodeHelper.CreateQRCode_ByLogo("/Ent/XCXQrCode/", url, logopath);//保存文件路径、二维码内容、logo路径
msg = ImagePath;
string SavePath_f = tempPath + ImagePath.Replace("/Ent/XCXQrCode/", "");
System.Drawing.Image img = System.Drawing.Image.FromFile(SavePath_f);
Bitmap bmp = new Bitmap(img.Width + 60, img.Height + 80);
Graphics g = Graphics.FromImage(bmp);
Brush bush_bj = new SolidBrush(Color.White);
g.FillRectangle(bush_bj, new Rectangle(0, 0, img.Width + 60, img.Height + 120));
Rectangle rec = new Rectangle();
rec.Height = img.Height;
rec.Width = img.Width;
rec.X = 30;
rec.Y = 35;
g.DrawImage(img, rec);
Font myFont = new Font("宋体", 12, FontStyle.Bold);
Brush bush = new SolidBrush(Color.Black);
Rectangle frec = new Rectangle();
frec.Height = 25;
frec.Width = img.Width;
frec.X = 50;
frec.Y = 10;
g.DrawString(" ", myFont, bush, frec);
Font myFont1 = new Font("宋体", 10, FontStyle.Regular);
Rectangle frecd = new Rectangle();
frecd.Height = 50;
frecd.Width = img.Width;
frecd.X = 20;
frecd.Y = img.Height + 40;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
g.DrawString(model.EnterpriseName, myFont1, bush, frecd, sf);
string SavePath_s = model.OrganizationCode + ".jpg";//图片保存到文件夹下
bmp.Save(tempPath + SavePath_s);
msg = GetUrl + "/Ent/XCXQrCode/" + SavePath_s;
}
else
{
msg = GetUrl + "/Ent/XCXQrCode/" + model.OrganizationCode + ".jpg";
}
}
catch (Exception ex)
{
msg = "该二维码未生成!";
}
}
else { msg = "该二维码未生成!"; }
return JsonConvert.SerializeObject(msg);
}