Example #1
0
        public async Task <IActionResult> ContentWxAppletQrCode([FromBody] ContentPlayBillModel info)
        {
            CommonResult      result            = new CommonResult();
            YuebonCacheHelper yuebonCacheHelper = new YuebonCacheHelper();

            try
            {
                if (info == null)
                {
                    return(ToJsonContent(result));
                }
                string page  = info.Page;   //此接口不可以带参数,如果需要加参数,必须加到scene中
                string scene = info.Scene;; //id=xxxxxx,scene最多允许32个字符
                int    width = string.IsNullOrEmpty(info.Width.ToString()) ? 480 : info.Width.ToInt();

                //图片名称
                string picname       = "ref" + width + GuidUtils.CreateNo() + ".png";
                var    _tempfilepath = "/upload/contentqrcode/";
                var    uploadPath    = _filePath + _tempfilepath;
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                string       qrcodePicPath = uploadPath + picname;//小程序二维码图片
                MemoryStream ms            = new MemoryStream();
                if (!System.IO.File.Exists(qrcodePicPath))
                {
                    var resultImg = await WxAppApi.GetWxaCodeUnlimitAsync(WxOpenAppId, qrcodePicPath, scene, page, width, false, null, true);

                    if (resultImg.errcode == ReturnCode.请求成功)
                    {
                        result.Success = true;
                        result.ErrCode = ErrCode.successCode;
                        result.ResData = _tempfilepath + picname;
                    }
                    else
                    {
                        result.ErrCode = resultImg.errcode.ToString();
                        result.ErrMsg  = resultImg.errmsg;
                    }
                }
                else
                {
                    result.ErrCode = ErrCode.successCode;
                    result.ErrMsg  = _tempfilepath + picname;
                }
            }
            catch (Exception ex)
            {
                Log4NetHelper.Error("代码生成异常", ex);
                result.ErrMsg  = "代码生成异常:" + ex.Message;
                result.ErrCode = ErrCode.failCode;
            }
            return(ToJsonContent(result));
        }
Example #2
0
        public async Task <IActionResult> ContentWxAppletQrCodeRes([FromQuery] ContentPlayBillModel info)
        {
            CommonResult      result            = new CommonResult();
            YuebonCacheHelper yuebonCacheHelper = new YuebonCacheHelper();
            MemoryStream      ms = new MemoryStream();

            try
            {
                if (info == null)
                {
                    return(ToJsonContent(result));
                }
                string page      = info.Page;   //此接口不可以带参数,如果需要加参数,必须加到scene中
                string scene     = info.Scene;; //id=xxxxxx,scene最多允许32个字符
                int    width     = string.IsNullOrEmpty(info.Width.ToString()) ? 480 : info.Width.ToInt();
                var    resultImg = await WxAppApi.GetWxaCodeUnlimitAsync(WxOpenAppId, ms, scene, page, width);

                ms.Position = 0;
                if (resultImg.errcode == ReturnCode.请求成功)
                {
                    var imgBase64 = Convert.ToBase64String(ms.GetBuffer());
                    result.Success = true;
                    result.ErrCode = ErrCode.successCode;
                    result.ResData = imgBase64;
                }
                else
                {
                    result.ErrCode = resultImg.errcode.ToString();
                    result.ErrMsg  = resultImg.errmsg;
                }
            }
            catch (Exception ex)
            {
                Log4NetHelper.Error("代码生成异常", ex);
                result.ErrMsg  = "代码生成异常:" + ex.Message;
                result.ErrCode = ErrCode.failCode;
            }
            finally{
                ms.Dispose();
            }
            return(ToJsonContent(result));
        }
Example #3
0
        public async Task <IActionResult> ContentPlayBillQrCode(ContentPlayBillModel info)
        {
            CommonResult      result            = new CommonResult();
            YuebonCacheHelper yuebonCacheHelper = new YuebonCacheHelper();
            MemoryStream      ms = new MemoryStream();

            try
            {
                if (info == null)
                {
                    return(ToJsonContent(result));
                }
                string page  = info.Page;   //此接口不可以带参数,如果需要加参数,必须加到scene中
                string scene = info.Scene;; //id=xxxxxx,scene最多允许32个字符

                //图片名称
                string picname       = "ref_" + GuidUtils.CreateNo() + ".jpg";
                var    _tempfilepath = "/upload/" + scene + "/contentqrcode/";
                var    uploadPath    = _filePath + _tempfilepath;
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                string qrcodePicPath = uploadPath + picname;//小程序二维码图片
                var    resultImg     = await WxAppApi.GetWxaCodeUnlimitAsync(WxOpenAppId, qrcodePicPath, scene, page, 280);

                if (resultImg.errcode == ReturnCode.请求成功)
                {
                    string picnameh = "c_" + GuidUtils.CreateNo() + ".jpg";
                    var    sor      = _filePath + "/images/";
                    string qrcodebg = "share_content_bg.jpg";

                    Bitmap   cardbmp = new Bitmap(460, 736);
                    Graphics g       = Graphics.FromImage(cardbmp);
                    g.SmoothingMode      = SmoothingMode.HighQuality;; //抗锯齿
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode  = InterpolationMode.High;
                    g.Clear(System.Drawing.Color.White); //白色填充

                    Bitmap bgimg = new Bitmap(460, 736);
                    //如果背景图片存在,
                    bgimg = (Bitmap)Image.FromFile(qrcodebg); //如果存在,读取背景图片
                    g.DrawImage(bgimg, 0, 0, 460, 736);
                    //合成二维码
                    Bitmap productImg = new Bitmap(128, 128);
                    productImg = (Bitmap)Image.FromFile(qrcodePicPath);
                    g.DrawImage(productImg, 276, 580, 128, 128);
                    //合成文字
                    Font nickName = new Font("微软雅黑", 22);
                    Font adtxt    = new Font("微软雅黑", 18);

                    StringFormat stringFormat = new StringFormat(StringFormatFlags.DisplayFormatControl);
                    Brush        fontBrush    = SystemBrushes.ControlText;
                    stringFormat.Alignment     = StringAlignment.Center;
                    stringFormat.LineAlignment = StringAlignment.Center;
                    RectangleF rectangleF = new RectangleF(40, 500, 380, 80);
                    g.DrawString(info.Title, adtxt, fontBrush, rectangleF, stringFormat);
                    cardbmp.Save(uploadPath + picnameh, ImageFormat.Jpeg);
                    cardbmp.Dispose();
                    ms.Dispose();

                    result.ResData = _tempfilepath + picnameh;
                }
                else
                {
                    result.ErrCode = resultImg.errcode.ToString();
                    result.ErrMsg  = resultImg.errmsg;
                }
            }
            catch (Exception ex)
            {
                Log4NetHelper.Error("代码生成异常", ex);
                result.ErrMsg  = "代码生成异常:" + ex.Message;
                result.ErrCode = ErrCode.failCode;
            }
            finally
            {
                ms.Dispose();
            }
            return(ToJsonContent(result));
        }