示例#1
0
        private string CreateQrCode(string fileImg, string replaceUrl)
        {
            string qrCode = "";

            try
            {
                //网络图片读取
                WebClient mywebclient = new WebClient();
                var       imgfile     = mywebclient.DownloadData(fileImg);

                var qRCodeWithIconDto = new Jinher.JAP.BaseApp.Tools.Deploy.CustomDTO.QRCodeWithIconDTO
                {
                    IconDate = imgfile,
                    Source   = replaceUrl
                };

                //生成带图片的二维码
                var codepath = TPS.BaseAppToolsSV.Instance.GenQRCodeWithIcon(qRCodeWithIconDto);
                qrCode = CustomConfig.CommonFileServerUrl + codepath;
            }
            catch (Exception ex)
            {
                //string errStack = ex.Message + ex.StackTrace;
                //while (ex.InnerException != null)
                //{
                //    errStack += ex.InnerException.Message + ex.InnerException.StackTrace;
                //    ex = ex.InnerException;
                //}
                //LogHelper.Error("CreateQrCode异常,异常信息:" + errStack, ex);
                //系统默认生成的不带图片的二维码
                string codepath = BaseAppToolsSV.Instance.GenQRCode(replaceUrl);
                qrCode = CustomConfig.CommonFileServerUrl + codepath;
            }
            return(qrCode);
        }
示例#2
0
        /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="fileImg">临时图片名称,可以空</param>
        /// <param name="replaceUrl">要构建二维码的推广码的短地址</param>
        /// <param name="pictype">是否上传图片;2:上传自定义图片</param>
        /// <returns></returns>
        public static string GenerateImgTwoCode(string fileImg, string replaceUrl, int pictype)
        {
            string twodimcodeimg = "";

            try
            {
                //用户自已上传图片生成链接图片
                if (pictype == 2)
                {
                    //将图片的文件转换成二进制流
                    //string pServer = HttpContext.Server.MapPath("~/TempImage/" + fileImg);

                    //将网络图片保存在本地
                    //string saveFile = Guid.NewGuid().ToString() + Path.GetExtension(fileImg).ToLower();
                    //string pServer = GetPath() + "\\" + saveFile;
                    //getimages(fileImg, GetPath(), saveFile);

                    //本地图片读取
                    Byte[] imgfile = Jinher.AMP.EBC.Common.ImageHelper.ConvertFileToBinary(fileImg);
                    Jinher.JAP.BaseApp.Tools.Deploy.CustomDTO.QRCodeWithIconDTO qRDTO = new Jinher.JAP.BaseApp.Tools.Deploy.CustomDTO.QRCodeWithIconDTO();
                    qRDTO.IconDate = imgfile;
                    qRDTO.Source   = replaceUrl;

                    //生成带图片的二维码
                    string codepath = Jinher.AMP.BTP.TPS.BaseAppToolsSV.Instance.GenQRCodeWithIcon(qRDTO);
                    twodimcodeimg = Jinher.AMP.BTP.Common.CustomConfig.CommonFileServerUrl + codepath;

                    //删除本地图片
                    System.IO.File.Delete(fileImg);
                }
                else
                {
                    //系统默认生成的不带图片的二维码
                    string codepath = Jinher.AMP.BTP.TPS.BaseAppToolsSV.Instance.GenQRCode(replaceUrl);
                    twodimcodeimg = Jinher.AMP.BTP.Common.CustomConfig.CommonFileServerUrl + codepath;
                }
            }
            catch (System.Exception ex)
            {
                string errStack = ex.Message + ex.StackTrace;
                while (ex.InnerException != null)
                {
                    errStack += ex.InnerException.Message + ex.InnerException.StackTrace;
                    ex        = ex.InnerException;
                }
                LogHelper.Error(string.Format("生成二维码异常。fileImg:{0},replaceUrl:{1},pictype:{2}", fileImg, replaceUrl, pictype), ex);
            }
            return(twodimcodeimg);
        }