/// <summary> /// 海报1 /// </summary> /// <param name="openid"></param> /// <returns></returns> public OAauth_Log SeadSeaNews(OAauth_Log oa) { string img = "/assets/img/bottom.jpg"; img = Server.MapPath(img); string headimg = "/wechat/spa/image/logo.jpg"; string qrimg = "/wechat/spa/image/logo.jpg"; if (oa != null) { if (string.IsNullOrEmpty(oa.Ticket)) //如果没有生成过邀请二维码,则生成一个。 { string jason = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + (oa.ID + 10000) + "}}}"; //oa的id增加一万 string resMessage = WeiPage.HttpXmlPostRequest("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + Token(mjuserid), jason, Encoding.UTF8); string[] a = resMessage.Split('\"'); if (a.Length > 3) { oa.Ticket = Server.UrlEncode(a[3]); DownQRImage(oa.Ticket); qrimg = "/wechat/QRImage/" + oa.Ticket + ".jpg"; } } else { qrimg = "/wechat/QRImage/" + oa.Ticket + ".jpg"; } qrimg = Server.MapPath(qrimg); if (!string.IsNullOrEmpty(oa.DownPic)) { headimg = oa.DownPic; } else if (!string.IsNullOrEmpty(oa.headimgurl)) { string down = DownHeadImage(oa); if (!string.IsNullOrEmpty(down)) { headimg = down; } } headimg = Server.MapPath(headimg); string img2 = @"E:\ASPNETTempFiles\seanews\"; if (!System.IO.Directory.Exists(img2)) { Directory.CreateDirectory(img2); } oa.SeaImg = Guid.NewGuid().ToString(); img2 += oa.SeaImg + ".jpg"; if (File.Exists(img) && File.Exists(headimg) && File.Exists(qrimg)) { ImageWriter iw = new ImageWriter(); System.Drawing.Bitmap bm = new System.Drawing.Bitmap(headimg); System.Drawing.Image newImage = CutEllipse(bm, new Rectangle(0, 0, bm.Width, bm.Height), new Size(200, 200)); iw.SaveWatermark(new System.Drawing.Bitmap(img), (Bitmap)newImage, ImageWriter.WatermarkPosition.LeftTop, 90, 70, new System.Drawing.Bitmap(qrimg), ImageWriter.WatermarkPosition.LeftBottom, 220, 50, img2, oa.Nickname);; // f.FILE_NAME, Server.MapPath("~/assets/images/shuiyin.png"), Server.MapPath("~/assets/images/shuiyin2.png"), Server.MapPath("~/assets/images/shuiyin3.png"), 0.3f, ImageWriter.WatermarkPosition.Center, 10, f.FILE_NAME); } if (File.Exists(img2)) { List <string> imglist = new List <string>(); imglist.Add(img2); string a = HttpUploadFile("https://api.weixin.qq.com/cgi-bin/media/upload?access_token=" + Token(mjuserid) + "&type=image", "图片", "application/x-jpg", new System.Collections.Specialized.NameValueCollection { }, imglist); Rootobject root = JsonConvert.DeserializeObject <Rootobject>(a); if (root.media_id != null) { oa.MEDIA_ID = root.media_id; oa.MEDIA_Time = DateTime.Now.AddDays(3).AddHours(-2); mss.SaveOA(oa); return(oa); } } } return(oa); }
/// <summary> /// 佰草集邀请海报1 /// </summary> /// <param name="openid"></param> /// <returns></returns> public string SeadSeaNews_BCJ(string openid, int SeaSource) { string img = "/assets/img/poster.jpg"; img = Server.MapPath(img); string headimg = "/wechat/spa/image/logo.jpg"; string qrimg = "/wechat/spa/image/logo.jpg"; OAauth_Log oa = mss.GetOA(openid); if (oa != null) { if (!oa.SeaSource.HasValue) { oa.SeaSource = SeaSource; } if (!string.IsNullOrEmpty(oa.MEDIA_ID) && oa.MEDIA_Time.HasValue && oa.MEDIA_Time > DateTime.Now) { return(oa.MEDIA_ID); //如果已有海报,并且未过期,则直接返回之前的海报。 } if (string.IsNullOrEmpty(oa.Ticket)) //如果没有生成过邀请二维码,则生成一个。 { //string access_token = w.Token(w.mjuserid); string jason = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + (oa.ID + 10000) + "}}}"; //oa的id增加一万 string resMessage = WeiPage.HttpXmlPostRequest("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + Token(mjuserid), jason, Encoding.UTF8); string[] a = resMessage.Split('\"'); if (a.Length > 3) { oa.Ticket = Server.UrlEncode(a[3]); DownQRImage(oa.Ticket); qrimg = "/wechat/QRImage/" + oa.Ticket + ".jpg"; } } else { qrimg = "/wechat/QRImage/" + oa.Ticket + ".jpg"; } qrimg = Server.MapPath(qrimg); if (!string.IsNullOrEmpty(oa.DownPic)) { headimg = oa.DownPic; } else if (!string.IsNullOrEmpty(oa.headimgurl)) { string down = DownHeadImage(oa); if (!string.IsNullOrEmpty(down)) { headimg = down; } } headimg = Server.MapPath(headimg); string img2 = @"D:\ASPNETTempFiles\seanews\"; if (!System.IO.Directory.Exists(img2)) { Directory.CreateDirectory(img2); } oa.SeaImg = Guid.NewGuid().ToString(); img2 += oa.SeaImg + ".jpg"; if (File.Exists(img) && File.Exists(headimg) && File.Exists(qrimg)) { ImageWriter iw = new ImageWriter(); System.Drawing.Bitmap bm = new System.Drawing.Bitmap(headimg); System.Drawing.Image newImage = CutEllipse(bm, new Rectangle(0, 0, bm.Width, bm.Height), new Size(200, 200)); using (Image image = Image.FromFile(img)) { if (IsPixelFormatIndexed(image.PixelFormat)) { Bitmap bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(bmp)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.DrawImage(image, 0, 0); } iw.SaveWatermark(bmp, (Bitmap)newImage, ImageWriter.WatermarkPosition.LeftTop, 120, 120, new System.Drawing.Bitmap(qrimg), ImageWriter.WatermarkPosition.LeftBottom, 130, 30, img2, oa.Nickname);; // f.FILE_NAME, Server.MapPath("~/assets/images/shuiyin.png"), Server.MapPath("~/assets/images/shuiyin2.png"), Server.MapPath("~/assets/images/shuiyin3.png"), 0.3f, ImageWriter.WatermarkPosition.Center, 10, f.FILE_NAME); } else { iw.SaveWatermark(new System.Drawing.Bitmap(img), (Bitmap)newImage, ImageWriter.WatermarkPosition.LeftTop, 120, 120, new System.Drawing.Bitmap(qrimg), ImageWriter.WatermarkPosition.LeftBottom, 130, 30, img2, oa.Nickname); }; // f.FILE_NAME, Server.MapPath("~/assets/images/shuiyin.png"), Server.MapPath("~/assets/images/shuiyin2.png"), Server.MapPath("~/assets/images/shuiyin3.png"), 0.3f, ImageWriter.WatermarkPosition.Center, 10, f.FILE_NAME); } } if (File.Exists(img2)) { List <string> imglist = new List <string>(); imglist.Add(img2); string a = HttpUploadFile("https://api.weixin.qq.com/cgi-bin/media/upload?access_token=" + Token(mjuserid) + "&type=image", "图片", "application/x-jpg", new System.Collections.Specialized.NameValueCollection { }, imglist); Rootobject root = JsonConvert.DeserializeObject <Rootobject>(a); if (root.media_id != null) { oa.MEDIA_ID = root.media_id; oa.MEDIA_Time = DateTime.Now.AddDays(3).AddHours(-2); mss.SaveOA(oa); return(root.media_id); // string message = @"{ // ""touser"":""{0}"", // ""msgtype"":""image"", // ""image"": // { // ""media_id"":""{1}"" // } //}"; // message = message.Replace("{0}", oa.FromUserName).Replace("{1}", root.media_id); // string Access_token = Token(mjuserid); // var postUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + Access_token; // string d = message; // //d = d.Replace("{0}", "oS7pm1iNL2P2pjdgHO3xC2NRdWE8").Replace("{1}", Message); // string resMessage = HttpXmlPostRequest(postUrl, d, Encoding.UTF8); } } } return("err"); }
public void SeadSeaNews(string openid) { string img = "/assets/img/bottom.jpg"; img = Server.MapPath(img); string headimg = "/wechat/spa/image/logo.jpg"; OAauth_Log oa = mss.GetOA(openid); if (oa != null) { if (!string.IsNullOrEmpty(oa.DownPic)) { headimg = oa.DownPic; } else if (!string.IsNullOrEmpty(oa.headimgurl)) { string down = DownHeadImage(oa); if (!string.IsNullOrEmpty(down)) { headimg = down; } } headimg = @"D:\小时光POS系统" + headimg.Replace("~", ""); string img2 = @"D:\ASPNETTempFiles\seanews\"; if (!System.IO.Directory.Exists(img2)) { Directory.CreateDirectory(img2); } img2 += Guid.NewGuid() + ".jpg"; if (File.Exists(img) && File.Exists(headimg)) { ImageWriter iw = new ImageWriter(); iw.SaveWatermark(new System.Drawing.Bitmap(img), new System.Drawing.Bitmap(headimg), ImageWriter.WatermarkPosition.Top, 50, img2);// f.FILE_NAME, Server.MapPath("~/assets/images/shuiyin.png"), Server.MapPath("~/assets/images/shuiyin2.png"), Server.MapPath("~/assets/images/shuiyin3.png"), 0.3f, ImageWriter.WatermarkPosition.Center, 10, f.FILE_NAME); } if (File.Exists(img2)) { List <string> imglist = new List <string>(); imglist.Add(img2); string a = HttpUploadFile("https://api.weixin.qq.com/cgi-bin/media/upload?access_token=" + Token(mjuserid) + "&type=image", "图片", "application/x-jpg", new System.Collections.Specialized.NameValueCollection { }, imglist); Rootobject root = JsonConvert.DeserializeObject <Rootobject>(a); if (root.media_id != null) { string message = @"{ ""touser"":""{0}"", ""msgtype"":""image"", ""image"": { ""media_id"":""{1}"" } }"; message = message.Replace("{0}", oa.FromUserName).Replace("{1}", root.media_id); string Access_token = Token(mjuserid); var postUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + Access_token; string d = message; //d = d.Replace("{0}", "oS7pm1iNL2P2pjdgHO3xC2NRdWE8").Replace("{1}", Message); string resMessage = HttpXmlPostRequest(postUrl, d, Encoding.UTF8); //Response.Write(resMessage); } } } }