示例#1
0
        //二维码

        public AbstractResponse GetQRCodeResponse(string openId)
        {
            //判断是否注册
            if (!MemberProcessor.IsExitOpenId(openId))
            {
                TextResponse response = new TextResponse
                {
                    CreateTime = DateTime.Now,
                    Content    = "您购买后系统会自动生成您的推广二维码海报."
                };
                return(response);
            }

            Hidistro.Entities.Members.MemberInfo member = MemberProcessor.GetMembers(openId);
            DistributorsInfo info = DistributorsBrower.GetUserIdDistributors(member.UserId);

            if (info == null)
            {
                TextResponse response = new TextResponse
                {
                    CreateTime = DateTime.Now,
                    Content    = "您购买后系统会自动生成您的推广二维码海报."
                };
                return(response);
            }

            ImageResponse imgResponse = new ImageResponse()
            {
                CreateTime = DateTime.Now,
                Image      = new Hishop.Weixin.MP.Domain.Image()
            };

            SiteSettings masterSettings = SettingsManager.GetMasterSettings(true);

            //生成二维码图片
            string sApplicationPath = System.Web.HttpContext.Current.Request.MapPath("/Templates/vshop/default/images/qrcode/");

            string qr_code = sApplicationPath + @"/QRCodeBg.jpg";

            string qr_code_name = sApplicationPath + @"/tmp/QRCode_" + info.UserId + ".jpg";                                                     //二维码图片
            string qr_code_bg   = sApplicationPath + @"/tmp/QRCode_bg_" + info.UserId + ".jpg";                                                  //拼接后的图片
            string link         = "http://" + System.Web.HttpContext.Current.Request.Url.Host + "/vshop/Default.aspx?ReferralId=" + info.UserId; //二维码链接

            if (!File.Exists(qr_code_name))
            {
                //生成二维码名片
                string code_url = TokenApi.CreateQRCode(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, info.UserId);

                //下载二维码
                Utils.HttpHelper helper = new Utils.HttpHelper();
                helper.DownloadFiles(code_url, qr_code_name);

                //头像图片
                string img_logo_src = System.Web.HttpContext.Current.Request.MapPath("/") + info.Logo;   //拼接后的图片
                Bitmap img_logo     = new Bitmap(img_logo_src);

                //拼接
                File.Copy(qr_code, qr_code_bg, false);

                Bitmap newImg = new Bitmap(qr_code);

                Graphics g = Graphics.FromImage(newImg);

                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //下面这个也设成高质量
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                //下面这个设成High
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

                System.Drawing.Image erweima = new Bitmap(qr_code_name);
                g.DrawImage(erweima, 158, 430, 204, 204);   //画二维码

                g.DrawImage(img_logo, 35, 26, 77, 77);      //画头像

                //我是...
                SolidBrush drawBrush  = new SolidBrush(Color.Red);
                SolidBrush drawBrush2 = new SolidBrush(Color.Black);

                Font drawFont = new Font("Arial", 16, FontStyle.Regular, GraphicsUnit.Pixel);

                MemberGradeInfo memberGrade = MemberProcessor.GetMemberGrade(member.GradeId);
                string          str         = member.UserName + " (" + memberGrade.Name + ")";
                string          str2        = info.StoreName + " 代言";

                g.DrawString("我是 ", drawFont, drawBrush2, 140, 50);
                g.DrawString(str, drawFont, drawBrush, 180, 50);

                g.DrawString("我为 ", drawFont, drawBrush2, 140, 75);
                g.DrawString(str2, drawFont, drawBrush, 180, 75);

                g.Dispose();
                newImg.Save(qr_code_bg);
            }

            //Utils.LogWriter.SaveLog("素材图片:" + qr_code_bg);

            //上传素材
            imgResponse.Image.MediaId = TokenApi.AddNews(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, qr_code_bg);
            //Utils.LogWriter.SaveLog("上传素材ID:" + imgResponse.Image.MediaId);

            return(imgResponse);
        }