生成扫描跳转到指定页面并带有参数的二维码

后台处理(WAPSplittinRule.cs)

using Hidistro.Core;

str3 = Globals.HostPath(HttpContext.Current.Request.Url) + "/Wapshop/ReferralAgreement.aspx?ReferralUserId=" + referraluserid.ToNullString();
this.userReferralQRCode.ImageUrl = "/api/VshopProcess.ashx?action=GenerateTwoDimensionalImage&url=" + str3;

第一行:拼接跳转地址和参数的字符串

第二行:调用异步生成二维码并把上面的地址、参数拼接进去

异步生成二维码(Vshopprocess.cs)

using Hidistro.Core;
using System.IO;
System.Drawing;using ThoughtWorks.QRCode.Codec;
 
  

private void GenerateTwoDimensionalImage(HttpContext context)
        {
            string str = Globals.HtmlDecode(context.Request["url"].ToString());
            if (!string.IsNullOrEmpty(str))
            {
                MemoryStream stream = Globals.GenerateTwoDimensionalImage(str);
                context.Response.ClearContent();
                context.Response.ContentType = "image/Jpeg";
                context.Response.BinaryWrite(stream.ToArray());
                context.Response.End();
            }
        }
public static MemoryStream GenerateTwoDimensionalImage(string url)
        {
            Bitmap bitmap = new QRCodeEncoder { QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE, QRCodeScale = 10, QRCodeVersion = 0, QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M }.Encode(url);
            MemoryStream stream = new MemoryStream();
            bitmap.Save(stream, ImageFormat.Png);
            return stream;
        }




你可能感兴趣的:(生成扫描跳转到指定页面并带有参数的二维码)