Update x gen URL redirect siti
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using ZXing;
|
||||
using ZXing.QrCode;
|
||||
@@ -8,6 +9,14 @@ namespace QR_GEN.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Struct x richiesta serializzata/deserializzata
|
||||
/// </summary>
|
||||
public struct qrRequest
|
||||
{
|
||||
public string valore;
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
@@ -29,6 +38,16 @@ namespace QR_GEN.Controllers
|
||||
{
|
||||
id = "www.steamware.net";
|
||||
}
|
||||
#if false
|
||||
// se arriva modo json --> deserializzo
|
||||
if (id.IndexOf("{") >= 0)
|
||||
{
|
||||
var richiesta = JsonConvert.DeserializeObject<qrRequest>(id);
|
||||
id = richiesta.valore;
|
||||
}
|
||||
#endif
|
||||
// url decode...
|
||||
id = HttpUtility.UrlDecode(id);
|
||||
// creo!
|
||||
QrCodeEncodingOptions options = new QrCodeEncodingOptions
|
||||
{
|
||||
@@ -44,6 +63,64 @@ namespace QR_GEN.Controllers
|
||||
// scrivo bitmap
|
||||
var pixelData = writer.Write(id);
|
||||
|
||||
// Return Image
|
||||
MemoryStream ms = new MemoryStream();
|
||||
pixelData.Save(ms, ImageFormat.Png);
|
||||
ms.Position = 0;
|
||||
return new FileStreamResult(ms, "image/png");
|
||||
}
|
||||
/// <summary>
|
||||
/// Restituisce un QR code dato valore
|
||||
/// </summary>
|
||||
/// <param name="id">id x impostare SITO x jumper</param>
|
||||
/// <param name="val">valore delle opzioni da embeddare</param>
|
||||
/// <returns></returns>
|
||||
public ActionResult QR_site(string id, string val)
|
||||
{
|
||||
string cmdArg = "";
|
||||
// se vuoto stea,ware...
|
||||
if (id == null || id == "")
|
||||
{
|
||||
cmdArg = "www.steamware.net";
|
||||
}
|
||||
#if false
|
||||
// se arriva modo json --> deserializzo
|
||||
if (id.IndexOf("{") >= 0)
|
||||
{
|
||||
var richiesta = JsonConvert.DeserializeObject<qrRequest>(id);
|
||||
id = richiesta.valore;
|
||||
}
|
||||
#endif
|
||||
#if false
|
||||
// url decode...
|
||||
id = HttpUtility.UrlDecode(id);
|
||||
#endif
|
||||
string tgtUrl = "";
|
||||
// in base a richiesta compongo stringa ...
|
||||
switch (id)
|
||||
{
|
||||
case "CTRACK_ELET_SCAL":
|
||||
tgtUrl = @"ctrack.steamware.net/elet-scal/jumper?USER_NAME=info@elettronicascalvina.it&UserAuthkey=asdfbqhewrqg7802345bhasdfg78&CodOpr=";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cmdArg = string.Format("{0}{1}", tgtUrl, val);
|
||||
// creo!
|
||||
QrCodeEncodingOptions options = new QrCodeEncodingOptions
|
||||
{
|
||||
DisableECI = true,
|
||||
CharacterSet = "UTF-8",
|
||||
Width = 600,
|
||||
Height = 600,
|
||||
Margin = 0
|
||||
};
|
||||
var writer = new BarcodeWriter();
|
||||
writer.Format = BarcodeFormat.QR_CODE;
|
||||
writer.Options = options;
|
||||
// scrivo bitmap
|
||||
var pixelData = writer.Write(cmdArg);
|
||||
|
||||
// Return Image
|
||||
MemoryStream ms = new MemoryStream();
|
||||
pixelData.Save(ms, ImageFormat.Png);
|
||||
|
||||
Reference in New Issue
Block a user