国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - C# - C#生成帶二維碼的專屬微信公眾號推廣海報實例代碼

C#生成帶二維碼的專屬微信公眾號推廣海報實例代碼

2022-03-06 13:31指間人生 C#

這篇文章主要給大家介紹了關于利用C#如何生成帶二維碼的專屬微信公眾號推廣海報的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們一起來看看吧

前言

很多微信公眾號中需要生成推廣海報的功能,粉絲獲得專屬海報后可以分享到朋友圈或發(fā)給朋友,為公眾號代言邀請好友即可獲取獎勵的。海報自帶渠道二維碼,粉絲長按二維碼即可關注微信公眾號,從而達到吸粉的目的。

效果如下:

C#生成帶二維碼的專屬微信公眾號推廣海報實例代碼

代碼實現(xiàn):

1.獲取臨時二維碼ticket

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/// <summary>
/// 獲取臨時二維碼ticket
/// </summary>
/// <param name="scene_str">場景值id openid做場景值id</param>
/// <returns></returns>
public static string createtempqrcode(string scene_str,string access_token)
{
 var result = httputility.sendposthttprequest($"https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={access_token}", "application/json", "{\"expire_seconds\": 2592000, \"action_name\": \"qr_str_scene\", \"action_info\": {\"scene\": {\"scene_str\": \"" + scene_str + "\"}}}");
 
 jobject jobect = (jobject)jsonconvert.deserializeobject(result);
 
 string ticket = (string)jobect["ticket"];
 
 if (string.isnullorempty(ticket))
 {
  loghelper.writelog(typeof(weixinhelper), "獲取臨時二維碼ticket失敗" + result);
  return null;
 }
 return ticket;
}

使用openid作為場景值的好處是通過掃a推廣的二維碼關注用戶的場景值便是a的openid。

2. 生成帶二維碼的專屬推廣圖片

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/// <summary>
/// 生成帶二維碼的專屬推廣圖片
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
public string draw(wxuser user)
{
 //背景圖片
 string path = server.mappath("/content/images/tg.jpg");
 
 system.drawing.image imgsrc = system.drawing.image.fromfile(path);
 
 //處理二維碼圖片大小 240*240px
 system.drawing.image qrcodeimage = reduceimage("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+user.ticket, 240, 240);
 
 //處理頭像圖片大小 100*100px
 image titleimage = reduceimage(user.headimgurl, 100, 100);
 
 using (graphics g = graphics.fromimage(imgsrc))
 {
  //畫專屬推廣二維碼
  g.drawimage(qrcodeimage, new rectangle(imgsrc.width - qrcodeimage.width - 200,
  imgsrc.height - qrcodeimage.height - 200,
  qrcodeimage.width,
  qrcodeimage.height),
  0, 0, qrcodeimage.width, qrcodeimage.height, graphicsunit.pixel);
 
  //畫頭像
  g.drawimage(titleimage, 8, 8, titleimage.width, titleimage.height);
 
  font font = new font("宋體", 30, fontstyle.bold);
 
  g.drawstring(user.nickname, font, new solidbrush(color.red), 110, 10);
 }
 string newpath = server.mappath(@"/content/images/newtg_" + guid.newguid().tostring() + ".jpg");
 imgsrc.save(newpath, system.drawing.imaging.imageformat.jpeg);
 return newpath;
}
 
 
/// <summary>
/// 縮小/放大圖片
/// </summary>
/// <param name="url">圖片網絡地址</param>
/// <param name="towidth">縮小/放大寬度</param>
/// <param name="toheight">縮小/放大高度</param>
/// <returns></returns>
public image reduceimage(string url, int towidth, int toheight)
{
 webrequest request = webrequest.create(url);
 webresponse response = request.getresponse();
 stream responsestream = response.getresponsestream();
 
 image originalimage = image.fromstream(responsestream);
 if (towidth <= 0 && toheight <= 0)
 {
  return originalimage;
 }
 else if (towidth > 0 && toheight > 0)
 {
  if (originalimage.width < towidth && originalimage.height < toheight)
   return originalimage;
 }
 else if (towidth <= 0 && toheight > 0)
 {
  if (originalimage.height < toheight)
   return originalimage;
  towidth = originalimage.width * toheight / originalimage.height;
 }
 else if (toheight <= 0 && towidth > 0)
 {
  if (originalimage.width < towidth)
   return originalimage;
  toheight = originalimage.height * towidth / originalimage.width;
 }
 image tobitmap = new bitmap(towidth, toheight);
 using (graphics g = graphics.fromimage(tobitmap))
 {
  g.interpolationmode = system.drawing.drawing2d.interpolationmode.high;
  g.smoothingmode = system.drawing.drawing2d.smoothingmode.highquality;
  g.clear(color.transparent);
  g.drawimage(originalimage,
     new rectangle(0, 0, towidth, toheight),
     new rectangle(0, 0, originalimage.width, originalimage.height),
     graphicsunit.pixel);
  originalimage.dispose();
  return tobitmap;
 }
}

3.將圖片上傳微信服務器,并發(fā)送給用戶

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
string imagepath = draw(user);
         
string result = httputility.uploadfile($"https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={access_token}&type=image", imagepath);
 
jobject jobject = (jobject)jsonconvert.deserializeobject(result);
         
string media_id = (string)jobject["media_id"];
if (!string.isnullorempty(media_id))
{
          
  string resxml = "<xml><tousername><![cdata[" + xmlmsg.fromusername + "]]></tousername><fromusername><![cdata[" + xmlmsg.tousername + "]]></fromusername><createtime>" + nowtime + "</createtime><msgtype><![cdata[image]]></msgtype><image><mediaid><![cdata[" + media_id + "]]></mediaid></image></xml>";
  return resxml;
}
loghelper.writelog(typeof(wechatcontroller), "上傳專屬推廣圖片素材失敗" + result);

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。

原文鏈接:https://www.cnblogs.com/gracexu/p/10081111.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩成人在线影院 | 欧美视频日韩视频 | 一本黄色片| 99精品欧美一区二区三区综合在线 | 欧美成人a∨高清免费观看 国产99久久 | 黄色一级视屏 | 亚洲精品一区二区三区在线 | 午夜大片男女免费观看爽爽爽尤物 | 亚洲视频在线观看视频 | 日韩中文字幕一区二区三区 | 午夜午夜精品一区二区三区文 | 九色在线 | 美日韩av | av基地网 | 在线观看亚洲视频 | 中文字幕在线电影 | 精品国产乱码久久久久久久 | 精品久久久久久久人人人人传媒 | 成人日韩在线观看 | 日本精品一区二区三区在线观看 | 国产不卡精品视频 | 精品一区二区6 | 日韩在线 | 久久久久久亚洲 | 欧美一区二区在线观看 | 欧美久久久网站 | 精品久草 | 久久久久久网站 | 欧美一级久久 | 999精品视频 | 亚洲天堂av影院 | 99久久精品免费 | 日韩一区二区视频 | 香蕉久久一区二区不卡无毒影院 | 欧美日韩精品一区二区公司 | 午夜tv| 午夜成人免费电影 | 一区二区不卡 | 欧美国产另类 | 男女xx网站| 黄色一级片在线观看 |